mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-15 23:12:48 +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
|
showPurgeDialog.value = false
|
||||||
scope.launch {
|
scope.launch {
|
||||||
val result = googleDriveSync.deleteSyncDataFromGoogleDrive()
|
val result = googleDriveSync.deleteSyncDataFromGoogleDrive()
|
||||||
if (result) {
|
when (result) {
|
||||||
context.toast(R.string.google_drive_sync_data_purged)
|
GoogleDriveSyncService.DeleteSyncDataStatus.NOT_INITIALIZED -> context.toast(R.string.google_drive_not_signed_in)
|
||||||
} else {
|
GoogleDriveSyncService.DeleteSyncDataStatus.NO_FILES -> context.toast(R.string.google_drive_sync_data_not_found)
|
||||||
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>(),
|
Injekt.get<SyncPreferences>(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
enum class DeleteSyncDataStatus {
|
||||||
|
NOT_INITIALIZED,
|
||||||
|
NO_FILES,
|
||||||
|
SUCCESS,
|
||||||
|
}
|
||||||
|
|
||||||
private val remoteFileName = "tachiyomi_sync_data.gz"
|
private val remoteFileName = "tachiyomi_sync_data.gz"
|
||||||
|
|
||||||
private val googleDriveService = GoogleDriveService(context)
|
private val googleDriveService = GoogleDriveService(context)
|
||||||
@ -124,12 +130,12 @@ class GoogleDriveSyncService(context: Context, json: Json, syncPreferences: Sync
|
|||||||
return fileList
|
return fileList
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun deleteSyncDataFromGoogleDrive(): Boolean {
|
suspend fun deleteSyncDataFromGoogleDrive(): DeleteSyncDataStatus {
|
||||||
val drive = googleDriveService.googleDriveService
|
val drive = googleDriveService.googleDriveService
|
||||||
|
|
||||||
if (drive == null) {
|
if (drive == null) {
|
||||||
logcat(LogPriority.ERROR) { "Google Drive service not initialized" }
|
logcat(LogPriority.ERROR) { "Google Drive service not initialized" }
|
||||||
return false
|
return DeleteSyncDataStatus.NOT_INITIALIZED
|
||||||
}
|
}
|
||||||
googleDriveService.refreshToken()
|
googleDriveService.refreshToken()
|
||||||
|
|
||||||
@ -139,12 +145,12 @@ class GoogleDriveSyncService(context: Context, json: Json, syncPreferences: Sync
|
|||||||
|
|
||||||
if (fileList.isNullOrEmpty()) {
|
if (fileList.isNullOrEmpty()) {
|
||||||
logcat(LogPriority.DEBUG) { "No sync data file found in Google Drive" }
|
logcat(LogPriority.DEBUG) { "No sync data file found in Google Drive" }
|
||||||
false
|
DeleteSyncDataStatus.NO_FILES
|
||||||
} else {
|
} else {
|
||||||
val fileId = fileList[0].id
|
val fileId = fileList[0].id
|
||||||
drive.files().delete(fileId).execute()
|
drive.files().delete(fileId).execute()
|
||||||
logcat(LogPriority.DEBUG) { "Deleted sync data file in Google Drive with file ID: $fileId" }
|
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