use of gov.whitehouse.util.FavoritesUtils.FAVORITE_PHOTOS 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