-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Adapt | ||
Tired of writing Adapters for RecyclerViews? Adapt provides a simple to use DSLs to make writing adapters easier and faster! | ||
|
||
## Example Usage | ||
|
||
```kotlin | ||
val adapter = adapt<String> { | ||
defineViewTypes { data, position -> | ||
if (data.toInt() % 5 == 0 || data.toInt() % 15 == 0) { | ||
2 | ||
} else 1 | ||
} | ||
create(1) { | ||
ViewSource.BindingViewSource(LayoutTextItemBinding.inflate(layoutInflater), ViewBinding::getRoot) | ||
}.bind { model, layoutTextItemBinding -> | ||
layoutTextItemBinding.tvTest.text = model + " TYPE_1" | ||
} | ||
create(2) { | ||
ViewSource.BindingViewSource(LayoutTextItemBinding.inflate(layoutInflater), ViewBinding::getRoot) | ||
}.bind { model, layoutTextItemBinding -> | ||
layoutTextItemBinding.tvTest.text = model + " TYPE_2" | ||
} | ||
} | ||
|
||
recyclerView.adapter = adapter | ||
|
||
|
||
adapter.submitData(listOf("Test A", "Test B", "Test C")) | ||
``` | ||
For further info, checkout the demo app | ||
|
||
|