diff --git a/app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadHelper.kt b/app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadHelper.kt index e2bef7428c..87b837c07c 100644 --- a/app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadHelper.kt +++ b/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?) { 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) } } 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 f4bbaaae4a..270100237b 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 @@ -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" diff --git a/app/src/main/java/com/owncloud/android/operations/DownloadFileOperation.java b/app/src/main/java/com/owncloud/android/operations/DownloadFileOperation.java index df1a62b2ab..517aeaca19 100644 --- a/app/src/main/java/com/owncloud/android/operations/DownloadFileOperation.java +++ b/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;