use of rx.Subscriber in project PhotoNoter by yydcdut.
the class RxUser method saveEvernote.
public Observable<IUser> saveEvernote() {
return Observable.create(new Observable.OnSubscribe<IUser>() {
@Override
public void call(Subscriber<? super IUser> subscriber) {
if (mEvernoteSession.isLoggedIn()) {
try {
User user = mEvernoteSession.getEvernoteClientFactory().getUserStoreClient().getUser();
mEvernoteUser = new EvernoteUser(user.getUsername());
SharedPreferences.Editor editor = mSharedPreferences.edit();
editor.putString(EVERNOTE_NAME, mEvernoteUser.getName());
editor.commit();
subscriber.onNext(mEvernoteUser);
} catch (EDAMUserException e) {
YLog.e(e);
subscriber.onError(e);
} catch (EDAMSystemException e) {
YLog.e(e);
subscriber.onError(e);
} catch (TException e) {
YLog.e(e);
subscriber.onError(e);
}
} else {
subscriber.onError(new RxException("没有登录"));
}
subscriber.onCompleted();
}
}).subscribeOn(Schedulers.io());
}
use of rx.Subscriber in project PhotoNoter by yydcdut.
the class RxGalleryPhotos method findByMedia.
@NonNull
public Observable<Map<String, MediaFolder>> findByMedia() {
return Observable.create(new Observable.OnSubscribe<Map<String, MediaFolder>>() {
@Override
public void call(Subscriber<? super Map<String, MediaFolder>> subscriber) {
if (mMediaCache == null || mMediaCache.size() == 0) {
mMediaCache = new HashMap<>();
MediaFolder mediaFolder4All = new MediaFolder(MediaFolder.ALL, new ArrayList<MediaPhoto>());
mMediaCache.put(MediaFolder.ALL, mediaFolder4All);
findInDatabase(mediaFolder4All);
}
subscriber.onNext(mMediaCache);
}
}).subscribeOn(Schedulers.io());
}
use of rx.Subscriber in project wh-app-android by WhiteHouse.
the class GalleryFragment method onFavoriteItemSelected.
private void onFavoriteItemSelected(boolean favorited) {
Observable<Boolean> obsAction;
FeedItem item = mFeedItems.get(mIndex);
if (favorited) {
obsAction = Observable.create((Subscriber<? super Boolean> subscriber) -> {
try {
FavoritesUtils.addToFavorites(getActivity(), FAVORITE_PHOTOS, item);
mFeedItems.set(mIndex, new FeedItem.Builder(item).setFavorited(true).build());
subscriber.onNext(true);
} catch (Exception e) {
Timber.w(e, "Unable to add FeedItem to favorites");
subscriber.onError(e);
}
subscriber.onCompleted();
});
obsAction = AndroidObservable.bindFragment(this, obsAction).subscribeOn(Schedulers.io());
bindSubscription(obsAction.subscribe(result -> {
if (result) {
Toast.makeText(getActivity(), R.string.added_to_favorites, Toast.LENGTH_SHORT).show();
}
configureOverflow(result);
}));
} else {
obsAction = Observable.create((Subscriber<? super Boolean> subscriber) -> {
try {
FavoritesUtils.removeFromFavorites(getActivity(), FAVORITE_PHOTOS, item);
mFeedItems.set(mIndex, new FeedItem.Builder(item).setFavorited(false).build());
subscriber.onNext(false);
} catch (Exception e) {
Timber.w(e, "Unable to remove FeedItem from favorites");
subscriber.onError(e);
}
subscriber.onCompleted();
});
obsAction = AndroidObservable.bindFragment(this, obsAction).subscribeOn(Schedulers.io());
bindSubscription(obsAction.subscribe(result -> {
if (!result) {
Toast.makeText(getActivity(), R.string.removed_from_favorites, Toast.LENGTH_SHORT).show();
}
configureOverflow(result);
}));
}
}
Aggregations