Last active
July 16, 2018 12:22
-
-
Save WindSekirun/164dac4e8a027fe83174d8622fb8c65e to your computer and use it in GitHub Desktop.
This file contains 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
package com.github.windsekirun.rxsociallogin.googletest | |
import android.annotation.SuppressLint | |
import android.content.Intent | |
import android.os.Bundle | |
import android.support.v7.app.AppCompatActivity | |
import com.github.windsekirun.rxsociallogin.RxSocialLogin | |
import com.github.windsekirun.rxsociallogin.google.GoogleLogin | |
import io.reactivex.disposables.CompositeDisposable | |
import kotlinx.android.synthetic.main.activity_main.* | |
class MainActivity : AppCompatActivity() { | |
private lateinit var googleLogin: GoogleLogin | |
private val compositeDisposable = CompositeDisposable() | |
@SuppressLint("SetTextI18n") | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
// listener | |
btnLogin.setOnClickListener { | |
googleLogin.onLogin() | |
} | |
googleLogin = GoogleLogin(this) | |
// subscribe RxSocialLogin | |
val disposable = RxSocialLogin.google(googleLogin) | |
.subscribe({ | |
txtResult.text = "success! $it" | |
}, { | |
txtResult.text = "error" | |
}) | |
// store in CompositeDisposable to prevent memory leak | |
compositeDisposable.add(disposable) | |
} | |
override fun onDestroy() { | |
super.onDestroy() | |
compositeDisposable.clear() | |
} | |
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | |
super.onActivityResult(requestCode, resultCode, data) | |
googleLogin.onActivityResult(requestCode, resultCode, data) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment