Use fileId for notificationId

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-01-10 12:49:58 +01:00 committed by Alper Öztürk
parent a0482e496d
commit e1dc124a72
2 changed files with 15 additions and 9 deletions

View file

@ -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
@ -122,16 +124,17 @@ class FileDownloadWorker(
override fun doWork(): Result {
return try {
val requestDownloads = getRequestDownloads()
notificationManager =
DownloadNotificationManager(workerId ?: SecureRandom().nextInt(), context, viewThemeUtils)
addAccountUpdateListener()
setForegroundAsync(
ForegroundServiceHelper.createWorkerForegroundInfo(
val foregroundInfo = ForegroundServiceHelper.createWorkerForegroundInfo(
notificationManager.getId(),
notificationManager.getNotification(),
ForegroundServiceType.DataSync
)
)
setForegroundAsync(foregroundInfo)
requestDownloads.forEach {
downloadFile(it)
@ -199,6 +202,8 @@ class FileDownloadWorker(
}
private fun getRequestDownloads(): AbstractList<String> {
workerId = inputData.keyValueMap[WORKER_ID] as Int
isAnyOperationFailed = false
setUser()
setFolder()
@ -206,7 +211,6 @@ class FileDownloadWorker(
val downloadType = getDownloadType()
conflictUploadId = inputData.keyValueMap[CONFLICT_UPLOAD_ID] as Long?
val behaviour = inputData.keyValueMap[BEHAVIOUR] as String? ?: ""
val activityName = inputData.keyValueMap[ACTIVITY_NAME] as String? ?: ""
val packageName = inputData.keyValueMap[PACKAGE_NAME] as String? ?: ""

View file

@ -519,6 +519,7 @@ internal class BackgroundJobManagerImpl(
override fun startFolderDownloadJob(folder: OCFile, user: User, filesPath: List<String>) {
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,