Skip to content

Instantly share code, notes, and snippets.

@tcw165
Last active February 19, 2018 02:03
Show Gist options
  • Save tcw165/3e51c89e6a587460ffa1dc4aa038d83d to your computer and use it in GitHub Desktop.
Save tcw165/3e51c89e6a587460ffa1dc4aa038d83d to your computer and use it in GitHub Desktop.
// 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