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)));
}
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)));
}
}
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)));
}
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;
}
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());
}
Aggregations