Created
June 28, 2018 14:04
-
-
Save davidbilik/e6acde75483415740c0031eefb8844bc to your computer and use it in GitHub Desktop.
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 Fragment.handleErrors(error:Throwable) { | |
when (error) { | |
is NoInternetConnectionException -> snackbar(view, R.string.general_no_connection_error) | |
is GeneralServerException -> snackbar(view, R.string.general_server_error) | |
else -> throw error | |
} | |
} | |
class LoginFragment : Fragment { | |
val viewModel: LoginViewModel | |
var disposables: CompositeDisposable | |
fun onViewCreated() { | |
disposables += viewModel.observeLoginResult() | |
.observeOnMainThread() | |
.subscribe { | |
when (it) { | |
is LoginResult.LoginOk -> finishLogin() | |
is LoginResult.LoginError -> { | |
when (it.error) { | |
is InvalidCredentialsException -> showInvalidCredentialsError() | |
is ValidationException -> showValidationErrors(it.error.errors) | |
else -> handleErrors(it.error) | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment