Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package XXX
- import android.content.Intent
- import android.os.Bundle
- import au.sjowl.base.basex.BaseActivity
- import com.google.android.gms.auth.api.signin.GoogleSignIn
- import com.google.android.gms.auth.api.signin.GoogleSignInClient
- import io.michaelrocks.lightsaber.getInstance
- import kotlinx.android.synthetic.main.activity_auth.*
- import kotlinx.coroutines.GlobalScope
- import kotlinx.coroutines.launch
- open class AuthActivity :
- BaseActivity<AuthPresenter, AuthView>(),
- AuthView {
- override val layoutId: Int get() = R.layout.activity_auth
- override fun providePresenter(): AuthPresenter = appInjector.getInstance()
- /* ******************** google sign in *********************/
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- signInButton.setOnClickListener { presenter.onGoogleSignIn() }
- }
- public override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
- super.onActivityResult(requestCode, resultCode, data)
- when (requestCode) {
- RC_SIGN_IN -> {
- val task = GoogleSignIn.getSignedInAccountFromIntent(data)
- presenter.onSignedIn(task)
- }
- }
- }
- /* ******************** View *********************/
- override suspend fun closeView() = GlobalScope.launch(uiDispatcher) {
- finish()
- }
- override suspend fun googleSignIn(googleSignInClient: GoogleSignInClient) = GlobalScope.launch(uiDispatcher) {
- val signInIntent = googleSignInClient.signInIntent
- startActivityForResult(signInIntent, RC_SIGN_IN)
- }
- companion object {
- private const val RC_SIGN_IN = 123
- }
- }
Add Comment
Please, Sign In to add comment