Эх сурвалжийг харах

Fix cancel

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 1 жил өмнө
parent
commit
5a5b18bad0

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

@@ -66,12 +66,14 @@ class FileDownloadHelper {
 
     fun cancelPendingOrCurrentDownloads(user: User?, file: OCFile?) {
         if (user == null || file == null) return
+        FileDownloadWorker.cancelCurrentDownload(user, file)
         backgroundJobManager.cancelFilesDownloadJob(user, file)
     }
 
-    fun cancelAllDownloadsForAccount(accountName: String?, currentDownload: DownloadFileOperation) {
-        if (currentDownload.user.nameEquals(accountName)) {
+    fun cancelAllDownloadsForAccount(accountName: String?, currentDownload: DownloadFileOperation?) {
+        if (currentDownload?.user?.nameEquals(accountName) == true) {
             currentDownload.file?.let { file ->
+                FileDownloadWorker.cancelCurrentDownload(currentDownload.user, file)
                 backgroundJobManager.cancelFilesDownloadJob(currentDownload.user, file)
             }
 

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

@@ -86,8 +86,13 @@ class FileDownloadWorker(
         const val EXTRA_ACCOUNT_NAME = "EXTRA_ACCOUNT_NAME"
 
         fun isDownloading(user: User, file: OCFile): Boolean {
-            return currentDownload?.file?.fileId == file.fileId &&
-                currentDownload?.user?.accountName == user.accountName
+            return currentDownload?.isActive(user, file) ?: false
+        }
+
+        fun cancelCurrentDownload(user: User, file: OCFile) {
+            if (currentDownload?.isActive(user, file) == true) {
+                currentDownload?.cancel()
+            }
         }
 
         fun getDownloadAddedMessage(): String {

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

@@ -98,6 +98,15 @@ public class DownloadFileOperation extends RemoteOperation {
         this(user, file, null, null, null, context, DownloadType.DOWNLOAD);
     }
 
+    public boolean isActive(User user, OCFile file) {
+        if (user == null || file == null) {
+            return false;
+        }
+
+        return getFile().getFileId() == file.getFileId() &&
+            getUser().getAccountName().equals(user.getAccountName());
+    }
+
     public String getSavePath() {
         if (file.getStoragePath() != null) {
             File parentFile = new File(file.getStoragePath()).getParentFile();