{"id":20471584,"url":"https://github.com/backbase/deferredresources","last_synced_at":"2025-04-13T11:07:49.777Z","repository":{"id":39673269,"uuid":"262352092","full_name":"Backbase/DeferredResources","owner":"Backbase","description":"Decoupling resource declaration from resource resolution on Android.","archived":false,"fork":false,"pushed_at":"2024-02-28T12:05:21.000Z","size":1608,"stargazers_count":115,"open_issues_count":1,"forks_count":4,"subscribers_count":12,"default_branch":"main","last_synced_at":"2024-04-16T10:58:17.784Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Backbase.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2020-05-08T14:57:48.000Z","updated_at":"2024-02-10T05:15:28.000Z","dependencies_parsed_at":"2024-02-23T09:45:04.343Z","dependency_job_id":null,"html_url":"https://github.com/Backbase/DeferredResources","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Backbase%2FDeferredResources","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Backbase%2FDeferredResources/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Backbase%2FDeferredResources/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Backbase%2FDeferredResources/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Backbase","download_url":"https://codeload.github.com/Backbase/DeferredResources/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224792471,"owners_count":17370788,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-15T14:16:34.060Z","updated_at":"2024-11-15T14:16:34.939Z","avatar_url":"https://github.com/Backbase.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Deferred Resources\n[![](https://github.com/Backbase/DeferredResources/workflows/CI/badge.svg?branch=main)](https://github.com/Backbase/DeferredResources/actions?query=workflow%3ACI+branch%3Amain)\n\nAn Android library that decouples resource declaration (without Context) from resource resolution\n(with Context). This allows the resolver (Activity, Fragment, or View) to be agnostic to the source\n(standard resources, attributes, or values fetched from an API), and allows repository/configuration\nlayers to remain ignorant of Android's Context.\n\nSee the [project website](https://backbase.github.io/DeferredResources/) for API documentation.\n\n## Download\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.backbase.oss.deferredresources/deferred-resources/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.backbase.oss.deferredresources/deferred-resources)\n\nDeferred Resources is available on Maven Central. Snapshots of the development version are available\nin [Sonatype's Snapshots\nrepository](https://oss.sonatype.org/#view-repositories;snapshots~browsestorage).\n\n```groovy\nimplementation \"com.backbase.oss.deferredresources:deferred-resources:$version\"\nimplementation \"com.backbase.oss.deferredresources:deferred-resources-view-extensions:$version\"\nimplementation \"com.backbase.oss.deferredresources:deferred-resources-compose-adapter:$version\"\nimplementation \"com.backbase.oss.deferredresources:deferred-resources-animation-lottie:$version\"\n```\n\n## Use\n\nIn the logic layer, declare the resource values however you like, without worrying about their\nresolution or about Context:\n```kotlin\nclass LocalViewModel : MyViewModel {\n    override fun getText(): DeferredText = DeferredText.Resource(R.string.someText)\n    override fun getTextColor(): DeferredColor = DeferredColor.Attribute(R.attr.colorOnBackground)\n    override fun getTextSize(): DeferredDimension = DeferredDimension.Attribute(R.attr.bodyTextSize)\n}\n\nclass RemoteViewModel(private val api: Api) : MyViewModel {\n    override fun getText(): DeferredText = DeferredText.Constant(api.fetchText())\n    override fun getTextColor(): DeferredColor = DeferredColor.Constant(api.fetchTextColor())\n    override fun getTextSize(): DeferredDimension =\n        DeferredDimension.Constant(api.fetchTextSize(), DeferredDimension.Constant.Unit.SP)\n}\n```\n\nIn the view layer, resolve a deferred resource to display it:\n```kotlin\nval text: DeferredText = viewModel.getText()\nval textColor: DeferredColor = viewModel.getTextColor()\nval textSize: DeferredDimension = viewModel.getTextSize()\ntextView.text = text.resolve(context)\ntextView.setTextColor(textColor.resolve(context))\ntextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, deferredSize.resolveExact(context))\n```\n\nWith view extensions, this is even simpler:\n```kotlin\ntextView.setText(viewModel.getText())\ntextView.setTextColor(viewModel.getTextColor())\ntextView.setTextSize(viewModel.getTextSize())\n```\n\n### Text types\n\nVarious types of text are supported: `DeferredText` for basic text, `DeferredFormattedString` for\nformatted text, `DeferredPlurals` for pluralized text, and `DeferredFormattedPlurals` for formatted,\npluralized text. Additionally, it's possible to \"partially resolve\" these more complex text types to\nbe more basic without yet having a `Context`.\n\n```kotlin\nval deferredFormattedPlurals = DeferredFormattedPlurals.Resource(R.plurals.formatted_plurals)\n\n// If you have the format args, quantity, and Context:\nval string: String = deferredFormattedPlurals.resolve(context, 5, \"million\")\n\n// If you have the format args and quantity, but no Context:\nval deferredText: DeferredText = deferredFormattedPlurals.withQuantityAndFormatArgs(5, \"million\")\n\n// If you have only the quantity:\nval deferredFormattedString: DeferredFormattedString = deferredFormattedPlurals.withQuantity(5)\n\n// If you have only the format args:\nval deferredPlurals: DeferredPlurals = deferredFormattedPlurals.withFormatArgs(\"million\")\n```\n#### Auxiliary type(s)\n`FormattedDeferredText` is a type that wraps a `DeferredFormattedString` and it's relevant \narguments. This is useful when the format arguments are determined at the declaration site rather \nthan the resolution site. \n\n```kotlin\nval formattedString = DeferredFormattedString.Constant(\"%s and %s\")\n// Formatted text with arguments at resolution site\nformattedString.resolve(context, \"A\", \"B\")\n\n// Formatted text with arguments at declaration site\nFormattedDeferredText(formattedString, \"A\", \"B\").resolve(context)\n```\n\nAll text-related types can eventually be converted to `DeferredText` through similar extensions.\n\n### Jetpack Compose UI\n\nFor each Deferred Resources type, the experimental `deferred-resources-compose-adapter` library\noffers a `remember*` function to resolve the Deferred item to a standard Compose UI type.\n\n```kotlin\nval color: Color = rememberResolvedColor(deferredColor)\nval size: Dp = rememberResolvedDp(deferredDimension)\nval icon: Painter = rememberResolvedPainter(deferredDrawable)\n```\n\nAll of these APIs are marked as `@ExperimentalComposeAdapter` and should not be considered stable.\nTheir behavior and binary compatibility are not guaranteed.\n\n### Lottie animations\n\nFor each `Drawable` type, the `deferred-resources-animation-lottie` library offers a new\n`DeferredLottieDrawable` class which resolves [Lottie](https://github.com/airbnb/lottie-android) files\ninto a `LottieDrawable`. This API is useful if one wishes to configure animations in their app.\n\n## License\n```\nCopyright 2020 Backbase R\u0026D, B.V.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbackbase%2Fdeferredresources","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbackbase%2Fdeferredresources","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbackbase%2Fdeferredresources/lists"}