From 8253d6587f52fe4b5ae6e61b8af6d030c6f14906 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Wed, 10 Jan 2024 13:02:24 +0100 Subject: [PATCH] Rebase master Signed-off-by: alperozturk --- .../files/downloader/FileDownloadWorker.kt | 20 +++++++++++-------- .../client/jobs/BackgroundJobManagerImpl.kt | 2 ++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadWorker.kt b/app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadWorker.kt index b4534cfa0a63..29a199d7a476 100644 --- a/app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadWorker.kt +++ b/app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadWorker.kt @@ -57,7 +57,7 @@ import java.util.Vector @Suppress("LongParameterList", "TooManyFunctions") class FileDownloadWorker( - viewThemeUtils: ViewThemeUtils, + private val viewThemeUtils: ViewThemeUtils, private val accountManager: UserAccountManager, private var localBroadcastManager: LocalBroadcastManager, private val context: Context, @@ -75,6 +75,7 @@ class FileDownloadWorker( } } + const val WORKER_ID = "WORKER_ID" const val FILES_SEPARATOR = "," const val FOLDER_REMOTE_PATH = "FOLDER_REMOTE_PATH" const val FILE_REMOTE_PATH = "FILE_REMOTE_PATH" @@ -106,7 +107,7 @@ class FileDownloadWorker( private var lastPercent = 0 private val intents = FileDownloadIntents(context) - private val notificationManager = DownloadNotificationManager(SecureRandom().nextInt(), context, viewThemeUtils) + private lateinit var notificationManager: DownloadNotificationManager private var downloadProgressListener = FileDownloadProgressListener() private var user: User? = null @@ -115,6 +116,7 @@ class FileDownloadWorker( private var currentUserFileStorageManager: FileDataStorageManager? = null private var fileDataStorageManager: FileDataStorageManager? = null + private var workerId: Int? = null private var folder: OCFile? = null private var isAnyOperationFailed = false @@ -123,15 +125,16 @@ class FileDownloadWorker( return try { val requestDownloads = getRequestDownloads() + notificationManager = + DownloadNotificationManager(workerId ?: SecureRandom().nextInt(), context, viewThemeUtils) addAccountUpdateListener() - setForegroundAsync( - ForegroundServiceHelper.createWorkerForegroundInfo( - notificationManager.getId(), - notificationManager.getNotification(), - ForegroundServiceType.DataSync - ) + val foregroundInfo = ForegroundServiceHelper.createWorkerForegroundInfo( + notificationManager.getId(), + notificationManager.getNotification(), + ForegroundServiceType.DataSync ) + setForegroundAsync(foregroundInfo) requestDownloads.forEach { downloadFile(it) @@ -199,6 +202,7 @@ class FileDownloadWorker( } private fun getRequestDownloads(): AbstractList { + workerId = inputData.keyValueMap[WORKER_ID] as Int isAnyOperationFailed = false setUser() setFolder() diff --git a/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManagerImpl.kt b/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManagerImpl.kt index 948dc62eac06..fe667776f107 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManagerImpl.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManagerImpl.kt @@ -519,6 +519,7 @@ internal class BackgroundJobManagerImpl( override fun startFolderDownloadJob(folder: OCFile, user: User, filesPath: List) { val data = workDataOf( + FileDownloadWorker.WORKER_ID to folder.fileId.toInt(), FileDownloadWorker.ACCOUNT_NAME to user.accountName, FileDownloadWorker.FOLDER_REMOTE_PATH to folder.remotePath, FileDownloadWorker.FILES_REMOTE_PATH to filesPath.joinToString(FileDownloadWorker.FILES_SEPARATOR), @@ -548,6 +549,7 @@ internal class BackgroundJobManagerImpl( val tag = startFileDownloadJobTag(user, file.fileId) val data = workDataOf( + FileDownloadWorker.WORKER_ID to file.fileId.toInt(), FileDownloadWorker.ACCOUNT_NAME to user.accountName, FileDownloadWorker.FILE_REMOTE_PATH to file.remotePath, FileDownloadWorker.BEHAVIOUR to behaviour,