Skip to content

Instantly share code, notes, and snippets.

@adevone
Last active December 4, 2020 17:08
Show Gist options
  • Save adevone/780cba18cdcd6d5dc8d85a17a135631b to your computer and use it in GitHub Desktop.
Save adevone/780cba18cdcd6d5dc8d85a17a135631b to your computer and use it in GitHub Desktop.
interface LoginByPhoneView {
fun displayState(state: LoginByPhoneState)
}
enum class LoginByPhoneState {
Request,
Confirm
}
class LoginByPhonePresenter {
private var stateToApply: LoginByPhoneState? = null
private var view: LoginByPhoneView? = null
fun onViewCreated(view: LoginByPhoneView) {
this.view = view
if (stateToApply != null) {
view.displayState(stateToApply!!)
stateToApply = null
}
}
fun onViewDestroyed() {
this.view = null
}
fun onRequestCodeClick() {
launch {
val code = requestCodeRepository.execute()
if (view != null) {
view?.displayState(LoginByPhoneState.Confirm)
} else {
stateToApply = LoginByPhoneState.Confirm
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment