Simplify worker

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-01-03 10:00:36 +01:00 committed by Alper Öztürk
parent 1c18a3d840
commit 01d620f051

View file

@ -96,7 +96,6 @@ class FileDownloadWorker(
private val pendingDownloads = IndexedForest<DownloadFileOperation>()
private var downloadProgressListener = FileDownloadProgressListener()
private var currentUser = Optional.empty<User>()
private var startedDownload = false
private var storageManager: FileDataStorageManager? = null
private var downloadClient: OwnCloudClient? = null
private var user: User? = null
@ -109,7 +108,12 @@ class FileDownloadWorker(
notificationManager.init()
addAccountUpdateListener()
startDownloadForEachRequest(requestDownloads)
requestDownloads.forEach {
downloadFile(it)
}
setIdleWorkerState()
Log_OC.e(TAG, "FilesDownloadWorker successfully completed")
Result.success()
@ -119,11 +123,6 @@ class FileDownloadWorker(
}
}
override fun onStopped() {
super.onStopped()
setIdleWorkerState()
}
private fun getRequestDownloads(): AbstractList<String> {
conflictUploadId = inputData.keyValueMap[CONFLICT_UPLOAD_ID] as Long?
val file = gson.fromJson(inputData.keyValueMap[FILE] as String, OCFile::class.java)
@ -190,26 +189,15 @@ class FileDownloadWorker(
am.addOnAccountsUpdatedListener(this, null, false)
}
private fun startDownloadForEachRequest(requestDownloads: AbstractList<String>) {
val it: Iterator<String> = requestDownloads.iterator()
while (it.hasNext()) {
val next = it.next()
Log_OC.e(TAG, "Download Key: $next")
downloadFile(next)
}
startedDownload = false
}
@Suppress("TooGenericExceptionCaught")
private fun downloadFile(downloadKey: String) {
startedDownload = true
currentDownload = pendingDownloads.get(downloadKey)
if (currentDownload == null) {
return
}
Log_OC.e(TAG, "FilesDownloadWorker downloading: $downloadKey")
setWorkerState(user, currentDownload)
val isAccountExist = accountManager.exists(currentDownload?.user?.toPlatformAccount())