https://github.com/jintin/composeadapter
Compose your Adapter with annotated ViewHolder
https://github.com/jintin/composeadapter
adapter android annotation-processing
Last synced: 23 days ago
JSON representation
Compose your Adapter with annotated ViewHolder
- Host: GitHub
- URL: https://github.com/jintin/composeadapter
- Owner: Jintin
- License: mit
- Created: 2019-07-03T15:46:17.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-09-12T00:13:58.000Z (over 5 years ago)
- Last Synced: 2025-04-10T16:43:40.101Z (12 months ago)
- Topics: adapter, android, annotation-processing
- Language: Kotlin
- Homepage: https://jintin.github.io/ComposeAdapter/
- Size: 168 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# ComposeAdapter
[](https://circleci.com/gh/Jintin/ComposeAdapter)
[](https://bintray.com/jintin/maven/ComposeAdapter-Compiler/_latestVersion)
[](https://bintray.com/jintin/maven/ComposeAdapter/_latestVersion)
ComposeAdapter is an Android tool to compose your Adapter with various ViewHolder by simple Annotations.
## Install
```groovy
implementation 'com.github.jintin:composeadapter:0.1.0'
kapt 'com.github.jintin:composeadapter-compiler:0.1.0'
```
## Usage
1. Add `@BindHolder` annotation to your Adapter with layout and model information.
- You can also mark `@BindLayout` to your ViewHolder with layout id so adapter side can omit.
2. Change your super class to auto-generated class, name will as same as your current class name plus "Helper".
```kotlin
@BindHolder(ViewHolder1::class)
@BindHolder(ViewHolder2::class, R.layout.item_holder2)
class SampleAdapter(private val list: List) : SampleAdapterHelper() {
//...
}
@BindLayout(R.layout.item_holder1)
class ViewHolder1(itemView: View) : RecyclerView.ViewHolder(itemView) {
//...
}
class ViewHolder2(itemView: View) : RecyclerView.ViewHolder(itemView) {
//...
}
```
3. Build project, the related `onCreateViewHolder` method will be created in the auto-generated super class with static viewType int for further usage.
```java
public abstract class SampleAdapterHelper extends RecyclerView.Adapter {
protected static final int TYPE_VIEW_HOLDER1 = 0;
protected static final int TYPE_VIEW_HOLDER2 = 1;
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
switch (viewType) {
case TYPE_VIEW_HOLDER1: {
View view = LayoutInflater.from(parent.getContext()).inflate(2131296285, parent, false);
return new ViewHolder1(view);
}
case TYPE_VIEW_HOLDER2: {
View view = LayoutInflater.from(parent.getContext()).inflate(2131296286, parent, false);
return new ViewHolder2(view);
}
default: throw new RuntimeException("Not support type" + viewType);
}
}
}
```
## Contributing
Bug reports and pull requests are welcome on GitHub at .
## License
The module is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).