Skip to content

Instantly share code, notes, and snippets.

@ininmm
Last active September 18, 2019 01:41
Show Gist options
  • Save ininmm/5d836178b8b052eb18449da6e7b44305 to your computer and use it in GitHub Desktop.
Save ininmm/5d836178b8b052eb18449da6e7b44305 to your computer and use it in GitHub Desktop.
同步的 ViewModel
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