use of com.yydcdut.note.bus.PhotoNoteCreateEvent in project PhotoNoter by yydcdut.
the class AlbumPresenterImpl method savePhotoFromLocal.
@Override
public void savePhotoFromLocal(final Uri imageUri) {
PhotoNote photoNote = new PhotoNote(System.currentTimeMillis() + ".jpg", System.currentTimeMillis(), System.currentTimeMillis(), "", "", System.currentTimeMillis(), System.currentTimeMillis(), mCategoryId);
mRxPhotoNote.savePhotoNote(photoNote).map(photoNote1 -> {
// 复制大图
ContentResolver cr = mContext.getContentResolver();
try {
FilePathUtils.copyFile(cr.openInputStream(imageUri), photoNote1.getBigPhotoPathWithoutFile());
// 保存小图
FilePathUtils.saveSmallPhotoFromBigPhoto(photoNote1.getBigPhotoPathWithFile(), photoNote1.getPhotoName());
} catch (FileNotFoundException e) {
YLog.e(e);
} catch (IOException e) {
YLog.e(e);
}
photoNote1.setPaletteColor(Utils.getPaletteColor(ImageLoaderManager.loadImageSync(photoNote.getBigPhotoPathWithFile())));
mRxPhotoNote.updatePhotoNote(photoNote1).subscribe(photoNotes -> {
}, (throwable -> YLog.e(throwable)));
return photoNote1;
}).doOnSubscribe(() -> 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();
});
}, (throwable -> YLog.e(throwable)));
}
use of com.yydcdut.note.bus.PhotoNoteCreateEvent in project PhotoNoter by yydcdut.
the class AlbumPresenterImpl method savePhotoFromSystemCamera.
@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.getBigPhotoPathWithFile(), photoNote.getPhotoName());
} catch (FileNotFoundException e) {
YLog.e(e);
} catch (IOException e) {
YLog.e(e);
}
photoNote1.setPaletteColor(Utils.getPaletteColor(ImageLoaderManager.loadImageSync(photoNote.getBigPhotoPathWithFile())));
mRxPhotoNote.updatePhotoNote(photoNote1).subscribe(photoNotes -> {
}, (throwable -> YLog.e(throwable)));
return photoNote1;
}).doOnSubscribe(() -> 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();
});
}, (throwable -> YLog.e(throwable)));
}
use of com.yydcdut.note.bus.PhotoNoteCreateEvent in project PhotoNoter by yydcdut.
the class AlbumPresenterImpl method savePhotosFromGallery.
@Override
public void savePhotosFromGallery(ArrayList<String> pathList) {
List<PhotoNote> photoNotes = new ArrayList<>(pathList.size());
for (String path : pathList) {
PhotoNote photoNote = new PhotoNote(System.currentTimeMillis() + ".jpg", System.currentTimeMillis(), System.currentTimeMillis(), "", "", System.currentTimeMillis(), System.currentTimeMillis(), mCategoryId);
photoNote.setTag(path);
photoNotes.add(photoNote);
try {
Thread.sleep(10);
} catch (InterruptedException e) {
YLog.e(e);
}
}
mRxPhotoNote.savePhotoNotes(photoNotes).flatMap(// 注意看这里是photoNotes
photoNotes1 -> Observable.from(photoNotes)).map(photoNote -> {
String path = (String) photoNote.getTag();
if (!TextUtils.isEmpty(path)) {
try {
// 复制大图
FilePathUtils.copyFile(path, photoNote.getBigPhotoPathWithoutFile());
// 保存小图
FilePathUtils.saveSmallPhotoFromBigPhoto(photoNote.getBigPhotoPathWithFile(), photoNote.getPhotoName());
photoNote.setPaletteColor(Utils.getPaletteColor(ImageLoaderManager.loadImageSync(photoNote.getBigPhotoPathWithFile())));
} catch (IOException e) {
YLog.e(e);
}
}
return photoNote;
}).lift((Observable.Operator<Integer, PhotoNote>) subscriber -> new Subscriber<PhotoNote>() {
@Override
public void onCompleted() {
subscriber.onNext(mCategoryId);
subscriber.onCompleted();
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(PhotoNote photoNote) {
}
}).doOnSubscribe(() -> mAlbumView.showProgressBar()).subscribeOn(AndroidSchedulers.mainThread()).subscribe(integer -> {
EventBus.getDefault().post(new PhotoNoteCreateEvent());
mRxPhotoNote.refreshByCategoryId(mCategoryId, mAlbumSortKind).observeOn(AndroidSchedulers.mainThread()).subscribe(photoNoteList -> {
mAlbumView.updateData(photoNoteList);
mAlbumView.notifyDataSetChanged();
mAlbumView.hideProgressBar();
}, (throwable -> YLog.e(throwable)));
}, (throwable -> YLog.e(throwable)));
}
Aggregations