Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/flavioarfaria/Catalog
Generate type-safe, user-friendly extensions to resolve Android resources.
https://github.com/flavioarfaria/Catalog
android gradle-plugin kotlin
Last synced: 9 days ago
JSON representation
Generate type-safe, user-friendly extensions to resolve Android resources.
- Host: GitHub
- URL: https://github.com/flavioarfaria/Catalog
- Owner: flavioarfaria
- License: apache-2.0
- Created: 2022-05-12T15:13:37.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-23T06:10:24.000Z (about 1 year ago)
- Last Synced: 2024-08-01T19:53:00.516Z (4 months ago)
- Topics: android, gradle-plugin, kotlin
- Language: Kotlin
- Homepage:
- Size: 329 KB
- Stars: 147
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-list - flavioarfaria/Catalog - Generate type-safe, user-friendly extensions to resolve Android resources. (Kotlin)
README
# Catalog
_Just like View Binding, but for resources._
Catalog is a Gradle plugin that generates type-safe, user-friendly extensions to resolve Android resources.
Let's see how the following string resource gets resolved without and with Catalog:
```xml
Good morning, %1$s! It’s %2$d°C outside.
```### Without Catalog:
Android resource resolution is overly verbose. It also uses snake case for resource identifiers,
which diverts away from Java/Kotlin naming conventions. In addition, parametrized strings and
plurals are not type safe. Android Studio comes with a very loose lint check for argument types,
but it treats all arguments as optional and it won't flag if you miss one.Here's how we resolve string resources without Catalog:
### With Catalog:
You can also use Catalog to access the resource id directly:
Catalog also works with plurals:
```xml
You have %1$d unread message
You have %1$d unread messages```
string arrays:
```xml
Spring
Summer
Fall
Winter```
and simple color resources:
```xml
#FFFF0000
```In the future, other resource types like integer arrays, dimensions, etc. will also be supported.
### Comment support
Resource comments are also carried over to extension properties and methods:
```xml
Catalog
```### Compose support
If you're using compose, `@Composable` extensions will also be generated. In order to avoid
signature clashes, Compose extensions are extension methods of
`com.flaviofaria.catalog.runtime.compose.[String, Plurals, StringArray]` whereas standard extensions
are extension methods of `com.flaviofaria.catalog.runtime.resources.[String, Plurals, StringArray]`,
so make sure you're importing the right class.## How it works
Catalog generates `Context` and `Fragment` extensions using [context receivers](https://blog.jetbrains.com/kotlin/2022/02/kotlin-1-6-20-m1-released/#prototype-of-context-receivers-for-kotlin-jvm).
Since these extensions are `inline`, there will be no increase in your app method count or any
significant impact on runtime performance.## Setup and configuration
To use Catalog, just apply the plugin to your module:
```groovy
plugins {
id 'com.flaviofaria.catalog' version '0.2.1'
}
```By default, Catalog generates non-Compose extensions only. Compose extensions will also be generated
if it detects Compose among your module dependencies. If your project is 100% written in Compose,
you can explicitly turn off non-Compose extensions by adding:```groovy
catalog {
generateResourcesExtensions = false
}
```Similarly, you can also turn off Compose extensions:
```groovy
catalog {
generateComposeExtensions = false
}
```