use of com.yydcdut.note.model.rx.exception.RxException in project PhotoNoter by yydcdut.
the class RxCategory method saveCategory.
/**
* 添加Category,这个category的check是true
* 要做的事情:
* 1、判断是否有这个字段了
* 2、将其他的Category都取消check
*
* @param label
* @param photosNumber
* @param sort
* @param isCheck
* @return
*/
public Observable<List<Category>> saveCategory(String label, int photosNumber, int sort, boolean isCheck) {
return Observable.create(new Observable.OnSubscribe<Long>() {
private int mInTimes = 0;
@Override
public void call(Subscriber<? super Long> subscriber) {
boolean exist = checkLabelExist(label);
if (exist && mInTimes == 0) {
//在没有mInTimes的时候,这里也会执行,不知道为啥.......
subscriber.onError(new RxException("这个Label已经有了"));
} else {
mInTimes++;
long id = mCategoryDB.save(label, photosNumber, sort, /* isCheck */
true);
if (mCache.size() != 0) {
subscriber.onNext(id);
subscriber.onCompleted();
} else {
//如果mCache中没有数据,直接跳到lift中
subscriber.onCompleted();
}
}
}
}).subscribeOn(Schedulers.io()).map(//重新获取cache数据
aLong -> mCache).flatMap(//转换成一个个的
categories1 -> Observable.from(categories1)).filter(//过滤出check为true的
category -> category.isCheck()).lift(new Observable.Operator<List<Category>, Category>() {
@Override
public Subscriber<? super Category> call(Subscriber<? super List<Category>> subscriber) {
return new Subscriber<Category>() {
@Override
public void onCompleted() {
mCache.clear();
mCache.addAll(mCategoryDB.findAll());
subscriber.onNext(mCache);
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(Category category3) {
//如果有check为true的话,进入到这里,如果没有的话直接进入到onCompleted
category3.setCheck(false);
mCategoryDB.update(category3);
}
};
}
});
}
use of com.yydcdut.note.model.rx.exception.RxException in project PhotoNoter by yydcdut.
the class RxCategory method setCategoryMenuPosition.
/**
* 设置check哪个category
*
* @param _id
* @return
*/
public Observable<List<Category>> setCategoryMenuPosition(int _id) {
return Observable.from(mCache).subscribeOn(Schedulers.io()).filter(//过滤出check为true的
category -> category.isCheck()).map(category3 -> {
category3.setCheck(false);
mCategoryDB.update(category3);
return mCache;
}).flatMap(//转换成一个个Category来处理
categories -> Observable.from(categories)).filter(//过滤出与ID相同的Category
category1 -> category1.getId() == _id).lift(new Observable.Operator<Category, Category>() {
@Override
public Subscriber<? super Category> call(Subscriber<? super Category> subscriber) {
return new Subscriber<Category>() {
/* 因为我想经过filter之后,如果没有数据就返回onError,所以设置这个参数 */
private int mInTimes = 0;
@Override
public void onCompleted() {
if (mInTimes == 0) {
subscriber.onError(new RxException("找不到这个ID的Category"));
}
}
@Override
public void onError(Throwable e) {
subscriber.onError(e);
}
@Override
public void onNext(Category category) {
mInTimes++;
subscriber.onNext(category);
}
};
}
}).map(category2 -> {
category2.setCheck(true);
int row = mCategoryDB.update(category2);
return row > 0 ? mCache : mCategoryDB.findAll();
});
}
use of com.yydcdut.note.model.rx.exception.RxException in project PhotoNoter by yydcdut.
the class RxUser method getQQ.
public Observable<IUser> getQQ() {
return Observable.create(new Observable.OnSubscribe<IUser>() {
@Override
public void call(Subscriber<? super IUser> subscriber) {
if (mQQUser == null) {
String name = mSharedPreferences.getString(Q_NAME, NAME_DEFAULT);
String netImagePath = mSharedPreferences.getString(Q_NET_IMAGE_PATH, Q_NET_IMAGE_PATH_DEFAULT);
if (TextUtils.isEmpty(name) || TextUtils.isEmpty(netImagePath)) {
subscriber.onError(new RxException("没有登录!!!"));
return;
} else {
mQQUser = new QQUser(name, netImagePath);
}
}
subscriber.onNext(mQQUser);
subscriber.onCompleted();
}
}).subscribeOn(Schedulers.io());
}
use of com.yydcdut.note.model.rx.exception.RxException in project PhotoNoter by yydcdut.
the class RxUser method getEvernote.
public Observable<IUser> getEvernote() {
return Observable.create(new Observable.OnSubscribe<IUser>() {
@Override
public void call(Subscriber<? super IUser> subscriber) {
if (mEvernoteUser == null) {
String name = mSharedPreferences.getString(EVERNOTE_NAME, NAME_DEFAULT);
if (TextUtils.isEmpty(name)) {
subscriber.onError(new RxException("没有登录!!!"));
} else {
mEvernoteUser = new EvernoteUser(name);
}
}
subscriber.onNext(mEvernoteUser);
subscriber.onCompleted();
}
}).subscribeOn(Schedulers.io());
}
use of com.yydcdut.note.model.rx.exception.RxException in project PhotoNoter by yydcdut.
the class SplashPresenterImpl method checkDisks.
private void checkDisks() {
if (!mLocalStorageUtils.isFirstTime()) {
initFiles();
Observable.create(new Observable.OnSubscribe<File[]>() {
@Override
public void call(Subscriber<? super File[]> subscriber) {
File f = new File(FilePathUtils.getPath());
if (f.exists()) {
subscriber.onNext(f.listFiles());
subscriber.onCompleted();
} else {
subscriber.onError(new RxException(""));
}
}
}).flatMap(fileList -> Observable.from(fileList)).subscribeOn(Schedulers.io()).observeOn(Schedulers.computation()).filter(file1 -> !file1.isDirectory()).filter(file -> file.getName().toLowerCase().endsWith(".jpg") || file.getName().toLowerCase().endsWith(".png") || file.getName().toLowerCase().endsWith(".jpeg")).count().subscribe((fileNumber -> {
mRxSandBox.getNumber().subscribe((integer -> {
if (fileNumber != integer) {
Intent checkIntent = new Intent(mContext, CheckService.class);
mContext.startService(checkIntent);
}
}), (throwable -> YLog.e(throwable)));
}), (throwable -> YLog.e(throwable)));
}
}
Aggregations