瀏覽代碼

Add missing random notification

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 1 年之前
父節點
當前提交
df7f32cd1e

+ 7 - 7
app/src/main/java/com/nextcloud/client/files/uploader/UploadNotificationManager.kt

@@ -44,16 +44,16 @@ class UploadNotificationManager(private val context: Context, private val viewTh
         private const val WORKER_ID = 411
     }
 
-    private val secureRandomGenerator = SecureRandom()
     private var notification: Notification? = null
+    private val secureRandomGenerator = SecureRandom()
     private lateinit var notificationBuilder: NotificationCompat.Builder
     private val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
 
     init {
-        init()
+        initNotificationBuilder()
     }
 
-    fun init() {
+    private fun initNotificationBuilder() {
         notificationBuilder = NotificationUtils.newNotificationBuilder(context, viewThemeUtils)
             .setContentTitle(context.resources.getString(R.string.app_name))
             .setContentText(context.resources.getString(R.string.foreground_service_upload))
@@ -134,10 +134,6 @@ class UploadNotificationManager(private val context: Context, private val viewTh
         notificationBuilder.setContentText(text)
     }
 
-    fun showRandomNotification() {
-        notificationManager.notify(secureRandomGenerator.nextInt(), notificationBuilder.build())
-    }
-
     fun addAction(icon: Int, textId: Int, intent: PendingIntent) {
         notificationBuilder.addAction(
             icon,
@@ -154,6 +150,10 @@ class UploadNotificationManager(private val context: Context, private val viewTh
         )
     }
 
+    fun showRandomNotification() {
+        notificationManager.notify(secureRandomGenerator.nextInt(), notificationBuilder.build())
+    }
+
     private fun showWorkerNotification() {
         notificationManager.notify(WORKER_ID, notificationBuilder.build())
     }

+ 5 - 0
app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt

@@ -246,6 +246,11 @@ class FilesUploadWorker(
             }
 
             notificationManager.setContentText(content)
+
+            if (!uploadResult.isSuccess) {
+                notificationManager.showRandomNotification()
+            }
+
             notificationManager.showNotificationTag(uploadFileOperation)
         }
     }