Skip to content

Commit 3642a25

Browse files
Merge pull request #245 from Ayush0Chaudhary/copilot/fix-211-2
Fix login loader disappearing prematurely during Google authentication
2 parents 173b9be + 46588ea commit 3642a25

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

app/src/main/java/com/blurr/voice/LoginActivity.kt.kt

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import android.util.Log
66
import android.view.View
77
import android.widget.Button // Changed from SignInButton
88
import android.widget.ProgressBar
9+
import android.widget.TextView
910
import android.widget.Toast
1011
import androidx.activity.result.ActivityResultLauncher
1112
import 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

app/src/main/res/layout/activity_onboarding.xml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
android:layout_above="@id/googleSignInButton"
2626
android:layout_centerHorizontal="true"
2727
android:layout_marginBottom="16dp"
28-
android:text="Use the invited email to unlock most of the features"
28+
android:text="Your AI assistant for Android"
2929
android:textAlignment="center"
3030
android:textColor="@android:color/white"
3131
android:textSize="16sp" />
@@ -59,4 +59,16 @@
5959
android:layout_centerInParent="true"
6060
android:visibility="gone"/>
6161

62+
<TextView
63+
android:id="@+id/loadingText"
64+
android:layout_width="wrap_content"
65+
android:layout_height="wrap_content"
66+
android:layout_below="@id/progressBar"
67+
android:layout_centerHorizontal="true"
68+
android:layout_marginTop="16dp"
69+
android:text="Signing you in..."
70+
android:textColor="@android:color/white"
71+
android:textSize="14sp"
72+
android:visibility="gone" />
73+
6274
</RelativeLayout>

0 commit comments

Comments
 (0)