From 71706f79c282dc6fa4b600494c68feab4eec64f6 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 17 Oct 2023 12:44:33 +0200 Subject: [PATCH 1/3] Remove extra info from files export Signed-off-by: alperozturk --- .../nextcloud/client/jobs/FilesExportWork.kt | 27 +++++-------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/com/nextcloud/client/jobs/FilesExportWork.kt b/app/src/main/java/com/nextcloud/client/jobs/FilesExportWork.kt index 427b9f605d..74475924c2 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/FilesExportWork.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/FilesExportWork.kt @@ -31,6 +31,7 @@ import android.content.Intent import android.content.Intent.FLAG_ACTIVITY_NEW_TASK import android.graphics.BitmapFactory import androidx.core.app.NotificationCompat +import androidx.core.content.ContextCompat import androidx.work.Worker import androidx.work.WorkerParameters import com.nextcloud.client.account.User @@ -69,9 +70,7 @@ class FilesExportWork( val successfulExports = exportFiles(fileIDs) - // show notification showSuccessNotification(successfulExports) - return Result.success() } @@ -119,19 +118,12 @@ class FilesExportWork( } private fun showErrorNotification(successfulExports: Int) { - if (successfulExports == 0) { - showNotification( - appContext.resources.getQuantityString(R.plurals.export_failed, successfulExports, successfulExports) - ) + val message = if (successfulExports == 0) { + appContext.resources.getQuantityString(R.plurals.export_failed, successfulExports, successfulExports) } else { - showNotification( - appContext.resources.getQuantityString( - R.plurals.export_partially_failed, - successfulExports, - successfulExports - ) - ) + appContext.resources.getQuantityString(R.plurals.export_partially_failed, successfulExports, successfulExports) } + showNotification(message) } private fun showSuccessNotification(successfulExports: Int) { @@ -147,14 +139,9 @@ class FilesExportWork( private fun showNotification(message: String) { val notificationId = SecureRandom().nextInt() - val notificationBuilder = NotificationCompat.Builder( - appContext, - NotificationUtils.NOTIFICATION_CHANNEL_DOWNLOAD - ) + val notificationBuilder = NotificationCompat.Builder(appContext, NotificationUtils.NOTIFICATION_CHANNEL_DOWNLOAD) .setSmallIcon(R.drawable.notification_icon) - .setLargeIcon(BitmapFactory.decodeResource(appContext.resources, R.drawable.notification_icon)) - .setSubText(user.accountName) - .setContentText(message) + .setContentTitle(message) .setAutoCancel(true) viewThemeUtils.androidx.themeNotificationCompatBuilder(appContext, notificationBuilder) From 1ffbca4fb5e3cc647cc15e6c81cf42bc275e58b3 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 17 Oct 2023 12:44:33 +0200 Subject: [PATCH 2/3] Remove extra info from files export Signed-off-by: alperozturk --- .../nextcloud/client/jobs/FilesExportWork.kt | 27 +++++-------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/com/nextcloud/client/jobs/FilesExportWork.kt b/app/src/main/java/com/nextcloud/client/jobs/FilesExportWork.kt index 427b9f605d..74475924c2 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/FilesExportWork.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/FilesExportWork.kt @@ -31,6 +31,7 @@ import android.content.Intent import android.content.Intent.FLAG_ACTIVITY_NEW_TASK import android.graphics.BitmapFactory import androidx.core.app.NotificationCompat +import androidx.core.content.ContextCompat import androidx.work.Worker import androidx.work.WorkerParameters import com.nextcloud.client.account.User @@ -69,9 +70,7 @@ class FilesExportWork( val successfulExports = exportFiles(fileIDs) - // show notification showSuccessNotification(successfulExports) - return Result.success() } @@ -119,19 +118,12 @@ class FilesExportWork( } private fun showErrorNotification(successfulExports: Int) { - if (successfulExports == 0) { - showNotification( - appContext.resources.getQuantityString(R.plurals.export_failed, successfulExports, successfulExports) - ) + val message = if (successfulExports == 0) { + appContext.resources.getQuantityString(R.plurals.export_failed, successfulExports, successfulExports) } else { - showNotification( - appContext.resources.getQuantityString( - R.plurals.export_partially_failed, - successfulExports, - successfulExports - ) - ) + appContext.resources.getQuantityString(R.plurals.export_partially_failed, successfulExports, successfulExports) } + showNotification(message) } private fun showSuccessNotification(successfulExports: Int) { @@ -147,14 +139,9 @@ class FilesExportWork( private fun showNotification(message: String) { val notificationId = SecureRandom().nextInt() - val notificationBuilder = NotificationCompat.Builder( - appContext, - NotificationUtils.NOTIFICATION_CHANNEL_DOWNLOAD - ) + val notificationBuilder = NotificationCompat.Builder(appContext, NotificationUtils.NOTIFICATION_CHANNEL_DOWNLOAD) .setSmallIcon(R.drawable.notification_icon) - .setLargeIcon(BitmapFactory.decodeResource(appContext.resources, R.drawable.notification_icon)) - .setSubText(user.accountName) - .setContentText(message) + .setContentTitle(message) .setAutoCancel(true) viewThemeUtils.androidx.themeNotificationCompatBuilder(appContext, notificationBuilder) From f8309d0791f40025abab7f2d3afc37d4c79996ee Mon Sep 17 00:00:00 2001 From: alperozturk Date: Fri, 20 Oct 2023 13:40:02 +0200 Subject: [PATCH 3/3] Fix code analytics warnings Signed-off-by: alperozturk --- .../nextcloud/client/jobs/FilesExportWork.kt | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/nextcloud/client/jobs/FilesExportWork.kt b/app/src/main/java/com/nextcloud/client/jobs/FilesExportWork.kt index 74475924c2..d8a417513b 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/FilesExportWork.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/FilesExportWork.kt @@ -29,9 +29,7 @@ import android.content.ContentResolver import android.content.Context import android.content.Intent import android.content.Intent.FLAG_ACTIVITY_NEW_TASK -import android.graphics.BitmapFactory import androidx.core.app.NotificationCompat -import androidx.core.content.ContextCompat import androidx.work.Worker import androidx.work.WorkerParameters import com.nextcloud.client.account.User @@ -104,7 +102,13 @@ class FilesExportWork( @Throws(IllegalStateException::class) private fun exportFile(ocFile: OCFile) { - FileExportUtils().exportFile(ocFile.fileName, ocFile.mimeType, contentResolver, ocFile, null) + FileExportUtils().exportFile( + ocFile.fileName, + ocFile.mimeType, + contentResolver, + ocFile, + null + ) } private fun downloadFile(ocFile: OCFile) { @@ -121,7 +125,11 @@ class FilesExportWork( val message = if (successfulExports == 0) { appContext.resources.getQuantityString(R.plurals.export_failed, successfulExports, successfulExports) } else { - appContext.resources.getQuantityString(R.plurals.export_partially_failed, successfulExports, successfulExports) + appContext.resources.getQuantityString( + R.plurals.export_partially_failed, + successfulExports, + successfulExports + ) } showNotification(message) } @@ -139,7 +147,10 @@ class FilesExportWork( private fun showNotification(message: String) { val notificationId = SecureRandom().nextInt() - val notificationBuilder = NotificationCompat.Builder(appContext, NotificationUtils.NOTIFICATION_CHANNEL_DOWNLOAD) + val notificationBuilder = NotificationCompat.Builder( + appContext, + NotificationUtils.NOTIFICATION_CHANNEL_DOWNLOAD + ) .setSmallIcon(R.drawable.notification_icon) .setContentTitle(message) .setAutoCancel(true) @@ -153,7 +164,8 @@ class FilesExportWork( appContext, notificationId, actionIntent, - PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE + PendingIntent.FLAG_CANCEL_CURRENT or + PendingIntent.FLAG_IMMUTABLE ) notificationBuilder.addAction( NotificationCompat.Action( @@ -163,7 +175,8 @@ class FilesExportWork( ) ) - val notificationManager = appContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager + val notificationManager = appContext + .getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager notificationManager.notify(notificationId, notificationBuilder.build()) }