Created
April 6, 2018 23:30
-
-
Save adrianhall/dcf5610f211ec93eeff1a87218439a7b to your computer and use it in GitHub Desktop.
Sign-in and Sign-out methods
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
/** | |
* Hook called when the user requests to sign-in to the application | |
*/ | |
private fun onLoginMenuItemSelected(): Boolean { | |
// Close the options menu | |
closeOptionsMenu() | |
// Produce the Alert dialog with the login form | |
val formView = layoutInflater.inflate(R.layout.login_form, null, false) | |
val username = formView.find<EditText>(R.id.login_form_username) | |
val password = formView.find<EditText>(R.id.login_form_password) | |
AlertDialog.Builder(this) | |
.setView(formView) | |
.setNegativeButton("Cancel") { _, _ -> toast("Cancelled") } | |
.setPositiveButton("Sign In") { _, _ -> model.signin(username.getContent(), password.getContent()) } | |
.show() | |
// We handled the request | |
return true | |
} | |
/** | |
* Hook called when the user requests to sign-out of the application | |
*/ | |
private fun onLogoutMenuItemSelected(): Boolean { | |
// Close the options menu | |
closeOptionsMenu() | |
// Produce an Are You Sure? dialog | |
alert("Are you sure you want to sign out?") { | |
yesButton { model.signout() } | |
noButton { } | |
}.show() | |
// We handled the request | |
return true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment