Skip to content

Steps for migration to v2.5.0

Vitaly Vivchar edited this page Feb 22, 2018 · 8 revisions

Step 1: Replace ItemModel to ViewModel in your models

-import com.github.vivchar.rendererrecyclerviewadapter.ItemModel;
+import com.github.vivchar.rendererrecyclerviewadapter.ViewModel;

public class YourModel
-		implements ItemModel {
+		implements ViewModel {

-	private static final int TYPE = 123;

-	public int getType() {
-		return TYPE;
-	}

	/* other methods */
}

Step 2: Replace the first argument in your view renderers, and remove Context argument

public class YourViewRenderer extends ViewRenderer<YourViewModel, YourViewHolder> {

-	public YourViewRenderer(Context context) {
-		super(YourViewModel.TYPE, context);
+	public YourViewRenderer() {
+		super(YourViewModel.class);
	}

	/* other methods */
}

Step 3: Change DiffCallback import in your diff-util implementation

-import com.github.vivchar.rendererrecyclerviewadapter.RendererRecyclerViewAdapter;
+import com.github.vivchar.rendererrecyclerviewadapter.DiffCallback;

public class YourDiffCallback
-		extends RendererRecyclerViewAdapter.DiffCallback<YourViewModel> {
+		extends DiffCallback<YourViewModel> {

	/* other methods */
}

Step 4: Change ViewHolder import in your view holders

+import com.github.vivchar.rendererrecyclerviewadapter.ViewHolder;

public class YourViewHolder
-		extends RecyclerView.ViewHolder  {
+		extends ViewHolder {

	/* other methods */
}

Step 5: Start using ViewBinder instead of ViewRender

public class YourViewBinder extends ViewBinder<YourViewModel> {
	public YourViewBinder() {
		super(
				R.layout.your_model_layout, //your item layout
				YourViewModel.class, //your model class
				(model, finder, payloads) -> finder
						.setText(R.id.title, model.getTitle())
						.setTextColor(R.id.text, model.getTitleColor())
						.setImageBitmap(R.id.image, model.getImage())
						.setVisible(R.id.image, model.isImageVisible())
						.setOnClickListener(R.id.button, new OnClickListener() {
							//...
						})
						.setChecked(R.id.check, model.isChecked())
						.find(R.id.custom, new ViewProvider<CustomView>() {
							//...
						})
		);
	}
}

Possible issues: