@@ -6,6 +6,7 @@ import android.util.Log
66import android.view.View
77import android.widget.Button // Changed from SignInButton
88import android.widget.ProgressBar
9+ import android.widget.TextView
910import android.widget.Toast
1011import androidx.activity.result.ActivityResultLauncher
1112import androidx.activity.result.IntentSenderRequest
@@ -32,6 +33,7 @@ class LoginActivity : AppCompatActivity() {
3233 private lateinit var firebaseAuth: FirebaseAuth
3334 private lateinit var signInButton: Button // Changed from SignInButton
3435 private lateinit var progressBar: ProgressBar
36+ private lateinit var loadingText: TextView
3537
3638 // New ActivityResultLauncher for the modern Identity API
3739 private lateinit var googleSignInLauncher: ActivityResultLauncher <IntentSenderRequest >
@@ -42,6 +44,7 @@ class LoginActivity : AppCompatActivity() {
4244
4345 signInButton = findViewById(R .id.googleSignInButton)
4446 progressBar = findViewById(R .id.progressBar)
47+ loadingText = findViewById(R .id.loadingText)
4548 firebaseAuth = Firebase .auth
4649
4750 // 1. Initialize the OneTapClient
@@ -70,19 +73,25 @@ class LoginActivity : AppCompatActivity() {
7073 val googleIdToken = credential.googleIdToken
7174 if (googleIdToken != null ) {
7275 Log .d(" LoginActivity" , " Got Google ID Token." )
73- // Pass the token to Firebase
76+ // Pass the token to Firebase - keep progress bar visible during Firebase auth
7477 firebaseAuthWithGoogle(googleIdToken)
7578 } else {
7679 Log .e(" LoginActivity" , " Google ID Token was null." )
7780 Toast .makeText(this , " Google Sign-In failed." , Toast .LENGTH_SHORT ).show()
81+ progressBar.visibility = View .GONE
82+ loadingText.visibility = View .GONE
7883 }
7984 } catch (e: ApiException ) {
8085 Log .w(" LoginActivity" , " Google sign in failed" , e)
8186 Toast .makeText(this , " Google Sign-In failed." , Toast .LENGTH_SHORT ).show()
87+ progressBar.visibility = View .GONE
88+ loadingText.visibility = View .GONE
8289 }
90+ } else {
91+ // User cancelled or there was an error - hide progress bar
92+ progressBar.visibility = View .GONE
93+ loadingText.visibility = View .GONE
8394 }
84- // Always hide the progress bar after the attempt
85- progressBar.visibility = View .GONE
8695 }
8796
8897
@@ -93,6 +102,7 @@ class LoginActivity : AppCompatActivity() {
93102
94103 private fun signIn () {
95104 progressBar.visibility = View .VISIBLE
105+ loadingText.visibility = View .VISIBLE
96106 // 4. Launch the sign-in flow
97107 oneTapClient.beginSignIn(signInRequest)
98108 .addOnSuccessListener(this ) { result ->
@@ -104,19 +114,25 @@ class LoginActivity : AppCompatActivity() {
104114 } catch (e: Exception ) {
105115 Log .e(" LoginActivity" , " Couldn't start One Tap UI: ${e.localizedMessage} " )
106116 progressBar.visibility = View .GONE
117+ loadingText.visibility = View .GONE
107118 }
108119 }
109120 .addOnFailureListener(this ) { e ->
110121 Log .e(" LoginActivity" , " Sign-in failed: ${e.localizedMessage} " )
111122 Toast .makeText(this , " Sign-in failed. Please try again." , Toast .LENGTH_SHORT ).show()
112123 progressBar.visibility = View .GONE
124+ loadingText.visibility = View .GONE
113125 }
114126 }
115127
116128 private fun firebaseAuthWithGoogle (idToken : String ) {
117129 val credential = GoogleAuthProvider .getCredential(idToken, null )
118130 firebaseAuth.signInWithCredential(credential)
119131 .addOnCompleteListener(this ) { task ->
132+ // Hide progress bar and loading text when Firebase authentication completes
133+ progressBar.visibility = View .GONE
134+ loadingText.visibility = View .GONE
135+
120136 if (task.isSuccessful) {
121137 val isNewUser = task.result?.additionalUserInfo?.isNewUser ? : false
122138
0 commit comments