use of com.yydcdut.note.entity.PhotoNote in project PhotoNoter by yydcdut.
the class AlbumPresenterImpl method deletePhotos.
@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(photoNotes -> {
FilePathUtils.deleteAllFiles(entry.getValue().getPhotoName());
mAlbumView.updateDataNoChange(photoNoteList);
}, (throwable -> YLog.e(throwable)));
}
EventBus.getDefault().post(new PhotoNoteDeleteEvent());
}, (throwable -> YLog.e(throwable)));
}
use of com.yydcdut.note.entity.PhotoNote 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());
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.entity.PhotoNote 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(new Observable.Operator<Integer, PhotoNote>() {
@Override
public Subscriber<? super PhotoNote> call(Subscriber<? super Integer> subscriber) {
return 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)));
}
use of com.yydcdut.note.entity.PhotoNote in project PhotoNoter by yydcdut.
the class CameraServicePresenterImpl 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 = BitmapFactory.decodeByteArray(data, 0, data.length);
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 -> {
try {
setExif(photoNote, sandPhoto.getSandExif(), sandPhoto.getCameraId(), sandPhoto.isMirror());
} catch (IOException e) {
YLog.e(e);
}
deleteFromDBAndSDCard(sandPhoto);
mCameraServiceView.sendBroadCast();
}, (throwable -> YLog.e(throwable)));
//todo bitmap可以重复利用?
bitmap.recycle();
System.gc();
}
use of com.yydcdut.note.entity.PhotoNote in project PhotoNoter by yydcdut.
the class PhotoNoteDB method update.
public synchronized int update(PhotoNote... photoNotes) {
SQLiteDatabase db = mNotesSQLite.getWritableDatabase();
int rows = 0;
for (PhotoNote photoNote : photoNotes) {
ContentValues contentValues = new ContentValues();
contentValues.put("photoName", photoNote.getPhotoName());
contentValues.put("createdPhotoTime", photoNote.getCreatedPhotoTime());
contentValues.put("editedPhotoTime", photoNote.getEditedPhotoTime());
contentValues.put("title", photoNote.getTitle());
contentValues.put("content", photoNote.getContent());
contentValues.put("createdNoteTime", photoNote.getCreatedNoteTime());
contentValues.put("editedNoteTime", photoNote.getEditedNoteTime());
contentValues.put("palette", photoNote.getPaletteColor());
// contentValues.put("tag", );
contentValues.put("categoryId", photoNote.getCategoryId());
contentValues.put("categoryLabel", "");
rows += db.update(NotesSQLite.TABLE_PHOTONOTE, contentValues, "_id = ?", new String[] { photoNote.getId() + "" });
}
db.close();
return rows;
}
Aggregations