Last active
February 19, 2018 02:03
-
-
Save tcw165/3e51c89e6a587460ffa1dc4aa038d83d to your computer and use it in GitHub Desktop.
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
// Hold the disposable in order to cancel the operation later. | |
val sharingDisposable = mView | |
.onClickStart() | |
.switchMap { _ -> | |
// 1. Generate BMP | |
getGenBmpObservable() | |
// 2. Show dialog | |
.switchMap { _ -> | |
getDialogSingle().toObservable() | |
} | |
// 3. Share | |
.switchMap { dialogPayload -> | |
if (dialogPayload.result == RESULT_OK) { | |
// If the user clicks OK, share to FB. | |
getShareToFacebookObservable(dialogPayload.data) | |
} else { | |
// The EMPTY observable calls observer's onComplete() | |
// to indicate the stream is over. | |
Observable.empty() | |
} | |
} | |
} | |
.subscribe { _ -> | |
Log.d("xyz", "all finished!") | |
}) | |
// When the cancel signal is received, dispose the observable chain. | |
onClickCancel() | |
.subscribe { _ -> | |
sharingDisposable.dispose() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment