@Override public void checkFavoritesAndSetIcon(int articleId) { Repository.FavoritesRepository favoritesRepository = SQLiteFavoritesRepository.getInstance(); Observable.fromCallable(() -> favoritesRepository.isInFavorites(articleId)) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(result -> view.setFavoritesButton(result)); }
@Override public void toggleFavorite(boolean currentState, ArticleData articleData) { Repository.FavoritesRepository favoritesRepository = SQLiteFavoritesRepository.getInstance(); if (currentState) { view.setFavoritesButton(false); favoritesRepository.removeFavorite(articleData.getId()); } else { view.setFavoritesButton(true); favoritesRepository.addFavorite(articleData); } }