This file contains 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
import org.junit.Test | |
import kotlin.test.assertEquals | |
import kotlin.test.assertTrue | |
object FileNameUtils { | |
private const val forbiddenFileNameCharsRegexp = "([\\\\<>:?\"*|/])" | |
fun removeForbiddenCharactersFromFileName(fileName: String): String { | |
return fileName.replace(forbiddenFileNameCharsRegexp.toRegex(), "") |
This file contains 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 updateFavorite(final @NonNull Integer id, final boolean favorite) { | |
favoritesCache.get(id).onNext(favorite); | |
} |
This file contains 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
favsApi.fetchFavoritesRequest() | |
.doOnNext(this::updateFavoritesCache); |
This file contains 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
public Observable<ResponseOrError<String>> addOrRemoveFromFavs(final int postId) { | |
return getIsFavoriteObservable(postId) | |
.take(1) // take first value from cache | |
.doOnNext(isCurrentlyFavorite -> { | |
updateFavorite(postId, !isCurrentlyFavorite); // toggle value before request for better User Experience | |
}) | |
.switchMap(isCurrentlyFavorite -> favsApi.addOrRemoveFromFavs(isCurrentlyFavorite) | |
.compose(ResponseOrError.toResponseOrErrorObservable()) // it's changing error event to onNext event to not finish a chain | |
.doOnNext(responseOrError -> { | |
if (responseOrError.isError()) { |
This file contains 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
favoritesCache = new Cache<Integer, BehaviorSubject<Boolean>>(new Cache.CacheProvider<>() { | |
@Override | |
public BehaviorSubject<Boolean> load(@Nonnull final Integer postId) { | |
return BehaviorSubject.create(false); | |
} | |
}); |
This file contains 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.getIsFavoriteObservable(postId) | |
.subscribe(isFavorite -> favButton.setFavorite(isFavorite)); |
This file contains 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.isFavorite()) // toggle state | |
makeFavRequest(favoriteButton.isFavorite()) | |
} |
This file contains 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(favButton) | |
.throttleFirst(1, TimeUnit.SECONDS) //Prevents from crazy clicks | |
.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 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 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
swagger: "2.0" | |
info: | |
version: 1.0.0 | |
title: Zumba's API | |
description: Documentation about Zumba's API. | |
contact: | |
name: Zumba Engineering Team | |
email: [email protected] | |
url: https://tech.zumba.com | |
host: apiv3.zumba.com |
NewerOlder