diff --git a/app/src/main/java/com/nextcloud/client/files/downloader/DownloadNotificationManager.kt b/app/src/main/java/com/nextcloud/client/files/downloader/DownloadNotificationManager.kt index 3977928ed7b3..c3ea0ef99710 100644 --- a/app/src/main/java/com/nextcloud/client/files/downloader/DownloadNotificationManager.kt +++ b/app/src/main/java/com/nextcloud/client/files/downloader/DownloadNotificationManager.kt @@ -52,7 +52,7 @@ class DownloadNotificationManager( init { notificationBuilder = NotificationUtils.newNotificationBuilder(context, viewThemeUtils).apply { - setContentTitle(context.resources.getString(R.string.app_name)) + setContentTitle(context.getString(R.string.downloader_download_in_progress_ticker)) setSmallIcon(R.drawable.notification_icon) setLargeIcon(BitmapFactory.decodeResource(context.resources, R.drawable.notification_icon)) diff --git a/app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadError.kt b/app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadError.kt new file mode 100644 index 000000000000..f46783b33c47 --- /dev/null +++ b/app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadError.kt @@ -0,0 +1,26 @@ +/* + * Nextcloud Android client application + * + * @author Alper Ozturk + * Copyright (C) 2023 Alper Ozturk + * Copyright (C) 2023 Nextcloud GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package com.nextcloud.client.files.downloader + +enum class FileDownloadError { + Failed, Cancelled +} diff --git a/app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadWorker.kt b/app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadWorker.kt index 818775643e90..9253f849331e 100644 --- a/app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadWorker.kt +++ b/app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadWorker.kt @@ -118,7 +118,7 @@ class FileDownloadWorker( private var fileDataStorageManager: FileDataStorageManager? = null private var workerId: Int? = null - private var isAnyOperationFailed = false + private var downloadError: FileDownloadError? = null @Suppress("TooGenericExceptionCaught") override fun doWork(): Result { @@ -140,7 +140,8 @@ class FileDownloadWorker( downloadFile(it) } - if (isAnyOperationFailed) { + downloadError?.let { + showDownloadErrorNotification(it) notificationManager.dismissNotification() } @@ -182,7 +183,6 @@ class FileDownloadWorker( workerId = inputData.keyValueMap[WORKER_ID] as Int Log_OC.e(TAG, "FilesDownloadWorker started for $workerId") - isAnyOperationFailed = false setUser() val files = getFiles() val downloadType = getDownloadType() @@ -339,7 +339,7 @@ class FileDownloadWorker( private fun cleanupDownloadProcess(result: RemoteOperationResult<*>?, fileName: String?) { result?.let { - showFailedDownloadNotifications(it, fileName) + checkDownloadError(it, fileName) } val removeResult = pendingDownloads.removePayload( @@ -362,26 +362,29 @@ class FileDownloadWorker( } } - private fun showFailedDownloadNotifications(result: RemoteOperationResult<*>, fileName: String?) { - if (result.isSuccess) { + private fun checkDownloadError(result: RemoteOperationResult<*>, fileName: String?) { + if (result.isSuccess || downloadError != null) { return } - isAnyOperationFailed = true - - val failMessage = if (result.isCancelled) { - context.getString( - R.string.downloader_file_download_cancelled, - fileName - ) + downloadError = if (result.isCancelled) { + FileDownloadError.Cancelled } else { - context.getString( - R.string.downloader_file_download_failed, - fileName - ) + FileDownloadError.Failed + } + } + + private fun showDownloadErrorNotification(downloadError: FileDownloadError) { + val text = when (downloadError) { + FileDownloadError.Cancelled -> { + context.getString(R.string.downloader_file_download_cancelled) + } + FileDownloadError.Failed -> { + context.getString(R.string.downloader_file_download_failed) + } } - notificationManager.showNewNotification(failMessage) + notificationManager.showNewNotification(text) } private fun notifyDownloadResult( diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e47fe3f86174..7f515a825cac 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -175,8 +175,8 @@ Download failed Could not download %1$s Not downloaded yet - %s file download cancelled - Error occurred while downloading %s file + Certain files were canceled during the download by user + Error occurred while downloading files Unexpected error occurred while downloading files Download failed, log in again Choose account