use of rx.Subscriber in project Rutgers-Course-Tracker by tevjef.
the class SubjectPresenterImpl method loadSubjects.
@Override
public void loadSubjects(boolean pullToRefresh) {
if (getView() != null)
getView().showLoading(pullToRefresh);
cancePreviousSubscription();
Subscriber<List<Subject>> mSubscriber = new Subscriber<List<Subject>>() {
@Override
public void onCompleted() {
if (getView() != null)
getView().showLoading(false);
}
@Override
public void onError(Throwable e) {
//Lets the view decide what to display depending on what type of exception it is.
if (getView() != null)
getView().showError(e);
//Removes the animated loading drawable
if (getView() != null) {
getView().showLoading(false);
}
}
@Override
public void onNext(List<Subject> subjectList) {
if (getView() != null) {
getView().setData(subjectList);
if (subjectList.size() == 0)
getView().showError(new RutgersDataIOException());
if (subjectList.size() > 0)
getView().showLayout(View.LayoutType.LIST);
}
}
};
mSubscription = mRetroRutgers.getSubjects(mRequest).doOnSubscribe(new Action0() {
@Override
public void call() {
isLoading = true;
}
}).doOnTerminate(new Action0() {
@Override
public void call() {
isLoading = false;
}
}).subscribeOn(mBackgroundThread).observeOn(mMainThread).subscribe(mSubscriber);
}
use of rx.Subscriber in project Rutgers-Course-Tracker by tevjef.
the class CoursePresenterImpl method loadCourses.
@Override
public void loadCourses(boolean pullToRefresh) {
if (getView() != null)
getView().showLoading(pullToRefresh);
cancePreviousSubscription();
Subscriber<List<Course>> mSubscriber = new Subscriber<List<Course>>() {
@Override
public void onCompleted() {
if (getView() != null)
getView().showLoading(false);
}
@Override
public void onError(Throwable e) {
//Removes the animated loading drawable
if (getView() != null)
getView().showLoading(false);
//Lets the view decide what to display depending on what type of exception it is.
if (getView() != null)
getView().showError(e);
}
@Override
public void onNext(List<Course> courseList) {
if (getView() != null)
getView().setData(courseList);
if (courseList.size() > 0) {
if (getView() != null)
getView().showLayout(View.LayoutType.LIST);
}
}
};
mSubscription = mRetroRutgers.getCourses(mRequest).doOnSubscribe(new Action0() {
@Override
public void call() {
isLoading = true;
}
}).doOnTerminate(new Action0() {
@Override
public void call() {
isLoading = false;
}
}).subscribeOn(mBackgroundThread).observeOn(mMainThread).subscribe(mSubscriber);
}
use of rx.Subscriber in project ListenerMusicPlayer by hefuyicoder.
the class PanelSlideListener method setBlurredAlbumArt.
private void setBlurredAlbumArt() {
Observable.create(new Observable.OnSubscribe<Drawable>() {
@Override
public void call(Subscriber<? super Drawable> subscriber) {
Bitmap bitmap = ((BitmapDrawable) albumImage.getDrawable()).getBitmap();
Drawable drawable = ImageUtil.createBlurredImageFromBitmap(bitmap, mContext, 3);
subscriber.onNext(drawable);
}
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<Drawable>() {
@Override
public void call(Drawable drawable) {
CoordinatorLayout.LayoutParams imageLayout = (CoordinatorLayout.LayoutParams) albumImage.getLayoutParams();
imageLayout.height = FrameLayout.LayoutParams.MATCH_PARENT;
imageLayout.width = FrameLayout.LayoutParams.MATCH_PARENT;
albumImage.setLayoutParams(imageLayout);
albumImage.setImageDrawable(drawable);
if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
ColorDrawable colorDrawable = new ColorDrawable(nowPlayingCardColor);
colorDrawable.setAlpha(200);
albumImage.setForeground(colorDrawable);
}
}
});
}
use of rx.Subscriber 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 rx.Subscriber 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();
});
}
Aggregations