Last active
December 9, 2016 07:40
-
-
Save elsennov/7f71fb9d6b043894b0a770ffbc31035f to your computer and use it in GitHub Desktop.
Stream concept using RxNavi and RxJava
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
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