Guest User

Untitled

a guest
Dec 19th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. package XXX
  2.  
  3. import android.content.Intent
  4. import android.os.Bundle
  5. import au.sjowl.base.basex.BaseActivity
  6. import com.google.android.gms.auth.api.signin.GoogleSignIn
  7. import com.google.android.gms.auth.api.signin.GoogleSignInClient
  8. import io.michaelrocks.lightsaber.getInstance
  9. import kotlinx.android.synthetic.main.activity_auth.*
  10. import kotlinx.coroutines.GlobalScope
  11. import kotlinx.coroutines.launch
  12.  
  13. open class AuthActivity :
  14. BaseActivity<AuthPresenter, AuthView>(),
  15. AuthView {
  16.  
  17. override val layoutId: Int get() = R.layout.activity_auth
  18. override fun providePresenter(): AuthPresenter = appInjector.getInstance()
  19.  
  20. /* ******************** google sign in *********************/
  21.  
  22. override fun onCreate(savedInstanceState: Bundle?) {
  23. super.onCreate(savedInstanceState)
  24.  
  25. signInButton.setOnClickListener { presenter.onGoogleSignIn() }
  26. }
  27.  
  28. public override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
  29. super.onActivityResult(requestCode, resultCode, data)
  30.  
  31. when (requestCode) {
  32. RC_SIGN_IN -> {
  33. val task = GoogleSignIn.getSignedInAccountFromIntent(data)
  34. presenter.onSignedIn(task)
  35. }
  36. }
  37. }
  38.  
  39. /* ******************** View *********************/
  40. override suspend fun closeView() = GlobalScope.launch(uiDispatcher) {
  41. finish()
  42. }
  43.  
  44. override suspend fun googleSignIn(googleSignInClient: GoogleSignInClient) = GlobalScope.launch(uiDispatcher) {
  45. val signInIntent = googleSignInClient.signInIntent
  46. startActivityForResult(signInIntent, RC_SIGN_IN)
  47. }
  48.  
  49. companion object {
  50. private const val RC_SIGN_IN = 123
  51. }
  52. }
Add Comment
Please, Sign In to add comment