Search in sources :

Example 1 with PhotoNoteCreateEvent

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)));
}
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) 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) AspectPermission(com.yydcdut.note.aspect.permission.AspectPermission) 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) ContentResolver(android.content.ContentResolver)

Example 2 with PhotoNoteCreateEvent

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)));
}
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) 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) AspectPermission(com.yydcdut.note.aspect.permission.AspectPermission) 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 3 with PhotoNoteCreateEvent

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)));
}
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) 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) AspectPermission(com.yydcdut.note.aspect.permission.AspectPermission) YLog(com.yydcdut.note.utils.YLog) IView(com.yydcdut.note.views.IView) PhotoNoteCreateEvent(com.yydcdut.note.bus.PhotoNoteCreateEvent) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Aggregations

ContentResolver (android.content.ContentResolver)3 Context (android.content.Context)3 Uri (android.net.Uri)3 Handler (android.os.Handler)3 TextUtils (android.text.TextUtils)3 R (com.yydcdut.note.R)3 AspectPermission (com.yydcdut.note.aspect.permission.AspectPermission)3 CategoryCreateEvent (com.yydcdut.note.bus.CategoryCreateEvent)3 CategoryMoveEvent (com.yydcdut.note.bus.CategoryMoveEvent)3 PhotoNoteCreateEvent (com.yydcdut.note.bus.PhotoNoteCreateEvent)3 PhotoNoteDeleteEvent (com.yydcdut.note.bus.PhotoNoteDeleteEvent)3 Category (com.yydcdut.note.entity.Category)3 PhotoNote (com.yydcdut.note.entity.PhotoNote)3 ContextLife (com.yydcdut.note.injector.ContextLife)3 ComparatorFactory (com.yydcdut.note.model.compare.ComparatorFactory)3 RxCategory (com.yydcdut.note.model.rx.RxCategory)3 RxPhotoNote (com.yydcdut.note.model.rx.RxPhotoNote)3 RxSandBox (com.yydcdut.note.model.rx.RxSandBox)3 IAlbumPresenter (com.yydcdut.note.presenters.home.IAlbumPresenter)3 FilePathUtils (com.yydcdut.note.utils.FilePathUtils)3