Skip to content

Instantly share code, notes, and snippets.

@adrianhall
Created April 6, 2018 23:30
Show Gist options
  • Save adrianhall/dcf5610f211ec93eeff1a87218439a7b to your computer and use it in GitHub Desktop.
Save adrianhall/dcf5610f211ec93eeff1a87218439a7b to your computer and use it in GitHub Desktop.
Sign-in and Sign-out methods
/**
* 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