Prepare all files to cancel

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-01-10 17:01:06 +01:00 committed by Alper Öztürk
parent 15dedf8116
commit eb0735e122
3 changed files with 9 additions and 17 deletions

View file

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

View file

@ -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"

View file

@ -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;