diff --git a/library/src/main/java/me/donnie/adapter/databinding/BaseBindingAdapter.java b/library/src/main/java/me/donnie/adapter/databinding/BaseBindingAdapter.java index 45d8d8f..1d82526 100644 --- a/library/src/main/java/me/donnie/adapter/databinding/BaseBindingAdapter.java +++ b/library/src/main/java/me/donnie/adapter/databinding/BaseBindingAdapter.java @@ -1,7 +1,6 @@ package me.donnie.adapter.databinding; import android.databinding.DataBindingUtil; -import android.databinding.ObservableArrayList; import android.databinding.ViewDataBinding; import android.support.annotation.IntRange; import android.support.annotation.LayoutRes; @@ -11,7 +10,9 @@ import android.view.View; import android.view.ViewGroup; +import java.util.ArrayList; import java.util.Collection; +import java.util.List; import me.donnie.adapter.BaseViewHolder; @@ -23,19 +24,18 @@ public abstract class BaseBindingAdapter extends RecyclerView.Adapter { - protected ObservableArrayList mData; - protected ListChangedCallback itemsChangeCallback; + protected List mData; protected int mLayoutResId; protected OnItemClickListener mOnItemClickListener; @NonNull - public ObservableArrayList getData() { + public List getData() { return mData; } - public void setData(@Nullable ObservableArrayList data) { - mData = data == null ? new ObservableArrayList() : data; + public void setData(@Nullable List data) { + mData = data == null ? new ArrayList() : data; notifyDataSetChanged(); } @@ -73,7 +73,7 @@ public T getItem(@IntRange(from = 0) int position) { } } - public BaseBindingAdapter(@Nullable ObservableArrayList data) { + public BaseBindingAdapter(@Nullable List data) { this(0, data); } @@ -81,12 +81,11 @@ public BaseBindingAdapter(@LayoutRes int layoutResId) { this(layoutResId, null); } - public BaseBindingAdapter(@LayoutRes int layoutResId, @Nullable ObservableArrayList data) { - this.mData = data == null ? new ObservableArrayList() : data; + public BaseBindingAdapter(@LayoutRes int layoutResId, @Nullable List data) { + this.mData = data == null ? new ArrayList() : data; if (layoutResId != 0) { this.mLayoutResId = layoutResId; } - this.itemsChangeCallback = new ListChangedCallback(); } @Override @@ -121,75 +120,6 @@ public void onClick(View v) { }); } - @Override - public void onAttachedToRecyclerView(RecyclerView recyclerView) { - super.onAttachedToRecyclerView(recyclerView); - this.mData.addOnListChangedCallback(itemsChangeCallback); - } - - @Override - public void onDetachedFromRecyclerView(RecyclerView recyclerView) { - super.onDetachedFromRecyclerView(recyclerView); - this.mData.removeOnListChangedCallback(itemsChangeCallback); - } - - protected void resetItems(ObservableArrayList newItems) { - this.mData = newItems; - } - - 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); - } - - private class ListChangedCallback extends ObservableArrayList.OnListChangedCallback> { - - @Override - public void onChanged(ObservableArrayList sender) { - BaseBindingAdapter.this.onChanged(sender); - } - - @Override - public void onItemRangeChanged(ObservableArrayList sender, int positionStart, int itemCount) { - BaseBindingAdapter.this.onItemRangeChanged(sender, positionStart, itemCount); - } - - @Override - public void onItemRangeInserted(ObservableArrayList sender, int positionStart, int itemCount) { - BaseBindingAdapter.this.onItemRangeInserted(sender, positionStart, itemCount); - } - - @Override - public void onItemRangeMoved(ObservableArrayList sender, int fromPosition, int toPosition, int itemCount) { - BaseBindingAdapter.this.onItemRangeMoved(sender); - } - - @Override - public void onItemRangeRemoved(ObservableArrayList sender, int positionStart, int itemCount) { - BaseBindingAdapter.this.onItemRangeRemoved(sender, positionStart, itemCount); - } - } - public interface OnItemClickListener { void onItemClick(View view, BaseViewHolder holder, int position); } diff --git a/library/src/main/java/me/donnie/adapter/databinding/MultiItemBindingAdapter.java b/library/src/main/java/me/donnie/adapter/databinding/MultiItemBindingAdapter.java index 7693c2a..ea594b5 100644 --- a/library/src/main/java/me/donnie/adapter/databinding/MultiItemBindingAdapter.java +++ b/library/src/main/java/me/donnie/adapter/databinding/MultiItemBindingAdapter.java @@ -1,11 +1,12 @@ package me.donnie.adapter.databinding; import android.databinding.DataBindingUtil; -import android.databinding.ObservableArrayList; import android.databinding.ViewDataBinding; import android.support.annotation.Nullable; import android.view.ViewGroup; +import java.util.List; + import me.donnie.adapter.BaseViewHolder; import me.donnie.adapter.databinding.delegate.ItemViewDelegate; import me.donnie.adapter.databinding.delegate.ItemViewDelegateManager; @@ -20,7 +21,7 @@ public abstract class MultiItemBindingAdapter exte protected ItemViewDelegateManager mItemViewDelegateManager; - public MultiItemBindingAdapter(@Nullable ObservableArrayList data) { + public MultiItemBindingAdapter(@Nullable List data) { super(data); mItemViewDelegateManager = new ItemViewDelegateManager<>(); }