Created
September 18, 2019 01:56
-
-
Save ininmm/0b1d4bc12390c895a1981eccf081a695 to your computer and use it in GitHub Desktop.
使用 RxJava 的 ViewModel
This file contains 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
fun getToken(): Observable<Token> { ...... } | |
fun verify(userName): Observable<Boolean> { | |
return getToken() | |
.flatMap { token -> | |
...... | |
} | |
} | |
fun requestAndSaveUserData(userName: String): Observable<Result> { | |
return verify(userName) | |
.flatMap { ...... } | |
} | |
fun login(userName: String) { | |
requestAndSaveUser(userName) | |
.subscribeOn(Schedulers.io()) | |
.observerOn(AndroidSchedulers.mainThread()) | |
.subscribe({ | |
showLoginSuccess(it) | |
}, { | |
it.printStackTrace() | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment