From 61bbe47fdfe47f0f3c371289ec1cae49aa2f682f Mon Sep 17 00:00:00 2001 From: alperozturk Date: Thu, 12 Dec 2024 15:45:51 +0100 Subject: [PATCH] fix code analytics Signed-off-by: alperozturk --- .../nextcloud/client/jobs/sync/SyncWorker.kt | 2 +- .../sync/SyncWorkerNotificationManager.kt | 31 ++++++++++--------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/nextcloud/client/jobs/sync/SyncWorker.kt b/app/src/main/java/com/nextcloud/client/jobs/sync/SyncWorker.kt index 777fa5e9e6..b9485e3aee 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/sync/SyncWorker.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/sync/SyncWorker.kt @@ -49,7 +49,7 @@ class SyncWorker( private val notificationManager = SyncWorkerNotificationManager(context) - @Suppress("DEPRECATION") + @Suppress("DEPRECATION", "MagicNumber") override suspend fun doWork(): Result { withContext(Dispatchers.Main) { notificationManager.showStartNotification() diff --git a/app/src/main/java/com/nextcloud/client/jobs/sync/SyncWorkerNotificationManager.kt b/app/src/main/java/com/nextcloud/client/jobs/sync/SyncWorkerNotificationManager.kt index ff906582e2..51d4d282c4 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/sync/SyncWorkerNotificationManager.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/sync/SyncWorkerNotificationManager.kt @@ -21,9 +21,13 @@ import kotlinx.coroutines.delay class SyncWorkerNotificationManager(private val context: Context) { private val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager + + @Suppress("MagicNumber") private val notificationId = 129 + private val channelId = NotificationUtils.NOTIFICATION_CHANNEL_DOWNLOAD + @Suppress("MagicNumber") private fun getNotification(title: String, description: String? = null, progress: Int? = null): Notification { return NotificationCompat.Builder(context, channelId).apply { setSmallIcon(android.R.drawable.stat_sys_download_done) @@ -70,6 +74,7 @@ class SyncWorkerNotificationManager(private val context: Context) { notificationManager.notify(notificationId, notification) } + @Suppress("MagicNumber") fun showProgressNotification(filename: String, currentIndex: Int, totalFileSize: Int) { val currentFileIndex = (currentIndex + 1) val title = "$currentFileIndex / $totalFileSize - $filename" @@ -78,30 +83,28 @@ class SyncWorkerNotificationManager(private val context: Context) { notificationManager.notify(notificationId, notification) } + @Suppress("MagicNumber") suspend fun showCompletionMessage(success: Boolean) { if (success) { - showSuccessNotification() + showNotification( + R.string.sync_worker_success_notification_title, + R.string.sync_worker_success_notification_description + ) } else { - showErrorNotification() + showNotification( + R.string.sync_worker_error_notification_title, + R.string.sync_worker_error_notification_description + ) } delay(1000) dismiss() } - private fun showSuccessNotification() { + private fun showNotification(titleId: Int, descriptionId: Int) { val notification = getNotification( - context.getString(R.string.sync_worker_success_notification_title), - context.getString(R.string.sync_worker_success_notification_description) - ) - - notificationManager.notify(notificationId, notification) - } - - private fun showErrorNotification() { - val notification = getNotification( - context.getString(R.string.sync_worker_error_notification_title), - context.getString(R.string.sync_worker_error_notification_description) + context.getString(titleId), + context.getString(descriptionId) ) notificationManager.notify(notificationId, notification)