Last active
September 18, 2019 01:41
-
-
Save ininmm/5d836178b8b052eb18449da6e7b44305 to your computer and use it in GitHub Desktop.
同步的 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
class ViewModel { | |
fun getToken(): Token { | |
// 做一些 API 耗時操作 | |
return token 請求 access token | |
} | |
fun verify(token, userName): Boolean { | |
// 做一些 API 耗時操作 | |
return result // 登入成功或失敗 | |
} | |
fun requestAndSaveUserData(userName): { | |
// 做一些 API 耗時操作 | |
return Success // 取得一些登入者的資料 | |
} | |
...... | |
fun login(userName: String) { | |
val token = getToken() | |
val result = verify(token, userName) | |
if (result) { | |
val success = requestAndSaveUserData(userName) | |
if (success) { | |
showLoginSuccess("Success") | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment