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 64e4c6319c0a..15c30c89429f 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 @@ -60,8 +60,12 @@ class FileDownloadHelper { return false } + val fileStorageManager = FileDataStorageManager(user, MainApp.getAppContext().contentResolver) + val topParentId = fileStorageManager.getTopParentId(file) + return if (file.isFolder) { - backgroundJobManager.isStartFileDownloadJobScheduled(user, file.fileId) + backgroundJobManager.isStartFileDownloadJobScheduled(user, file.fileId) || + backgroundJobManager.isStartFileDownloadJobScheduled(user, topParentId) } else { FileDownloadWorker.isDownloading(user.accountName, file.fileId) } diff --git a/app/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java b/app/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java index bd57e9a9ffef..3d30d8aff20f 100644 --- a/app/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/app/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -180,6 +180,27 @@ public boolean fileExists(String path) { return fileDao.getFileByEncryptedRemotePath(path, user.getAccountName()) != null; } + public long getTopParentId(OCFile file) { + if (file.getParentId() == 1) { + return file.getFileId(); + } + + return getTopParentIdRecursive(file); + } + + private long getTopParentIdRecursive(OCFile file) { + if (file.getParentId() == 1) { + return file.getFileId(); + } + + OCFile parentFile = getFileById(file.getParentId()); + if (parentFile != null) { + return getTopParentId(parentFile); + } + + return file.getFileId(); + } + public List getAllFilesRecursivelyInsideFolder(OCFile file) { ArrayList result = new ArrayList<>();