فهرست منبع

Simplify worker

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 1 سال پیش
والد
کامیت
01d620f051
1فایلهای تغییر یافته به همراه8 افزوده شده و 20 حذف شده
  1. 8 20
      app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadWorker.kt

+ 8 - 20
app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadWorker.kt

@@ -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())