super.onAttachedToRecyclerView(recyclerView);
this.items.addOnListChangedCallback(itemsChangeCallback);
}
@Override
public void onDetachedFromRecyclerView(RecyclerView recyclerView) {
super.onDetachedFromRecyclerView(recyclerView);
this.items.removeOnListChangedCallback(itemsChangeCallback);
}
//region 处理数据集变化
protected void onChanged(ObservableArrayList newItems) {
resetItems(newItems);
notifyDataSetChanged();
}
protected void onItemRangeChanged(ObservableArrayList newItems, int positionStart, int itemCount) {
resetItems(newItems);
notifyItemRangeChanged(positionStart, itemCount);
}
protected void onItemRangeInserted(ObservableArrayList newItems, int positionStart, int itemCount) {
resetItems(newItems);
notifyItemRangeInserted(positionStart, itemCount);
}
protected void onItemRangeMoved(ObservableArrayList newItems) {
resetItems(newItems);
notifyDataSetChanged();
}
protected void onItemRangeRemoved(ObservableArrayList newItems, int positionStart, int itemCount) {
resetItems(newItems);
notifyItemRangeRemoved(positionStart, itemCount);
}
protected void resetItems(ObservableArrayList newItems) {
this.items = newItems;
}
//endregion
protected abstract @LayoutRes
int getLayoutResId(int viewType);
protected abstract void onBindItem(B binding, M item);
class ListChangedCallback extends ObservableArrayList.OnListChangedCallback<ObservableArrayList> { </