diff --git a/RvHelperLib/src/main/java/com/dreamliner/rvhelper/adapter/BaseDataAdapter.java b/RvHelperLib/src/main/java/com/dreamliner/rvhelper/adapter/BaseDataAdapter.java index 37644d7..8a64eee 100644 --- a/RvHelperLib/src/main/java/com/dreamliner/rvhelper/adapter/BaseDataAdapter.java +++ b/RvHelperLib/src/main/java/com/dreamliner/rvhelper/adapter/BaseDataAdapter.java @@ -108,6 +108,10 @@ public final void addAll(T... items) { } public void insert(T object, int index) { + if (index < 0 || index > mDatas.size()) { + Log.i(TAG, "insert: index error"); + return; + } synchronized (mLock) { if (null != mDatas) { mDatas.add(index, object); @@ -116,19 +120,32 @@ public void insert(T object, int index) { notifyItemInserted(index); } + public void insertAll(Collection collection, int index) { + if (index < 0 || index > mDatas.size()) { + Log.i(TAG, "insertAll: index error"); + return; + } + synchronized (mLock) { + if (null != mDatas) { + mDatas.addAll(index, collection); + } + } + notifyItemRangeInserted(index, index + collection.size()); + } + public void remove(int index) { - if (index >= 0 && index < getItemCount()) { - synchronized (mLock) { - mDatas.remove(index); - } - notifyItemRemoved(index); - } else { + if (index < 0 || index >= getItemCount()) { Log.i(TAG, "remove: index error"); + return; + } + synchronized (mLock) { + mDatas.remove(index); } + notifyItemRemoved(index); } - public void remove(T object) { + public boolean remove(T object) { int removeIndex = -1; boolean removeSuccess = false; synchronized (mLock) { @@ -143,7 +160,9 @@ public void remove(T object) { } if (removeSuccess) { notifyItemRemoved(removeIndex); + return true; } + return false; } public void clear() {