Browse Source

Extract setProgress common logic

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 1 năm trước cách đây
mục cha
commit
6269c23b60

+ 2 - 12
app/src/main/java/com/nextcloud/client/jobs/download/DownloadNotificationManager.kt

@@ -24,7 +24,7 @@ class DownloadNotificationManager(
     private val id: Int,
     private val context: Context,
     viewThemeUtils: ViewThemeUtils
-): WorkerNotificationManager(id, context, viewThemeUtils, R.string.downloader_download_in_progress_ticker) {
+) : WorkerNotificationManager(id, context, viewThemeUtils, R.string.downloader_download_in_progress_ticker) {
 
     @Suppress("MagicNumber")
     fun prepareForStart(operation: DownloadFileOperation, currentDownloadIndex: Int, totalDownloadSize: Int) {
@@ -53,17 +53,7 @@ class DownloadNotificationManager(
 
     @Suppress("MagicNumber")
     fun updateDownloadProgress(percent: Int, totalToTransfer: Long) {
-        val progressText = String.format(
-            context.getString(R.string.downloader_notification_manager_in_progress_text),
-            percent
-        )
-
-        notificationBuilder.run {
-            setProgress(100, percent, totalToTransfer < 0)
-            setContentTitle(currentOperationTitle)
-            setContentText(progressText)
-        }
-
+        setProgress(percent, R.string.downloader_notification_manager_in_progress_text, totalToTransfer < 0)
         showNotification()
     }
 

+ 13 - 0
app/src/main/java/com/nextcloud/client/jobs/notification/WorkerNotificationManager.kt

@@ -41,6 +41,19 @@ open class WorkerNotificationManager(
         notificationManager.notify(id, notificationBuilder.build())
     }
 
+    fun setProgress(percent: Int, progressTextId: Int ,indeterminate: Boolean) {
+        val progressText = String.format(
+            context.getString(progressTextId),
+            percent
+        )
+
+        notificationBuilder.run {
+            setProgress(100, percent, indeterminate)
+            setContentTitle(currentOperationTitle)
+            setContentText(progressText)
+        }
+    }
+
     fun dismissWorkerNotifications() {
         notificationManager.cancel(id)
     }

+ 3 - 13
app/src/main/java/com/nextcloud/client/jobs/upload/UploadNotificationManager.kt

@@ -66,19 +66,9 @@ class UploadNotificationManager(private val context: Context, viewThemeUtils: Vi
 
     @Suppress("MagicNumber")
     fun updateUploadProgress(percent: Int, currentOperation: UploadFileOperation?) {
-        val progressText = String.format(
-            context.getString(R.string.upload_notification_manager_upload_in_progress_text),
-            percent
-        )
-
-        notificationBuilder.run {
-            setProgress(100, percent, false)
-            setContentTitle(currentOperationTitle)
-            setContentText(progressText)
-
-            showNotification()
-            dismissOldErrorNotification(currentOperation)
-        }
+        setProgress(percent, R.string.upload_notification_manager_upload_in_progress_text, false)
+        showNotification()
+        dismissOldErrorNotification(currentOperation)
     }
 
     fun notifyForFailedResult(