コード例 #1
0
 @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());
                       });
             });
   }
 }
コード例 #2
0
 @Override
 public void updateFromBroadcast(
     boolean broadcast_process, boolean broadcast_service, boolean broadcast_photo) {
   // 当图片数据改变的时候,比如滤镜,Service作图
   // 另外个进程发来广播的时候
   // todo  这里可以弄动画,需要计算的过程
   if (broadcast_process || broadcast_service) {
     mRxPhotoNote
         .refreshByCategoryId(mCategoryId, mAlbumSortKind)
         .observeOn(AndroidSchedulers.mainThread())
         .subscribe(
             photoNoteList -> {
               mAlbumView.updateData(photoNoteList);
             });
   } else if (broadcast_photo) {
     mAlbumView.notifyDataSetChanged();
   }
 }