diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDataScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDataScreen.kt index dc9ce50252..32a8bf5fec 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDataScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDataScreen.kt @@ -400,12 +400,19 @@ object SettingsDataScreen : SearchableSettings { when (result) { GoogleDriveSyncService.DeleteSyncDataStatus.NOT_INITIALIZED -> context.toast( MR.strings.google_drive_not_signed_in, + duration = 5000, ) GoogleDriveSyncService.DeleteSyncDataStatus.NO_FILES -> context.toast( MR.strings.google_drive_sync_data_not_found, + duration = 5000, ) GoogleDriveSyncService.DeleteSyncDataStatus.SUCCESS -> context.toast( MR.strings.google_drive_sync_data_purged, + duration = 5000, + ) + GoogleDriveSyncService.DeleteSyncDataStatus.ERROR -> context.toast( + MR.strings.google_drive_sync_data_purge_error, + duration = 10000, ) } } 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 b532d89f82..63b819edf6 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 @@ -56,18 +56,22 @@ class GoogleDriveSyncService(context: Context, json: Json, syncPreferences: Sync NOT_INITIALIZED, NO_FILES, SUCCESS, + ERROR, } - private val remoteFileName = "tachiyomi_sync_data.gz" + private val appName = context.stringResource(MR.strings.app_name) - private val lockFileName = "tachiyomi_sync.lock" + private val remoteFileName = "${appName}_sync_data.gz" + + private val lockFileName = "${appName}_sync.lock" private val googleDriveService = GoogleDriveService(context) override suspend fun beforeSync() { try { googleDriveService.refreshToken() - val drive = googleDriveService.driveService ?: throw Exception("Google Drive service not initialized") + val drive = googleDriveService.driveService + ?: throw Exception(context.stringResource(MR.strings.google_drive_not_signed_in)) var backoff = 1000L @@ -105,6 +109,7 @@ class GoogleDriveSyncService(context: Context, json: Json, syncPreferences: Sync } } catch (e: Exception) { logcat(LogPriority.ERROR) { "Error in GoogleDrive beforeSync: ${e.message}" } + throw Exception(context.stringResource(MR.strings.error_before_sync_gdrive) + ": ${e.message}") } } @@ -234,6 +239,7 @@ class GoogleDriveSyncService(context: Context, json: Json, syncPreferences: Sync Log.d("GoogleDrive", "Created lock file with ID: ${file.id}") } catch (e: Exception) { Log.e("GoogleDrive", "Error creating lock file: ${e.message}") + throw Exception(e.message) } } @@ -282,19 +288,24 @@ class GoogleDriveSyncService(context: Context, json: Json, syncPreferences: Sync googleDriveService.refreshToken() return withContext(Dispatchers.IO) { - val appDataFileList = getAppDataFileList(drive) - - if (appDataFileList.isEmpty()) { - logcat(LogPriority.DEBUG) { "No sync data file found in appData folder of Google Drive" } - DeleteSyncDataStatus.NO_FILES - } else { - for (file in appDataFileList) { - drive.files().delete(file.id).execute() - logcat( - LogPriority.DEBUG, - ) { "Deleted sync data file in appData folder of Google Drive with file ID: ${file.id}" } + try { + val appDataFileList = getAppDataFileList(drive) + + if (appDataFileList.isEmpty()) { + logcat(LogPriority.DEBUG) { "No sync data file found in appData folder of Google Drive" } + DeleteSyncDataStatus.NO_FILES + } else { + for (file in appDataFileList) { + drive.files().delete(file.id).execute() + logcat( + LogPriority.DEBUG, + ) { "Deleted sync data file in appData folder of Google Drive with file ID: ${file.id}" } + } + DeleteSyncDataStatus.SUCCESS } - DeleteSyncDataStatus.SUCCESS + } catch (e: Exception) { + logcat(LogPriority.ERROR) { "Error occurred while interacting with Google Drive: ${e.message}" } + DeleteSyncDataStatus.ERROR } } } @@ -441,7 +452,7 @@ class GoogleDriveService(private val context: Context) { NetHttpTransport(), jsonFactory, credential, - ).setApplicationName("Tachiyomi") + ).setApplicationName(context.stringResource(MR.strings.app_name)) .build() } diff --git a/i18n/src/commonMain/resources/MR/base/strings.xml b/i18n/src/commonMain/resources/MR/base/strings.xml index b96002f3df..7af35e7585 100644 --- a/i18n/src/commonMain/resources/MR/base/strings.xml +++ b/i18n/src/commonMain/resources/MR/base/strings.xml @@ -577,11 +577,13 @@ Clear Sync Data from Google Drive Sync data purged from Google Drive No sync data found in Google Drive + Error purging sync data from Google Drive, Try to sign in again. Logged in to Google Drive Failed to log in to Google Drive: %s Not signed in to Google Drive Error uploading sync data to Google Drive Error Deleting Google Drive Lock File + Error before sync: %s Purge confirmation Purging sync data will delete all your sync data from Google Drive. Are you sure you want to continue? Create sync triggers