Skip to content

Instantly share code, notes, and snippets.

@WindSekirun
Last active July 16, 2018 12:22
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 WindSekirun/164dac4e8a027fe83174d8622fb8c65e to your computer and use it in GitHub Desktop.
Save WindSekirun/164dac4e8a027fe83174d8622fb8c65e to your computer and use it in GitHub Desktop.
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