@Override public void deletePhotos() { // 注意java.util.ConcurrentModificationException at // java.util.ArrayList$ArrayListIterator.next(ArrayList.java:573) mRxPhotoNote .findByCategoryId(mCategoryId, mAlbumSortKind) .observeOn(AndroidSchedulers.mainThread()) .subscribe( photoNoteList -> { TreeMap<Integer, PhotoNote> map = getTreeMap(); for (int i = 0; i < photoNoteList.size(); i++) { PhotoNote photoNote = photoNoteList.get(i); if (photoNote.isSelected()) { map.put(i, photoNote); } } int times = 0; for (Map.Entry<Integer, PhotoNote> entry : map.entrySet()) { photoNoteList.remove(entry.getValue()); mAlbumView.notifyItemRemoved(entry.getKey() - times); times++; mRxPhotoNote.deletePhotoNote(entry.getValue()).subscribe(); } EventBus.getDefault().post(new PhotoNoteDeleteEvent()); }); }
@Override public void changePhotosCategory(int toCategoryId) { if (mCategoryId != toCategoryId) { mRxPhotoNote .findByCategoryId(mCategoryId, mAlbumSortKind) .observeOn(AndroidSchedulers.mainThread()) .map( photoNoteList -> { TreeMap<Integer, PhotoNote> map = getTreeMap(); for (int i = 0; i < photoNoteList.size(); i++) { PhotoNote photoNote = photoNoteList.get(i); if (photoNote.isSelected()) { photoNote.setSelected(false); photoNote.setCategoryId(toCategoryId); map.put(i, photoNote); } } int times = 0; for (Map.Entry<Integer, PhotoNote> entry : map.entrySet()) { photoNoteList.remove(entry.getValue()); mAlbumView.notifyItemRemoved(entry.getKey() - times); // todo 这个在这里合适吗?觉得严重的不合适 mRxPhotoNote.updatePhotoNote(entry.getValue()).subscribe(); times++; } return map.size(); }) .subscribe( integer -> { mRxCategory .updateChangeCategory(mCategoryId, toCategoryId, integer) .subscribe( categories -> { mRxPhotoNote .refreshByCategoryId(mCategoryId, ComparatorFactory.FACTORY_NOT_SORT) .subscribe(); mRxPhotoNote .refreshByCategoryId(toCategoryId, ComparatorFactory.FACTORY_NOT_SORT) .subscribe(); EventBus.getDefault().post(new CategoryMoveEvent()); }); }); } }