@Override public void changeCategoryWithPhotos(int categoryId) { mCategoryId = categoryId; mRxPhotoNote .findByCategoryId(mCategoryId, mAlbumSortKind) .observeOn(AndroidSchedulers.mainThread()) .subscribe( photoNoteList -> { mAlbumView.updateData(photoNoteList); }); }
@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(); } }
@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(); }); }); }