use of com.yydcdut.note.entity.PhotoNote in project PhotoNoter by yydcdut.
the class SandBoxServicePresenterImpl method makePhoto.
/**
* 做图
*
* @param sandPhoto
*/
private void makePhoto(SandPhoto sandPhoto) {
byte[] rowData = getDataFromFile(sandPhoto.getFileName(), sandPhoto.getSize());
if (rowData == null) {
return;
}
byte[] data;
if (sandPhoto.getImageFormat() == ImageFormat.JPEG) {
data = rowData;
} else {
data = decodeNV21(rowData, sandPhoto.getSandExif().getImageWidth(), sandPhoto.getSandExif().getImageLength());
}
if (data == null) {
return;
}
Bitmap bitmap = null;
try {
bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
} catch (OutOfMemoryError e) {
YLog.e(e);
}
String fileName = sandPhoto.getTime() + ".jpg";
if (FilePathUtils.savePhoto(fileName, bitmap)) {
FilePathUtils.saveSmallPhoto(fileName, bitmap);
}
PhotoNote photoNote = new PhotoNote(fileName, sandPhoto.getTime(), sandPhoto.getTime(), "", "", sandPhoto.getTime(), sandPhoto.getTime(), sandPhoto.getCategoryId());
photoNote.setPaletteColor(Utils.getPaletteColor(bitmap));
mRxPhotoNote.savePhotoNote(photoNote).subscribe(photoNote1 -> {
}, (throwable -> YLog.e(throwable)));
try {
setExif(photoNote, sandPhoto.getSandExif(), sandPhoto.getCameraId(), sandPhoto.isMirror());
} catch (IOException e) {
YLog.e(e);
}
deleteFromDBAndSDCard(sandPhoto);
// bitmap.recycle();
System.gc();
}
use of com.yydcdut.note.entity.PhotoNote in project PhotoNoter by yydcdut.
the class AlbumPresenterImpl method changePhotosCategory.
@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);
mRxPhotoNote.updatePhotoNote(entry.getValue()).subscribe((photoNotes -> {
}), (throwable -> YLog.e(throwable)));
times++;
}
return map.size();
}).subscribe(integer -> {
mRxCategory.updateChangeCategory(mCategoryId, toCategoryId, integer).subscribe(categories -> {
mRxPhotoNote.refreshByCategoryId(mCategoryId, ComparatorFactory.FACTORY_NOT_SORT).subscribe((photoNoteList) -> mAlbumView.updateDataNoChange(photoNoteList), (throwable -> YLog.e(throwable)));
mRxPhotoNote.refreshByCategoryId(toCategoryId, ComparatorFactory.FACTORY_NOT_SORT).subscribe(photoNotes -> {
}, (throwable -> YLog.e(throwable)));
EventBus.getDefault().post(new CategoryMoveEvent());
}, (throwable -> YLog.e(throwable)));
}, (throwable -> YLog.e(throwable)));
}
}
use of com.yydcdut.note.entity.PhotoNote in project PhotoNoter by yydcdut.
the class EditCategoryPresenterImpl method deleteCategories.
/**
* 删除分类
*/
private void deleteCategories() {
if (mDeleteCategoryIdList.size() > 0) {
mRxCategory.refreshCategories().observeOn(Schedulers.io()).subscribe(categories -> {
for (int id : mDeleteCategoryIdList) {
mRxPhotoNote.findByCategoryId(id, ComparatorFactory.FACTORY_NOT_SORT).subscribe(photoNoteList -> {
for (PhotoNote photoNote : photoNoteList) {
FilePathUtils.deleteAllFiles(photoNote.getPhotoName());
}
mRxPhotoNote.deletePhotoNotes(photoNoteList, id).subscribe((photoNoteList2 -> {
}), (throwable -> YLog.e(throwable)));
}, (throwable -> YLog.e(throwable)));
mRxCategory.delete(id).subscribe(categories2 -> mHandler.sendEmptyMessage(1), (throwable -> YLog.e(throwable)));
}
}, (throwable -> YLog.e(throwable)));
} else {
mHandler.sendEmptyMessage(MESSAGE_DELETE_NONE);
}
}
use of com.yydcdut.note.entity.PhotoNote in project PhotoNoter by yydcdut.
the class AlbumAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(PhotoViewHolder holder, int position) {
PhotoNote photoNote = mPhotoNoteList.get(position);
if (photoNote.isSelected()) {
holder.checkLayout.setVisibility(View.VISIBLE);
} else {
holder.checkLayout.setVisibility(View.INVISIBLE);
}
ImageLoaderManager.displayImage(photoNote.getSmallPhotoPathWithFile(), holder.imageView);
int color = photoNote.getPaletteColor();
AppCompat.setBackgroundDrawable(holder.checkLayout, new ColorDrawable(Color.argb(0x70, Color.red(color), Color.green(color), Color.blue(color))));
}
use of com.yydcdut.note.entity.PhotoNote 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());
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)));
}
Aggregations