Skip to content

Commit 1e80f61

Browse files
committed
ignore
1 parent ee3fef6 commit 1e80f61

5 files changed

Lines changed: 12 additions & 10 deletions

File tree

app/src/github/java/in/hridayan/ashell/settings/data/repository/GoogleAuthRepositoryImpl.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import androidx.credentials.exceptions.NoCredentialException
1212
import com.google.android.libraries.identity.googleid.GetGoogleIdOption
1313
import com.google.android.libraries.identity.googleid.GoogleIdTokenCredential
1414
import dagger.hilt.android.qualifiers.ApplicationContext
15+
import `in`.hridayan.ashell.core.utils.findActivity
1516
import `in`.hridayan.ashell.settings.data.SettingsKeys
1617
import `in`.hridayan.ashell.settings.domain.exception.NoGoogleAccountException
1718
import `in`.hridayan.ashell.settings.domain.model.GoogleUserState
@@ -80,9 +81,10 @@ class GoogleAuthRepositoryImpl @Inject constructor(
8081
}
8182
}
8283

83-
override suspend fun signIn(): Result<String> = withContext(Dispatchers.IO) {
84+
override suspend fun signIn(context: Context): Result<String> = withContext(Dispatchers.IO) {
8485
try {
85-
val credentialManager = CredentialManager.create(context)
86+
val activity = context.findActivity()
87+
val credentialManager = CredentialManager.create(activity ?: context)
8688

8789
val googleIdOption = GetGoogleIdOption.Builder()
8890
.setFilterByAuthorizedAccounts(false)
@@ -94,7 +96,7 @@ class GoogleAuthRepositoryImpl @Inject constructor(
9496
.build()
9597

9698
val result: GetCredentialResponse =
97-
credentialManager.getCredential(context, request)
99+
credentialManager.getCredential(activity ?: context, request)
98100

99101
val credential = result.credential
100102

app/src/main/java/in/hridayan/ashell/settings/domain/repository/GoogleAuthRepository.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ interface GoogleAuthRepository {
1515
* Launch sign-in via Credential Manager (modern bottom sheet) and request Drive scope.
1616
* Returns Result.success(email) or Result.failure(exception).
1717
*/
18-
suspend fun signIn(): Result<String>
18+
suspend fun signIn(context: Context): Result<String>
1919

2020
/** Sign out and clear stored credential. */
2121
suspend fun signOut()

app/src/main/java/in/hridayan/ashell/settings/presentation/components/dialog/NoGoogleAccountDialog.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ fun NoGoogleAccountDialog(
5454
Text(
5555
text = stringResource(R.string.no_google_account_title),
5656
style = MaterialTheme.typography.titleLarge,
57-
color = MaterialTheme.colorScheme.primary,
5857
textAlign = TextAlign.Center,
5958
modifier = Modifier
6059
.fillMaxWidth()

app/src/main/java/in/hridayan/ashell/settings/presentation/page/backup/screens/BackupAndRestoreScreen.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ fun BackupAndRestoreScreen(
171171
}
172172

173173
is SettingsUiEvent.RequestGoogleSignIn -> {
174-
backupAndRestoreViewModel.signInWithGoogle()
174+
backupAndRestoreViewModel.signInWithGoogle(context)
175175
}
176176

177177
is SettingsUiEvent.Navigate -> navController.navigate(event.route)
@@ -265,7 +265,7 @@ fun BackupAndRestoreScreen(
265265
userPhotoUrl = googleUserState.photoUrl,
266266
isLoading = isSigningIn || cloudOperationMessage != null,
267267
onSignInClick = {
268-
backupAndRestoreViewModel.signInWithGoogle()
268+
backupAndRestoreViewModel.signInWithGoogle(context)
269269
},
270270
onSignOutClick = {
271271
dialogManager.show(DialogKey.Settings.ConfirmGoogleSignOut)

app/src/main/java/in/hridayan/ashell/settings/presentation/page/backup/viewmodel/BackupAndRestoreViewModel.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,12 @@ class BackupAndRestoreViewModel @Inject constructor(
207207
}
208208
}
209209

210-
fun signInWithGoogle() {
210+
fun signInWithGoogle(context: Context) {
211211
viewModelScope.launch {
212212
Log.d(TAG, "signInWithGoogle: starting...")
213213
_isSigningIn.value = true
214214

215-
val result = googleAuthRepository.signIn()
215+
val result = googleAuthRepository.signIn(context)
216216

217217
_isSigningIn.value = false
218218

@@ -242,9 +242,10 @@ class BackupAndRestoreViewModel @Inject constructor(
242242
}
243243
} else {
244244
viewModelScope.launch {
245+
val errorMessage = error.message ?: context.getString(R.string.unknown_error)
245246
_uiEvent.emit(
246247
SettingsUiEvent.ShowToast(
247-
context.getString(R.string.sign_in_failed)
248+
context.getString(R.string.sign_in_failed) + ": $errorMessage"
248249
)
249250
)
250251
}

0 commit comments

Comments
 (0)