Last active
September 11, 2018 18:20
-
-
Save adrianhall/a7bf292ffda7b63472b36b5a3ab1be8d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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