@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 sortData() {
   mRxPhotoNote
       .findByCategoryId(mCategoryId, mAlbumSortKind)
       .observeOn(AndroidSchedulers.mainThread())
       .subscribe(photoNoteList -> mAlbumView.notifyDataSetChanged());
 }
 @Override
 public void attachView(IView iView) {
   mAlbumView = (IAlbumView) iView;
   mRxPhotoNote
       .findByCategoryId(mCategoryId, mAlbumSortKind)
       .observeOn(AndroidSchedulers.mainThread())
       .subscribe(photoNoteList -> mAlbumView.setAdapter(photoNoteList));
 }
Esempio n. 4
0
 @Override
 public void refreshImage() {
   mRxPhotoNote
       .findByCategoryId(mCategoryId, mComparator)
       .map(photoNoteList -> photoNoteList.get(mPosition))
       .observeOn(AndroidSchedulers.mainThread())
       .subscribe(photoNote -> mZoomView.showImage(photoNote.getBigPhotoPathWithFile()));
 }
 @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());
                       });
             });
   }
 }
Esempio n. 6
0
 @Override
 public void attachView(IView iView) {
   mZoomView = (IZoomView) iView;
   mRxPhotoNote
       .findByCategoryId(mCategoryId, mComparator)
       .map(photoNoteList -> photoNoteList.get(mPosition))
       .observeOn(AndroidSchedulers.mainThread())
       .subscribe(photoNote -> mZoomView.showImage(photoNote.getBigPhotoPathWithFile()));
   PGEditSDK.instance().initSDK(mActivity.getApplication());
 }
 @Override
 public void changeCategoryWithPhotos(int categoryId) {
   mCategoryId = categoryId;
   mRxPhotoNote
       .findByCategoryId(mCategoryId, mAlbumSortKind)
       .observeOn(AndroidSchedulers.mainThread())
       .subscribe(
           photoNoteList -> {
             mAlbumView.updateData(photoNoteList);
           });
 }
Esempio n. 8
0
 @Override
 public void saveSmallImage(final Bitmap thumbNail) {
   mRxPhotoNote
       .findByCategoryId(mCategoryId, mComparator)
       .map(photoNoteList -> photoNoteList.get(mPosition))
       .doOnSubscribe(() -> mZoomView.showProgressBar())
       .subscribeOn(AndroidSchedulers.mainThread())
       .subscribe(
           photoNote -> {
             FilePathUtils.saveSmallPhotoFromSDK(photoNote.getPhotoName(), thumbNail);
             photoNote.setPaletteColor(
                 UiHelper.getPaletteColor(
                     ImageLoaderManager.loadImageSync(photoNote.getBigPhotoPathWithFile())));
             mRxPhotoNote
                 .updatePhotoNote(photoNote)
                 .observeOn(AndroidSchedulers.mainThread())
                 .subscribe(
                     photoNoteList -> {
                       sendBroadcast();
                       mZoomView.hideProgressBar();
                       mIsChanged = true;
                     });
           });
 }
 @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();
   }
 }
Esempio n. 10
0
 @Override
 public void jump2PGEditActivity() {
   int memoryClass =
       ((ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();
   if (memoryClass <= 48) {
     ImageLoaderManager.clearMemoryCache();
   }
   mRxPhotoNote
       .findByCategoryId(mCategoryId, mComparator)
       .map(photoNoteList -> photoNoteList.get(mPosition))
       .observeOn(AndroidSchedulers.mainThread())
       .subscribe(
           photoNote -> {
             String path = photoNote.getBigPhotoPathWithoutFile();
             if (!path.endsWith(".jpg")) {
               mZoomView.showSnackBar(
                   mContext.getResources().getString(R.string.toast_pgedit_not_support));
             } else {
               mZoomView.jump2PGEditActivity(path);
             }
           });
 }
 @Override
 public void savePhotoFromSystemCamera() {
   PhotoNote photoNote =
       new PhotoNote(
           System.currentTimeMillis() + ".jpg",
           System.currentTimeMillis(),
           System.currentTimeMillis(),
           "",
           "",
           System.currentTimeMillis(),
           System.currentTimeMillis(),
           mCategoryId);
   mRxPhotoNote
       .savePhotoNote(photoNote)
       .map(
           photoNote1 -> {
             // 复制大图
             try {
               FilePathUtils.copyFile(
                   FilePathUtils.getTempFilePath(), photoNote1.getBigPhotoPathWithoutFile());
               // 保存小图
               FilePathUtils.saveSmallPhotoFromBigPhoto(photoNote);
             } catch (FileNotFoundException e) {
               e.printStackTrace();
             } catch (IOException e) {
               e.printStackTrace();
             }
             photoNote1.setPaletteColor(
                 UiHelper.getPaletteColor(
                     ImageLoaderManager.loadImageSync(photoNote.getBigPhotoPathWithFile())));
             mRxPhotoNote.updatePhotoNote(photoNote1).subscribe();
             return photoNote1;
           })
       .doOnSubscribe(
           new Action0() { // todo // FIXME: 15/11/29 lambda
             @Override
             public void call() {
               mAlbumView.showProgressBar();
             }
           })
       .subscribeOn(AndroidSchedulers.mainThread())
       .subscribe(
           photoNote2 -> {
             EventBus.getDefault().post(new PhotoNoteCreateEvent());
             // 因为是最新时间,即“图片创建事件”、“图片修改时间”、“笔记创建时间”、“笔记修改时间”,所以要么在最前面,要么在最后面//// TODO: 15/11/20
             // 还是因时间来判断插入到哪里,所以要计算
             mRxPhotoNote
                 .findByCategoryId(mCategoryId, mAlbumSortKind)
                 .observeOn(AndroidSchedulers.mainThread())
                 .subscribe(
                     photoNoteList -> {
                       mAlbumView.updateData(photoNoteList);
                       switch (mAlbumSortKind) {
                         case ComparatorFactory.FACTORY_CREATE_CLOSE:
                         case ComparatorFactory.FACTORY_EDITED_CLOSE:
                           mAlbumView.notifyItemInserted(photoNoteList.size() - 1);
                           break;
                         case ComparatorFactory.FACTORY_CREATE_FAR:
                         case ComparatorFactory.FACTORY_EDITED_FAR:
                           mAlbumView.notifyItemInserted(0);
                           break;
                       }
                       mAlbumView.hideProgressBar();
                     });
           });
 }