⚒ Modular components for RecyclerView development enforcing clean, reusable and testable code, with built-in support for paging and complex hierarchies of data.
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:
Source
s, and the UI component into Presenter
s. [docs]
Source
and Presenter
is an independent piece of code that can be reused.Source
s and Presenter
s. [docs]
Source
s declare dependencies among them, in a CoordinatorLayout.Behavior
fashion. [docs]
Page
. [docs]
LiveData
and Lifecycle
s, extensions for data binding.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)