Need support, consulting, or have any other business-related question? Feel free to get in touch.
Like the project, make profit from it, or simply want to thank back? Please consider sponsoring me!
A collection of modular elements for RecyclerView
lists, alternative to
Google's Paging library, designed in Kotlin with these goals in mind:
implementation("com.otaliastudios:elements:0.5.0")
Design features:
- Separation of concerns: we split the model component into
Source
s, and the UI component intoPresenter
s. [docs] - Simplicity: No need to extend Adapters, ViewHolders or all that Paging lib. boilerplate.
- Reusability: as a result, each
Source
andPresenter
is an independent piece of code that can be reused. - Modularity: let the adapter accept multiple
Source
s andPresenter
s. [docs] - Testability: a consequence of the above, each component can be independently tested.
- Coordination: let
Source
s declare dependencies among them, in aCoordinatorLayout.Behavior
fashion. [docs] - Paging: built-in concept of
Page
. [docs] - Integration with Arch components: heavy use of
LiveData
andLifecycle
s, extensions for data binding. - Animations: give
Presenters
s fine grained control over how to animate each item [docs]
If you are curious about how it works in practice, take a look at the sample app in the app
module.
⠀
⠀
If you like the project, make profit from it, or simply want to thank back, please consider sponsoring me through the GitHub Sponsors program! You can have your company logo here, get private support hours or simply help me push this forward.
Feel free to contact me for support, consulting or any other business-related question.
Please read the official website for setup instructions and documentation.
You might also be interested in our changelog. After migrating
to Elements, your code will look like the examples below.
Simplest single-paged list:
val data = listOf("Monday", "Tuesday", "Wednesday", "Friday", "Saturday", "Sunday")
Adapter.builder(lifecycle)
.addSource(Source.fromList(data))
.addPresenter(Presenter.simple(context, R.layout.item, { view, day -> view.text = day }))
.into(recyclerView)
Paged list with multiple sources and presenters, headers, ads, error/empty indicators and progress bars:
Adapter.builder(lifecycle)
.addSource(ContactsSource()) // Add a paged list of contacts
.addSource(ContactsHeaderSource()) // Add the letters A, B, C as a header
.addSource(AdSource(5)) // Add some ads each 5 items
.addPresenter(ContactsPresenter(context))
.addPresenter(ContactsHeaderPresenter(context))
.addPresenter(AdPresenter(context))
.addPresenter(Presenter.forLoadingIndicator(context, R.layout.loading))
.addPresenter(Presenter.forErrorIndicator(context, R.layout.error))
.addPresenter(Presenter.forEmptyIndicator(context, R.layout.empty))
.into(recyclerView)