Search in sources :

Example 1 with CategoryEditEvent

use of com.yydcdut.note.bus.CategoryEditEvent 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 -> {
            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();
            }
        }), (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)1 Handler (android.os.Handler)1 Message (android.os.Message)1 R (com.yydcdut.note.R)1 CategoryDeleteEvent (com.yydcdut.note.bus.CategoryDeleteEvent)1 CategoryEditEvent (com.yydcdut.note.bus.CategoryEditEvent)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 IEditCategoryPresenter (com.yydcdut.note.presenters.setting.IEditCategoryPresenter)1 FilePathUtils (com.yydcdut.note.utils.FilePathUtils)1 YLog (com.yydcdut.note.utils.YLog)1 IView (com.yydcdut.note.views.IView)1 IEditCategoryView (com.yydcdut.note.views.setting.IEditCategoryView)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1