Skip to content

Instantly share code, notes, and snippets.

@Kolyall
Created November 13, 2019 06:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kolyall/d448de268a4b73334fe5ff0a3a16cbd1 to your computer and use it in GitHub Desktop.
Save Kolyall/d448de268a4b73334fe5ff0a3a16cbd1 to your computer and use it in GitHub Desktop.
RxViews

RxViews:

  1. CacheSwitch Button
RxCompoundButton.checkedChanges(mCacheSwitch)
.compose(RxNetworkUtils.builder().sync().build())
.skip(1)
.onBackpressureLatest()
.debounce(250, TimeUnit.MILLISECONDS)
.share()
.switchMap(isChecked ->
mDataPlaceRepository.isCacheAllowed()
.filter(inDbIsChecked -> inDbIsChecked != isChecked)
.flatMap(aBoolean ->
mDataPlaceRepository.updateCache(isChecked) .compose(RxNetworkUtils.builder(getView()).async().errorToast().build()))
.onErrorResumeNext(throwable ->
mDataPlaceRepository.isCacheAllowed()
.compose(RxNetworkUtils.builder(getView()) .async().errorToast().errorHandler().build())
.doOnNext(isCacheActivated -> {
//on Error set restore state from settings
getView().setCachingActivated(isCacheActivated, false);
})
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment