Last active
June 7, 2017 14:16
-
-
Save marcin-adamczewski/091a00e38213ce88f5403ec770d0aea1 to your computer and use it in GitHub Desktop.
Medium Article
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| RxView.clicks(fab) | |
| .throttleFirst(1, TimeUnit.SECONDS) // prevents crazy clicks | |
| .observeOn(AndroidSchedulers.mainThread()) | |
| .switchMap(ignore -> favoritesManager.addOrRemoveFromFavs(postId)) // toggle cache state and make API request | |
| .subscribe(responseOrError -> { | |
| if (responseOrError.isError()) { | |
| Toast.makeText(PostDetailsActivity.this, "API error", Toast.LENGTH_SHORT).show(); | |
| } | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| favsManager.getFavObservable(postId) | |
| .subscribe(isFavorite -> favButton.setFavorite(isFavrotie)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| favoritesManager.getIsFavoriteObservable(postId) | |
| .subscribe(isFavorite -> fab.setImageDrawable(getResources().getDrawable(isFavorite ? | |
| R.drawable.ic_favorite_black_24dp : R.drawable.ic_favorite_border_black_24dp))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void onFavoriteButtonClick() { | |
| favoriteButton.setFavorite(favoriteButton.isFavrotie()) | |
| makeFavRequest(favoriteButton.isFavrotie()) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| favoritesManager.toggleValue(postId); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment