Browse Source

Prepare all files to cancel

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 1 year ago
parent
commit
eb0735e122

+ 6 - 4
app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadHelper.kt

@@ -61,15 +61,17 @@ class FileDownloadHelper {
         }
 
         return FileDownloadWorker.isDownloading(user.accountName, file.fileId) ||
-            FileDownloadWorker.isDownloading(user.accountName, file.parentId)
+            FileDownloadWorker.isDownloading(user.accountName, file.parentId) ||
+            backgroundJobManager.isStartFileDownloadJobScheduled(user, file.fileId) ||
+            backgroundJobManager.isStartFileDownloadJobScheduled(user, file.parentId)
     }
 
     fun cancelPendingOrCurrentDownloads(user: User?, files: List<OCFile>?) {
         if (user == null || files == null) return
 
-        files.forEach {
-            FileDownloadWorker.cancelOperation(user.accountName, it.fileId)
-            backgroundJobManager.cancelFilesDownloadJob(user, it.fileId)
+        files.forEach { file ->
+            FileDownloadWorker.cancelOperation(user.accountName, file.fileId)
+            backgroundJobManager.cancelFilesDownloadJob(user, file.fileId)
         }
     }
 

+ 2 - 13
app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadWorker.kt

@@ -71,23 +71,12 @@ class FileDownloadWorker(
 
         fun cancelOperation(accountName: String, fileId: Long) {
             pendingDownloads.all.forEach {
-                it.value.payload?.cancelMatchingOperation(accountName, fileId)
+                it.value?.payload?.cancelMatchingOperation(accountName, fileId)
             }
         }
 
-        /*
-                Folder 1 -- id = 100
-                    file 1-- parentID 100
-                    folder 2-- parentID 100
-                        file 3-- parentID 100
-                        file 4 -- parentID 100
-                Folder 4 -- parentID 100
-                    file 6         -- parentID 100
-
-         */
-
         fun isDownloading(accountName: String, fileId: Long): Boolean {
-            return pendingDownloads.all.any { it.value.payload.isMatching(accountName, fileId) }
+            return pendingDownloads.all.any { it.value?.payload?.isMatching(accountName, fileId) == true }
         }
 
         const val WORKER_ID = "WORKER_ID"

+ 1 - 0
app/src/main/java/com/owncloud/android/operations/DownloadFileOperation.java

@@ -23,6 +23,7 @@ package com.owncloud.android.operations;
 
 import android.content.Context;
 import android.text.TextUtils;
+import android.util.Log;
 import android.webkit.MimeTypeMap;
 
 import com.nextcloud.client.account.User;