Skip to content

Commit

Permalink
1.完善BaseDataAdapter的操作list的方法.
Browse files Browse the repository at this point in the history
  • Loading branch information
chenzj-king committed Jun 22, 2016
1 parent 4bec7f2 commit f7e96ff
Showing 1 changed file with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -116,19 +120,32 @@ public void insert(T object, int index) {
notifyItemInserted(index);
}

public void insertAll(Collection<? extends T> 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) {
Expand All @@ -143,7 +160,9 @@ public void remove(T object) {
}
if (removeSuccess) {
notifyItemRemoved(removeIndex);
return true;
}
return false;
}

public void clear() {
Expand Down

0 comments on commit f7e96ff

Please sign in to comment.