daily pastebin goal
19%
SHARE
TWEET

Untitled

a guest Mar 19th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import android.app.ProgressDialog
  2. import android.databinding.DataBindingUtil
  3. import android.os.Bundle
  4. import android.support.v7.app.AppCompatActivity
  5. import android.text.TextUtils
  6. import android.view.View
  7. import android.widget.Toast
  8. import com.google.firebase.auth.FirebaseAuth
  9. import com.nezspencer.testapp.databinding.ActivitySubBinding
  10.  
  11. class SubActivity : AppCompatActivity(), FirebaseAuth.AuthStateListener, View.OnClickListener{
  12.  
  13.     private lateinit var mAuth : FirebaseAuth
  14.     private lateinit var progress : ProgressDialog
  15.     private lateinit var binding : ActivitySubBinding
  16.     override fun onCreate(savedInstanceState: Bundle?) {
  17.         super.onCreate(savedInstanceState)
  18.         binding = DataBindingUtil.setContentView(this, R.layout.activity_sub)
  19.         progress = ProgressDialog(this)
  20.         progress.setCanceledOnTouchOutside(false)
  21.         progress.setCancelable(false)
  22.  
  23.         binding.btnSignin.setOnClickListener(this)
  24.         binding.btnSignup.setOnClickListener(this)
  25.         mAuth = FirebaseAuth.getInstance()
  26.  
  27.     }
  28.  
  29.     override fun onStart() {
  30.         super.onStart()
  31.         mAuth.addAuthStateListener(this)
  32.     }
  33.  
  34.     override fun onStop() {
  35.         super.onStop()
  36.         mAuth.removeAuthStateListener(this)
  37.     }
  38.  
  39.     override fun onAuthStateChanged(p0: FirebaseAuth) {
  40.         if (progress.isShowing)
  41.             progress.hide()
  42.  
  43.         if (p0.currentUser != null) {
  44.             //do some UI magic
  45.             Toast.makeText(this, "Auth successful", Toast.LENGTH_SHORT).show()
  46.         }
  47.         else {
  48.             // also do some UI unauthenticated magic
  49.             Toast.makeText(this, "Auth failed", Toast.LENGTH_SHORT).show()
  50.         }
  51.     }
  52.  
  53.     override fun onClick(p0: View?) {
  54.         when(p0!!.id){
  55.             R.id.btn_signup -> {
  56.                 val email = binding.etEmail.text.toString()
  57.                 val password = binding.etPwd.text.toString()
  58.                 if (!TextUtils.isEmpty(email) && !TextUtils.isEmpty(password))
  59.                     signupUser(email, password)
  60.             }
  61.             R.id.btn_signin ->{
  62.                 val email = binding.etEmail.text.toString()
  63.                 val password = binding.etPwd.text.toString()
  64.                 if (!TextUtils.isEmpty(email) && !TextUtils.isEmpty(password))
  65.                     signInUser(email, password)
  66.             }
  67.         }
  68.     }
  69.  
  70.     private fun signupUser(email : String, password : String){
  71.         if (!progress.isShowing)
  72.             progress.show()
  73.         mAuth.createUserWithEmailAndPassword(email, password)
  74.     }
  75.  
  76.  
  77.  
  78.     private fun signInUser(email : String, password: String) {
  79.         if (!progress.isShowing)
  80.             progress.show()
  81.         mAuth.signInWithEmailAndPassword(email, password)
  82.     }
  83. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top