Skip to content

Instantly share code, notes, and snippets.

@Ekalips
Last active August 6, 2017 11:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ekalips/f186fe9f2d347f8db76f18992aac8750 to your computer and use it in GitHub Desktop.
Save Ekalips/f186fe9f2d347f8db76f18992aac8750 to your computer and use it in GitHub Desktop.
public abstract class TestAdapterGenerated extends Adapter<BindingViewHolder> implements DataSetInterface {
List<TestData> data;
{
data = new java.util.ArrayList<>();
}
@Override
@CallSuper
public int getItemViewType(int position) {
return ViewTypeEnum.getViewTypeFromDataClass(data.get(position).getClass());
}
@Override
@CallSuper
public BindingViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new com.ekalips.BindingViewHolder<>(ViewTypeEnum.getLayoutIdFromViewType(viewType), parent);
}
@Override
@CallSuper
public void onBindViewHolder(final BindingViewHolder holder, int position) {
final Object currentData = data.get(holder.getAdapterPosition());
if (currentData instanceof com.ekalips.annotationbindingrecyclerview.data.TestData) {
holder.getBinding().setVariable(com.ekalips.AnnotationBRMapper.getBRForName("testData"), currentData);
}
holder.getBinding().setVariable(com.ekalips.AnnotationBRMapper.getBRForName("clickAdapter"), new ClickAdapter() {
@Override
public void onClick(View view) {
myMethod(holder.getAdapterPosition(), holder, currentData);
}
});
}
@CallSuper
@Override
public int getItemCount() {
return data.size();
}
@Override
public void setData(List data) {
this.data.clear();
this.data.addAll(data);
notifyDataSetChanged();
}
public abstract Void myMethod(int position, BindingViewHolder holder, Object object);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment