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

Extract dismissNotification common logic

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

+ 1 - 5
app/src/main/java/com/nextcloud/client/jobs/download/DownloadNotificationManager.kt

@@ -10,8 +10,6 @@ package com.nextcloud.client.jobs.download
 import android.app.PendingIntent
 import android.content.Context
 import android.content.Intent
-import android.os.Handler
-import android.os.Looper
 import com.nextcloud.client.jobs.notification.WorkerNotificationManager
 import com.owncloud.android.R
 import com.owncloud.android.operations.DownloadFileOperation
@@ -59,9 +57,7 @@ class DownloadNotificationManager(
 
     @Suppress("MagicNumber")
     fun dismissNotification() {
-        Handler(Looper.getMainLooper()).postDelayed({
-            notificationManager.cancel(id)
-        }, 2000)
+        dismissNotification(2000)
     }
 
     fun showNewNotification(text: String) {

+ 6 - 2
app/src/main/java/com/nextcloud/client/jobs/notification/WorkerNotificationManager.kt

@@ -12,6 +12,8 @@ import android.app.NotificationManager
 import android.content.Context
 import android.graphics.BitmapFactory
 import android.os.Build
+import android.os.Handler
+import android.os.Looper
 import androidx.core.app.NotificationCompat
 import com.owncloud.android.R
 import com.owncloud.android.ui.notifications.NotificationUtils
@@ -54,8 +56,10 @@ open class WorkerNotificationManager(
         }
     }
 
-    fun dismissWorkerNotifications() {
-        notificationManager.cancel(id)
+    fun dismissNotification(delay: Long = 0) {
+        Handler(Looper.getMainLooper()).postDelayed({
+            notificationManager.cancel(id)
+        }, delay)
     }
 
     fun getId(): Int {

+ 2 - 2
app/src/main/java/com/nextcloud/client/jobs/upload/FileUploadWorker.kt

@@ -113,7 +113,7 @@ class FileUploadWorker(
 
         setIdleWorkerState()
         currentUploadFileOperation?.cancel(null)
-        notificationManager.dismissWorkerNotifications()
+        notificationManager.dismissNotification()
 
         super.onStopped()
     }
@@ -249,7 +249,7 @@ class FileUploadWorker(
         if (!isStopped || !result.isCancelled) {
             uploadsStorageManager.updateDatabaseUploadResult(result, uploadFileOperation)
             notifyUploadResult(uploadFileOperation, result)
-            notificationManager.dismissWorkerNotifications()
+            notificationManager.dismissNotification()
         }
     }