/ RecyclerView

A single adapter with multiple view types for the whole project

A single adapter with multiple view types for the whole project

Renderer RecyclerView Adapter

A single adapter with multiple view types for the whole project.

Examples

All View Renderer View Binder Load More
example view-renderer--1- view-renderer load-more
Composite ViewState Diff Util Payload
composite view-state diff-util payload

Gradle

dependencies {
    compile 'com.github.vivchar:RendererRecyclerViewAdapter:2.6.0'
}

BETA

    maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
    implementation 'com.github.vivchar:RendererRecyclerViewAdapter:2.7.0-SNAPSHOT'

Usage

  • Step 1: Add the ViewModel interface to your UI model
public class SomeModel implements ViewModel {
	...
}
  • Step 2: Create your item_layout
<LinearLayout ... >
	<TextView android:id = "@+id/title" ... />
	<ImageView android:id = "@+id/image" ... />
	<Button android:id = "@+id/button" ... />
	<CustomView android:id = "@+id/custom" ... />
</LinearLayout>
  • Step 3: Initialize Adapter and register the ViewBinder
mRecyclerViewAdapter = new RendererRecyclerViewAdapter();

mRecyclerViewAdapter.registerRenderer(new ViewBinder<>(
	R.layout.item_layout,
	SomeModel.class,
	(model, finder, payloads) -> finder
		.find(R.id.custom, (ViewProvider<CustomView>) customView -> { ... })
		.setBackground(R.id.image, model.getBackground())
		.setText(R.id.text, model.getText())
		.setOnClickListener(R.id.button, v -> { ... })
));
mRecyclerViewAdapter.registerRenderer(...); /* you can use several types of cells */

/* Regular code:
mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mRecyclerView.setAdapter(mRecyclerViewAdapter);

mRecyclerViewAdapter.setItems(getItems());
mRecyclerViewAdapter.notifyDataSetChanged();
*/

GitHub