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 6c82b36a5b..7a19cc5b88 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 @@ -96,7 +96,6 @@ class FileDownloadWorker( private val pendingDownloads = IndexedForest() private var downloadProgressListener = FileDownloadProgressListener() private var currentUser = Optional.empty() - 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 { 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) { - val it: Iterator = 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())