mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-15 15:02:49 +01:00
refactor: Improve toast error messages for Google Drive sync data purge
Previously, the UI displayed a "No files found" message even when the user was not signed into Google Drive. This commit refines the error messaging to specify "Not signed in to Google Drive" when appropriate. Signed-off-by: KaiserBh <kaiserbh@proton.me>
This commit is contained in:
parent
30af850211
commit
a84a396484
@ -489,10 +489,10 @@ object SettingsBackupAndSyncScreen : SearchableSettings {
|
||||
showPurgeDialog.value = false
|
||||
scope.launch {
|
||||
val result = googleDriveSync.deleteSyncDataFromGoogleDrive()
|
||||
if (result) {
|
||||
context.toast(R.string.google_drive_sync_data_purged)
|
||||
} else {
|
||||
context.toast(R.string.google_drive_sync_data_not_found)
|
||||
when (result) {
|
||||
GoogleDriveSyncService.DeleteSyncDataStatus.NOT_INITIALIZED -> context.toast(R.string.google_drive_not_signed_in)
|
||||
GoogleDriveSyncService.DeleteSyncDataStatus.NO_FILES -> context.toast(R.string.google_drive_sync_data_not_found)
|
||||
GoogleDriveSyncService.DeleteSyncDataStatus.SUCCESS -> context.toast(R.string.google_drive_sync_data_purged)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -46,6 +46,12 @@ class GoogleDriveSyncService(context: Context, json: Json, syncPreferences: Sync
|
||||
Injekt.get<SyncPreferences>(),
|
||||
)
|
||||
|
||||
enum class DeleteSyncDataStatus {
|
||||
NOT_INITIALIZED,
|
||||
NO_FILES,
|
||||
SUCCESS,
|
||||
}
|
||||
|
||||
private val remoteFileName = "tachiyomi_sync_data.gz"
|
||||
|
||||
private val googleDriveService = GoogleDriveService(context)
|
||||
@ -124,12 +130,12 @@ class GoogleDriveSyncService(context: Context, json: Json, syncPreferences: Sync
|
||||
return fileList
|
||||
}
|
||||
|
||||
suspend fun deleteSyncDataFromGoogleDrive(): Boolean {
|
||||
suspend fun deleteSyncDataFromGoogleDrive(): DeleteSyncDataStatus {
|
||||
val drive = googleDriveService.googleDriveService
|
||||
|
||||
if (drive == null) {
|
||||
logcat(LogPriority.ERROR) { "Google Drive service not initialized" }
|
||||
return false
|
||||
return DeleteSyncDataStatus.NOT_INITIALIZED
|
||||
}
|
||||
googleDriveService.refreshToken()
|
||||
|
||||
@ -139,12 +145,12 @@ class GoogleDriveSyncService(context: Context, json: Json, syncPreferences: Sync
|
||||
|
||||
if (fileList.isNullOrEmpty()) {
|
||||
logcat(LogPriority.DEBUG) { "No sync data file found in Google Drive" }
|
||||
false
|
||||
DeleteSyncDataStatus.NO_FILES
|
||||
} else {
|
||||
val fileId = fileList[0].id
|
||||
drive.files().delete(fileId).execute()
|
||||
logcat(LogPriority.DEBUG) { "Deleted sync data file in Google Drive with file ID: $fileId" }
|
||||
true
|
||||
DeleteSyncDataStatus.SUCCESS
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user