Skip to content

Instantly share code, notes, and snippets.

@adrianhall
Last active September 11, 2018 18:20
Show Gist options
  • Save adrianhall/a7bf292ffda7b63472b36b5a3ab1be8d to your computer and use it in GitHub Desktop.
Save adrianhall/a7bf292ffda7b63472b36b5a3ab1be8d to your computer and use it in GitHub Desktop.
override fun onNavigationItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.main_drawer_login -> {
if (service.identityManager.isUserSignedIn) {
service.identityManager.signOut()
updateNavigationDrawer(service.identityManager.isUserSignedIn)
} else {
service.identityManager.login(this@MainActivity, object : DefaultSignInResultHandler() {
/**
* Called when the user has obtained an identity by signing in with a provider.
*
* @param callingActivity the calling activity that should be finished.
* @param provider the provider or null if succeeded with an unauthenticated identity.
*/
override fun onSuccess(callingActivity: Activity?, provider: IdentityProvider?) {
if (service.identityManager.isUserSignedIn) {
analyticsService.recordSuccessfulLogin(service.identityManager.cachedUserID)
updateNavigationDrawer(true)
} else {
analyticsService.recordFailedLogin()
updateNavigationDrawer(false)
}
}
/**
* User pressed back from the sign-in Activity.
*
* @return true if the activity should be finished, otherwise false.
*/
override fun onCancel(callingActivity: Activity?): Boolean = true
})
val authConfig = AuthUIConfiguration.Builder()
.userPools(true)
.build()
SignInActivity.startSignInActivity(this@MainActivity, authConfig)
}
}
}
drawer_layout.closeDrawer(GravityCompat.START)
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment