Search in sources :

Example 1 with CategoryMoveEvent

use of com.yydcdut.note.bus.CategoryMoveEvent 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)));
    }
}
Also used : 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) RxPhotoNote(com.yydcdut.note.model.rx.RxPhotoNote) PhotoNote(com.yydcdut.note.entity.PhotoNote) TreeMap(java.util.TreeMap) CategoryMoveEvent(com.yydcdut.note.bus.CategoryMoveEvent)

Aggregations

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