diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsBackupAndSyncScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsBackupAndSyncScreen.kt index f092719a5..f4ad14532 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsBackupAndSyncScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsBackupAndSyncScreen.kt @@ -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) } } }, diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/sync/service/GoogleDriveSyncService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/sync/service/GoogleDriveSyncService.kt index bd800d457..8710f857f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/sync/service/GoogleDriveSyncService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/sync/service/GoogleDriveSyncService.kt @@ -46,6 +46,12 @@ class GoogleDriveSyncService(context: Context, json: Json, syncPreferences: Sync Injekt.get(), ) + 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 } } }