Search in sources :

Example 11 with PhotoNote

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)));
}
Also used : RxPhotoNote(com.yydcdut.note.model.rx.RxPhotoNote) PhotoNote(com.yydcdut.note.entity.PhotoNote) Context(android.content.Context) RxPhotoNote(com.yydcdut.note.model.rx.RxPhotoNote) Uri(android.net.Uri) PhotoNoteDeleteEvent(com.yydcdut.note.bus.PhotoNoteDeleteEvent) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) ArrayList(java.util.ArrayList) Observable(rx.Observable) Inject(javax.inject.Inject) IAlbumView(com.yydcdut.note.views.home.IAlbumView) ContentResolver(android.content.ContentResolver) RxSandBox(com.yydcdut.note.model.rx.RxSandBox) Handler(android.os.Handler) ContextLife(com.yydcdut.note.injector.ContextLife) EventBus(org.greenrobot.eventbus.EventBus) Map(java.util.Map) Category(com.yydcdut.note.entity.Category) FilePathUtils(com.yydcdut.note.utils.FilePathUtils) R(com.yydcdut.note.R) Utils(com.yydcdut.note.utils.Utils) PermissionUtils(com.yydcdut.note.utils.PermissionUtils) Fragment(android.app.Fragment) RxCategory(com.yydcdut.note.model.rx.RxCategory) CategoryMoveEvent(com.yydcdut.note.bus.CategoryMoveEvent) Subscriber(rx.Subscriber) PhotoNoteCreateEvent(com.yydcdut.note.bus.PhotoNoteCreateEvent) LocalStorageUtils(com.yydcdut.note.utils.LocalStorageUtils) TextUtils(android.text.TextUtils) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) IAlbumPresenter(com.yydcdut.note.presenters.home.IAlbumPresenter) List(java.util.List) Permission(com.yydcdut.note.utils.permission.Permission) TreeMap(java.util.TreeMap) ComparatorFactory(com.yydcdut.note.model.compare.ComparatorFactory) ImageLoaderManager(com.yydcdut.note.utils.ImageManager.ImageLoaderManager) CategoryCreateEvent(com.yydcdut.note.bus.CategoryCreateEvent) PhotoNote(com.yydcdut.note.entity.PhotoNote) Comparator(java.util.Comparator) YLog(com.yydcdut.note.utils.YLog) IView(com.yydcdut.note.views.IView) PhotoNoteDeleteEvent(com.yydcdut.note.bus.PhotoNoteDeleteEvent) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 12 with PhotoNote

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)));
}
Also used : RxPhotoNote(com.yydcdut.note.model.rx.RxPhotoNote) PhotoNote(com.yydcdut.note.entity.PhotoNote) Context(android.content.Context) RxPhotoNote(com.yydcdut.note.model.rx.RxPhotoNote) Uri(android.net.Uri) PhotoNoteDeleteEvent(com.yydcdut.note.bus.PhotoNoteDeleteEvent) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) ArrayList(java.util.ArrayList) Observable(rx.Observable) Inject(javax.inject.Inject) IAlbumView(com.yydcdut.note.views.home.IAlbumView) ContentResolver(android.content.ContentResolver) RxSandBox(com.yydcdut.note.model.rx.RxSandBox) Handler(android.os.Handler) ContextLife(com.yydcdut.note.injector.ContextLife) EventBus(org.greenrobot.eventbus.EventBus) Map(java.util.Map) Category(com.yydcdut.note.entity.Category) FilePathUtils(com.yydcdut.note.utils.FilePathUtils) R(com.yydcdut.note.R) Utils(com.yydcdut.note.utils.Utils) PermissionUtils(com.yydcdut.note.utils.PermissionUtils) Fragment(android.app.Fragment) RxCategory(com.yydcdut.note.model.rx.RxCategory) CategoryMoveEvent(com.yydcdut.note.bus.CategoryMoveEvent) Subscriber(rx.Subscriber) PhotoNoteCreateEvent(com.yydcdut.note.bus.PhotoNoteCreateEvent) LocalStorageUtils(com.yydcdut.note.utils.LocalStorageUtils) TextUtils(android.text.TextUtils) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) IAlbumPresenter(com.yydcdut.note.presenters.home.IAlbumPresenter) List(java.util.List) Permission(com.yydcdut.note.utils.permission.Permission) TreeMap(java.util.TreeMap) ComparatorFactory(com.yydcdut.note.model.compare.ComparatorFactory) ImageLoaderManager(com.yydcdut.note.utils.ImageManager.ImageLoaderManager) CategoryCreateEvent(com.yydcdut.note.bus.CategoryCreateEvent) PhotoNote(com.yydcdut.note.entity.PhotoNote) Comparator(java.util.Comparator) YLog(com.yydcdut.note.utils.YLog) IView(com.yydcdut.note.views.IView) PhotoNoteCreateEvent(com.yydcdut.note.bus.PhotoNoteCreateEvent) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 13 with PhotoNote

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)));
}
Also used : RxPhotoNote(com.yydcdut.note.model.rx.RxPhotoNote) PhotoNote(com.yydcdut.note.entity.PhotoNote) Context(android.content.Context) RxPhotoNote(com.yydcdut.note.model.rx.RxPhotoNote) Uri(android.net.Uri) PhotoNoteDeleteEvent(com.yydcdut.note.bus.PhotoNoteDeleteEvent) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) ArrayList(java.util.ArrayList) Observable(rx.Observable) Inject(javax.inject.Inject) IAlbumView(com.yydcdut.note.views.home.IAlbumView) ContentResolver(android.content.ContentResolver) RxSandBox(com.yydcdut.note.model.rx.RxSandBox) Handler(android.os.Handler) ContextLife(com.yydcdut.note.injector.ContextLife) EventBus(org.greenrobot.eventbus.EventBus) Map(java.util.Map) Category(com.yydcdut.note.entity.Category) FilePathUtils(com.yydcdut.note.utils.FilePathUtils) R(com.yydcdut.note.R) Utils(com.yydcdut.note.utils.Utils) PermissionUtils(com.yydcdut.note.utils.PermissionUtils) Fragment(android.app.Fragment) RxCategory(com.yydcdut.note.model.rx.RxCategory) CategoryMoveEvent(com.yydcdut.note.bus.CategoryMoveEvent) Subscriber(rx.Subscriber) PhotoNoteCreateEvent(com.yydcdut.note.bus.PhotoNoteCreateEvent) LocalStorageUtils(com.yydcdut.note.utils.LocalStorageUtils) TextUtils(android.text.TextUtils) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) IAlbumPresenter(com.yydcdut.note.presenters.home.IAlbumPresenter) List(java.util.List) Permission(com.yydcdut.note.utils.permission.Permission) TreeMap(java.util.TreeMap) ComparatorFactory(com.yydcdut.note.model.compare.ComparatorFactory) ImageLoaderManager(com.yydcdut.note.utils.ImageManager.ImageLoaderManager) CategoryCreateEvent(com.yydcdut.note.bus.CategoryCreateEvent) PhotoNote(com.yydcdut.note.entity.PhotoNote) Comparator(java.util.Comparator) YLog(com.yydcdut.note.utils.YLog) IView(com.yydcdut.note.views.IView) PhotoNoteCreateEvent(com.yydcdut.note.bus.PhotoNoteCreateEvent) Subscriber(rx.Subscriber) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 14 with PhotoNote

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();
}
Also used : RxPhotoNote(com.yydcdut.note.model.rx.RxPhotoNote) PhotoNote(com.yydcdut.note.entity.PhotoNote) Context(android.content.Context) Rect(android.graphics.Rect) RxPhotoNote(com.yydcdut.note.model.rx.RxPhotoNote) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SandPhoto(com.yydcdut.note.entity.SandPhoto) BitmapFactory(android.graphics.BitmapFactory) ExifInterface(android.media.ExifInterface) Inject(javax.inject.Inject) Const(com.yydcdut.note.utils.Const) RxSandBox(com.yydcdut.note.model.rx.RxSandBox) FilePathUtils(com.yydcdut.note.utils.FilePathUtils) Utils(com.yydcdut.note.utils.Utils) ICameraServiceView(com.yydcdut.note.views.service.ICameraServiceView) ImageFormat(android.graphics.ImageFormat) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) SandExif(com.yydcdut.note.entity.SandExif) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Bitmap(android.graphics.Bitmap) YuvImage(android.graphics.YuvImage) ICameraServicePresenter(com.yydcdut.note.presenters.service.ICameraServicePresenter) PhotoNote(com.yydcdut.note.entity.PhotoNote) Queue(java.util.Queue) YLog(com.yydcdut.note.utils.YLog) IView(com.yydcdut.note.views.IView) InputStream(java.io.InputStream) Bitmap(android.graphics.Bitmap) IOException(java.io.IOException)

Example 15 with PhotoNote

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;
}
Also used : PhotoNote(com.yydcdut.note.entity.PhotoNote) ContentValues(android.content.ContentValues) SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Aggregations

PhotoNote (com.yydcdut.note.entity.PhotoNote)18 RxPhotoNote (com.yydcdut.note.model.rx.RxPhotoNote)10 Context (android.content.Context)8 FilePathUtils (com.yydcdut.note.utils.FilePathUtils)8 YLog (com.yydcdut.note.utils.YLog)8 IView (com.yydcdut.note.views.IView)8 ArrayList (java.util.ArrayList)8 Inject (javax.inject.Inject)8 Handler (android.os.Handler)7 RxSandBox (com.yydcdut.note.model.rx.RxSandBox)7 Utils (com.yydcdut.note.utils.Utils)7 FileNotFoundException (java.io.FileNotFoundException)7 IOException (java.io.IOException)7 List (java.util.List)7 R (com.yydcdut.note.R)6 Category (com.yydcdut.note.entity.Category)6 ContextLife (com.yydcdut.note.injector.ContextLife)6 ComparatorFactory (com.yydcdut.note.model.compare.ComparatorFactory)6 RxCategory (com.yydcdut.note.model.rx.RxCategory)6 Map (java.util.Map)6