Exemplo n.º 1
0
 @Override
 public void createCategory(String newCategoryLabel) {
   mRxCategory
       .getAllCategories()
       .observeOn(AndroidSchedulers.mainThread())
       .subscribe(
           categories -> {
             int totalNumber = categories.size();
             if (!TextUtils.isEmpty(newCategoryLabel)) {
               mRxCategory
                   .saveCategory(newCategoryLabel, 0, totalNumber, true)
                   .observeOn(AndroidSchedulers.mainThread())
                   .subscribe(
                       categories1 -> {
                         boolean success = false;
                         for (Category category : categories1) {
                           if (category.getLabel().equals(newCategoryLabel)) {
                             mAlbumView.changeActivityListMenuCategoryChecked(category);
                             EventBus.getDefault().post(new CategoryCreateEvent());
                             success = true;
                             break;
                           }
                         }
                         if (!success) {
                           mAlbumView.showToast(
                               mContext.getResources().getString(R.string.toast_fail));
                         }
                       });
             } else {
               mAlbumView.showToast(mContext.getResources().getString(R.string.toast_fail));
             }
           });
 }
Exemplo n.º 2
0
 @Override
 public void jump2Camera() {
   if (mLocalStorageUtils.getCameraSystem()) {
     mAlbumView.jump2CameraSystemActivity();
   } else {
     mAlbumView.jump2CameraActivity(mCategoryId);
   }
 }
Exemplo n.º 3
0
 @Override
 public void sortData() {
   mRxPhotoNote
       .findByCategoryId(mCategoryId, mAlbumSortKind)
       .observeOn(AndroidSchedulers.mainThread())
       .subscribe(photoNoteList -> mAlbumView.notifyDataSetChanged());
 }
Exemplo n.º 4
0
 @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());
           });
 }
Exemplo n.º 5
0
 @Override
 public void attachView(IView iView) {
   mAlbumView = (IAlbumView) iView;
   mRxPhotoNote
       .findByCategoryId(mCategoryId, mAlbumSortKind)
       .observeOn(AndroidSchedulers.mainThread())
       .subscribe(photoNoteList -> mAlbumView.setAdapter(photoNoteList));
 }
Exemplo n.º 6
0
 @Override
 public boolean checkStorageEnough() {
   if (!FilePathUtils.isSDCardStoredEnough()) {
     mAlbumView.showToast(mContext.getResources().getString(R.string.no_space));
     return false;
   }
   return true;
 }
Exemplo n.º 7
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();
   }
 }
Exemplo n.º 8
0
 @Override
 public void changeCategoryWithPhotos(int categoryId) {
   mCategoryId = categoryId;
   mRxPhotoNote
       .findByCategoryId(mCategoryId, mAlbumSortKind)
       .observeOn(AndroidSchedulers.mainThread())
       .subscribe(
           photoNoteList -> {
             mAlbumView.updateData(photoNoteList);
           });
 }
Exemplo n.º 9
0
 @Override
 public void movePhotos2AnotherCategory() {
   mRxCategory
       .getAllCategories()
       .observeOn(AndroidSchedulers.mainThread())
       .subscribe(
           categories -> {
             final String[] categoryIdStringArray = new String[categories.size()];
             final String[] categoryLabelArray = new String[categories.size()];
             for (int i = 0; i < categoryIdStringArray.length; i++) {
               categoryIdStringArray[i] = categories.get(i).getId() + "";
               categoryLabelArray[i] = categories.get(i).getLabel();
             }
             mAlbumView.showMovePhotos2AnotherCategoryDialog(
                 categoryIdStringArray, categoryLabelArray);
           });
 }
Exemplo n.º 10
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());
                       });
             });
   }
 }
Exemplo n.º 11
0
 @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();
                     });
           });
 }
Exemplo n.º 12
0
 @Override
 public void jump2DetailActivity(int position) {
   mAlbumView.jump2DetailActivity(mCategoryId, position, mAlbumSortKind);
 }