Search in sources :

Example 6 with Category

use of com.yydcdut.note.entity.Category in project PhotoNoter by yydcdut.

the class EditCategoryPresenterImpl method deleteCategory.

@Override
public void deleteCategory(int index) {
    mRxCategory.getAllCategories().map(categories -> {
        Category category = categories.get(index);
        categories.remove(category);
        return category;
    }).observeOn(AndroidSchedulers.mainThread()).subscribe(category1 -> {
        mDeleteCategoryIdList.add(category1.getId());
        mEditCategoryView.updateListView();
    }, (throwable -> YLog.e(throwable)));
}
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)

Example 7 with Category

use of com.yydcdut.note.entity.Category in project PhotoNoter by yydcdut.

the class HomePresenterImpl method updateFromBroadcast.

@Override
public void updateFromBroadcast(boolean broadcast_process, boolean broadcast_service) {
    // 有时候categoryLabel为null,感觉原因是activity被回收了,但是一直解决不掉,所以迫不得已的解决办法
    if (mCategoryId == -1) {
        mRxCategory.getAllCategories().subscribe(categories -> {
            for (Category category : categories) {
                if (category.isCheck()) {
                    mCategoryId = category.getId();
                }
            }
        }, (throwable -> YLog.e(throwable)));
    }
    // 从另外个进程过来的数据
    if (broadcast_process) {
        mRxPhotoNote.refreshByCategoryId(mCategoryId, ComparatorFactory.FACTORY_NOT_SORT).subscribe(photoNoteList -> {
            mRxCategory.findByCategoryId(mCategoryId).subscribe(category -> {
                category.setPhotosNumber(photoNoteList.size());
                mRxCategory.updateCategory(category).observeOn(AndroidSchedulers.mainThread()).subscribe(categories -> {
                    mHomeView.notifyCategoryDataChanged();
                }, (throwable -> YLog.e(throwable)));
            }, (throwable -> YLog.e(throwable)));
        });
    }
    // 从Service中来
    if (broadcast_service) {
        mRxCategory.getAllCategories().observeOn(AndroidSchedulers.mainThread()).subscribe(categories -> mHomeView.updateCategoryList(categories), (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)

Example 8 with Category

use of com.yydcdut.note.entity.Category 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 9 with Category

use of com.yydcdut.note.entity.Category in project PhotoNoter by yydcdut.

the class CategoryDB method delete.

/**
 * 删除分类
 *
 * @param categories
 * @return
 */
public synchronized int delete(Category... categories) {
    SQLiteDatabase db = mNotesSQLite.getWritableDatabase();
    db.beginTransaction();
    int rows = 0;
    try {
        for (Category category : categories) {
            rows += db.delete(NotesSQLite.TABLE_CATEGORY, "_id = ?", new String[] { category.getId() + "" });
        }
        db.setTransactionSuccessful();
    } catch (Exception e) {
        YLog.e(e);
        return -1;
    } finally {
        // 处理完成
        db.endTransaction();
        db.close();
    }
    return rows;
}
Also used : Category(com.yydcdut.note.entity.Category) SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Example 10 with Category

use of com.yydcdut.note.entity.Category in project PhotoNoter by yydcdut.

the class RxCategory method updateOrder.

/**
 * 更新顺序
 *
 * @return
 */
public Observable<List<Category>> updateOrder() {
    return Observable.create((Observable.OnSubscribe<List<Category>>) subscriber -> {
        for (int i = 0; i < mCache.size(); i++) {
            Category category = mCache.get(i);
            category.setSort(i);
            mCategoryDB.update(category);
        }
        subscriber.onNext(mCache);
        subscriber.onCompleted();
    }).subscribeOn(Schedulers.io());
}
Also used : Category(com.yydcdut.note.entity.Category)

Aggregations

Category (com.yydcdut.note.entity.Category)14 Context (android.content.Context)8 Inject (javax.inject.Inject)8 ContextLife (com.yydcdut.note.injector.ContextLife)7 RxCategory (com.yydcdut.note.model.rx.RxCategory)7 FilePathUtils (com.yydcdut.note.utils.FilePathUtils)7 List (java.util.List)7 Handler (android.os.Handler)6 ComparatorFactory (com.yydcdut.note.model.compare.ComparatorFactory)6 RxPhotoNote (com.yydcdut.note.model.rx.RxPhotoNote)6 YLog (com.yydcdut.note.utils.YLog)6 PhotoNote (com.yydcdut.note.entity.PhotoNote)5 IView (com.yydcdut.note.views.IView)5 EventBus (org.greenrobot.eventbus.EventBus)5 AndroidSchedulers (rx.android.schedulers.AndroidSchedulers)5 Schedulers (rx.schedulers.Schedulers)5 Intent (android.content.Intent)4 R (com.yydcdut.note.R)4 CategoryDeleteEvent (com.yydcdut.note.bus.CategoryDeleteEvent)4 CategoryEditEvent (com.yydcdut.note.bus.CategoryEditEvent)4