Skip to content

Instantly share code, notes, and snippets.

@Majirefy
Created March 20, 2017 02:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Majirefy/07c61350e4093dab401e007b9f786576 to your computer and use it in GitHub Desktop.
Save Majirefy/07c61350e4093dab401e007b9f786576 to your computer and use it in GitHub Desktop.
private class PlayServiceListener : GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
override fun onConnected(bundle: Bundle?) {
Toast.makeText(context, R.string.login_succeed, Toast.LENGTH_SHORT).show()
GameManager.listener?.loadHighScore()
}
override fun onConnectionSuspended(i: Int) {
// Attempt to reconnect
mGoogleApiClient?.connect()
}
override fun onConnectionFailed(connectionResult: ConnectionResult) {
if (mResolvingError) {
// Already attempting to resolve an error.
return
} else if (connectionResult.hasResolution()) {
try {
mResolvingError = true
connectionResult.startResolutionForResult(context as Activity, REQUEST_RESOLVE_ERROR)
} catch (e: IntentSender.SendIntentException) {
// There was an error with the resolution intent. Try again.
mGoogleApiClient?.connect()
}
} else {
// Show dialog using GoogleApiAvailability.getErrorDialog()
Toast.makeText(context, R.string.login_failed, Toast.LENGTH_SHORT).show()
mResolvingError = true
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment