Эх сурвалжийг харах

Better notifications

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 1 жил өмнө
parent
commit
95e9be6ce9

+ 1 - 1
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))
 

+ 26 - 0
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 <https://www.gnu.org/licenses/>.
+ */
+
+package com.nextcloud.client.files.downloader
+
+enum class FileDownloadError {
+    Failed, Cancelled
+}

+ 21 - 18
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(

+ 2 - 2
app/src/main/res/values/strings.xml

@@ -175,8 +175,8 @@
     <string name="downloader_download_failed_ticker">Download failed</string>
     <string name="downloader_download_failed_content">Could not download %1$s</string>
     <string name="downloader_not_downloaded_yet">Not downloaded yet</string>
-    <string name="downloader_file_download_cancelled">%s file download cancelled</string>
-    <string name="downloader_file_download_failed">Error occurred while downloading %s file</string>
+    <string name="downloader_file_download_cancelled">Certain files were canceled during the download by user</string>
+    <string name="downloader_file_download_failed">Error occurred while downloading files</string>
     <string name="downloader_unexpected_error">Unexpected error occurred while downloading files</string>
     <string name="downloader_download_failed_credentials_error">Download failed, log in again</string>
     <string name="common_choose_account">Choose account</string>