Skip to content

Instantly share code, notes, and snippets.

@elsennov
Last active December 9, 2016 07:40
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 elsennov/7f71fb9d6b043894b0a770ffbc31035f to your computer and use it in GitHub Desktop.
Save elsennov/7f71fb9d6b043894b0a770ffbc31035f to your computer and use it in GitHub Desktop.
Stream concept using RxNavi and RxJava
private void initLogout() {
RxNavi.observe(naviComponent, Event.VIEW_CREATED)
.filter(viewCreated -> accountPresenter.isLoggedIn(getContext()))
.observeOn(AndroidSchedulers.mainThread())
.doOnNext(viewCreated -> viewCreated.view()
.findViewById(R.id.account_divider_logout).setVisibility(View.VISIBLE))
.map(viewCreated -> {
View logoutButton = viewCreated.view().findViewById(R.id.account_logout);
logoutButton.setVisibility(View.VISIBLE);
return logoutButton;
})
.flatMap(RxView::clicks)
.switchMap(aVoid -> getLogoutConfirmationObservable())
.filter(confirmed -> confirmed)
.doOnNext(aVoid -> showProgressDialog(false))
.observeOn(Schedulers.io())
.flatMap(aVoid -> accountPresenter.onLogoutConfirmedObservable(getContext()))
.observeOn(AndroidSchedulers.mainThread())
.doOnNext(confirmed -> hideProgressDialog())
.takeUntil(RxNavi.observe(naviComponent, Event.DESTROY))
.subscribe(
confirmed -> {
SkyfishUi.lure().launchSfeLoginForm(getContext());
},
throwable -> {
LogUtils.error(TAG, "Error in initLogout", throwable);
accountPresenter.handleErrorGenerally(throwable, baseActivity);
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment