Skip to content

Commit

Permalink
Rebase master
Browse files Browse the repository at this point in the history
Signed-off-by: alperozturk <[email protected]>
  • Loading branch information
alperozturk96 committed Jan 10, 2024
1 parent 8f69194 commit 8253d65
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -199,6 +202,7 @@ class FileDownloadWorker(
}

private fun getRequestDownloads(): AbstractList<String> {
workerId = inputData.keyValueMap[WORKER_ID] as Int
isAnyOperationFailed = false
setUser()
setFolder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 8253d65

Please sign in to comment.