Search in sources :

Example 1 with CategoryDeleteEvent

use of com.yydcdut.note.bus.CategoryDeleteEvent in project PhotoNoter by yydcdut.

the class HomePresenterImpl method onCategoryDeleteEvent.

@Subscribe(threadMode = ThreadMode.MAIN)
public void onCategoryDeleteEvent(CategoryDeleteEvent categoryDeleteEvent) {
    mRxCategory.getAllCategories().observeOn(AndroidSchedulers.mainThread()).subscribe(categories -> {
        int beforeCategoryId = mCategoryId;
        for (Category category : categories) {
            if (category.isCheck()) {
                mCategoryId = category.getId();
                break;
            }
        }
        mHomeView.updateCategoryList(categories);
        if (mCategoryId != beforeCategoryId) {
            mHomeView.changePhotos4Category(mCategoryId);
        }
    }, (throwable -> YLog.e(throwable)));
}
Also used : Context(android.content.Context) RxPhotoNote(com.yydcdut.note.model.rx.RxPhotoNote) PhotoNoteDeleteEvent(com.yydcdut.note.bus.PhotoNoteDeleteEvent) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) Intent(android.content.Intent) RxUser(com.yydcdut.note.model.rx.RxUser) Inject(javax.inject.Inject) CategoryUpdateEvent(com.yydcdut.note.bus.CategoryUpdateEvent) UserImageEvent(com.yydcdut.note.bus.UserImageEvent) Const(com.yydcdut.note.utils.Const) Handler(android.os.Handler) ContextLife(com.yydcdut.note.injector.ContextLife) EventBus(org.greenrobot.eventbus.EventBus) Category(com.yydcdut.note.entity.Category) FilePathUtils(com.yydcdut.note.utils.FilePathUtils) SDKInitializer(com.baidu.mapapi.SDKInitializer) PermissionUtils(com.yydcdut.note.utils.PermissionUtils) RxCategory(com.yydcdut.note.model.rx.RxCategory) CategoryMoveEvent(com.yydcdut.note.bus.CategoryMoveEvent) IHomePresenter(com.yydcdut.note.presenters.home.IHomePresenter) IHomeView(com.yydcdut.note.views.home.IHomeView) PhotoNoteCreateEvent(com.yydcdut.note.bus.PhotoNoteCreateEvent) ThreadMode(org.greenrobot.eventbus.ThreadMode) CategoryEditEvent(com.yydcdut.note.bus.CategoryEditEvent) Subscribe(org.greenrobot.eventbus.Subscribe) Permission(com.yydcdut.note.utils.permission.Permission) ComparatorFactory(com.yydcdut.note.model.compare.ComparatorFactory) ImageLoaderManager(com.yydcdut.note.utils.ImageManager.ImageLoaderManager) CategoryCreateEvent(com.yydcdut.note.bus.CategoryCreateEvent) CategoryDeleteEvent(com.yydcdut.note.bus.CategoryDeleteEvent) AspectPermission(com.yydcdut.note.aspect.permission.AspectPermission) Activity(android.app.Activity) YLog(com.yydcdut.note.utils.YLog) IView(com.yydcdut.note.views.IView) Category(com.yydcdut.note.entity.Category) RxCategory(com.yydcdut.note.model.rx.RxCategory) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 2 with CategoryDeleteEvent

use of com.yydcdut.note.bus.CategoryDeleteEvent in project PhotoNoter by yydcdut.

the class EditCategoryPresenterImpl method handleMessage.

@Override
public boolean handleMessage(Message msg) {
    switch(msg.what) {
        case MESSAGE_RENAME_NONE:
            deleteCategories();
            return false;
        case MESSAGE_DELETE_NONE:
            sortCategories();
            return false;
        case MESSAGE_FINISH:
            if (mDeleteCategoryIdList.size() > 0) {
                EventBus.getDefault().post(new CategoryDeleteEvent());
            } else {
                EventBus.getDefault().post(new CategoryEditEvent());
            }
            mEditCategoryView.hideProgressBar();
            mEditCategoryView.finishActivity();
            return false;
        default:
            mCurrentMessage++;
            break;
    }
    if (mCurrentMessage == mRenameCategoryLabelMap.size()) {
        deleteCategories();
    } else if (mCurrentMessage == mRenameCategoryLabelMap.size() + mDeleteCategoryIdList.size()) {
        sortCategories();
    } else if (mCurrentMessage == mRenameCategoryLabelMap.size() + mDeleteCategoryIdList.size() + 1) {
        mRxCategory.getAllCategories().subscribe((categories -> {
            // todo 删除图片,删除PhotoNote
            boolean checked = false;
            for (Category category : categories) {
                checked |= category.isCheck();
            }
            if (!checked && categories.size() > 0) {
                categories.get(0).setCheck(true);
                mRxCategory.updateCategory(categories.get(0)).subscribe();
            }
        // todo 当所有的都没有了怎么办
        }), (throwable -> YLog.e(throwable)), () -> mHandler.sendEmptyMessage(MESSAGE_FINISH));
    }
    return false;
}
Also used : Context(android.content.Context) RxPhotoNote(com.yydcdut.note.model.rx.RxPhotoNote) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) HashMap(java.util.HashMap) IEditCategoryPresenter(com.yydcdut.note.presenters.setting.IEditCategoryPresenter) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) 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) Schedulers(rx.schedulers.Schedulers) R(com.yydcdut.note.R) RxCategory(com.yydcdut.note.model.rx.RxCategory) Iterator(java.util.Iterator) CategoryEditEvent(com.yydcdut.note.bus.CategoryEditEvent) IEditCategoryView(com.yydcdut.note.views.setting.IEditCategoryView) List(java.util.List) Message(android.os.Message) ComparatorFactory(com.yydcdut.note.model.compare.ComparatorFactory) CategoryDeleteEvent(com.yydcdut.note.bus.CategoryDeleteEvent) PhotoNote(com.yydcdut.note.entity.PhotoNote) YLog(com.yydcdut.note.utils.YLog) IView(com.yydcdut.note.views.IView) Category(com.yydcdut.note.entity.Category) RxCategory(com.yydcdut.note.model.rx.RxCategory) CategoryDeleteEvent(com.yydcdut.note.bus.CategoryDeleteEvent) CategoryEditEvent(com.yydcdut.note.bus.CategoryEditEvent)

Aggregations

Context (android.content.Context)2 Handler (android.os.Handler)2 CategoryDeleteEvent (com.yydcdut.note.bus.CategoryDeleteEvent)2 CategoryEditEvent (com.yydcdut.note.bus.CategoryEditEvent)2 Category (com.yydcdut.note.entity.Category)2 ContextLife (com.yydcdut.note.injector.ContextLife)2 ComparatorFactory (com.yydcdut.note.model.compare.ComparatorFactory)2 RxCategory (com.yydcdut.note.model.rx.RxCategory)2 RxPhotoNote (com.yydcdut.note.model.rx.RxPhotoNote)2 FilePathUtils (com.yydcdut.note.utils.FilePathUtils)2 YLog (com.yydcdut.note.utils.YLog)2 IView (com.yydcdut.note.views.IView)2 Inject (javax.inject.Inject)2 EventBus (org.greenrobot.eventbus.EventBus)2 AndroidSchedulers (rx.android.schedulers.AndroidSchedulers)2 Activity (android.app.Activity)1 Intent (android.content.Intent)1 Message (android.os.Message)1 SDKInitializer (com.baidu.mapapi.SDKInitializer)1 R (com.yydcdut.note.R)1