mirror of
https://github.com/nextcloud/android.git
synced 2024-11-27 09:39:25 +03:00
Simplify worker
Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
parent
1c18a3d840
commit
01d620f051
1 changed files with 8 additions and 20 deletions
|
@ -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())
|
||||
|
|
Loading…
Reference in a new issue