From 0a0405f913aa598abe7bd008e5686df01db7c5e5 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 2 Dec 2024 12:13:00 +0100 Subject: [PATCH] add isDownloading Signed-off-by: alperozturk --- .../nextcloud/client/jobs/sync/SyncWorker.kt | 26 +++++-------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/com/nextcloud/client/jobs/sync/SyncWorker.kt b/app/src/main/java/com/nextcloud/client/jobs/sync/SyncWorker.kt index d627570e0f..3bf7d9461e 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/sync/SyncWorker.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/sync/SyncWorker.kt @@ -12,7 +12,6 @@ import androidx.work.CoroutineWorker import androidx.work.WorkerParameters import com.nextcloud.client.account.User import com.owncloud.android.datamodel.FileDataStorageManager -import com.owncloud.android.datamodel.OCFile import com.owncloud.android.lib.common.OwnCloudClientManagerFactory import com.owncloud.android.lib.common.utils.Log_OC import com.owncloud.android.operations.DownloadFileOperation @@ -31,13 +30,11 @@ class SyncWorker( const val FILE_PATHS = "FILE_PATHS" - // FIXME it's not synchronous - fun isDownloading(fileId: Long): Boolean { - return downloadFileIds.contains(fileId) || currentDownloadFolderId == fileId - } + private var downloadingFilePaths = ArrayList() - private var currentDownloadFolderId: Long? = null - private var downloadFileIds = ArrayList() + fun isDownloading(path: String): Boolean { + return downloadingFilePaths.contains(path) + } } private val notificationManager = SyncWorkerNotificationManager(context) @@ -56,6 +53,9 @@ class SyncWorker( return@withContext Result.failure() } + // TODO + // downloadingFilePaths = filePaths + val fileDataStorageManager = FileDataStorageManager(user, context.contentResolver) val account = user.toOwnCloudAccount() @@ -76,8 +76,6 @@ class SyncWorker( delay(1000) val operation = DownloadFileOperation(user, file, context).execute(client) - setCurrentDownloadFileIds(fileDataStorageManager, file) - Log_OC.d(TAG, "Syncing file: " + file.decryptedRemotePath) if (!operation.isSuccess) { result = false @@ -87,8 +85,6 @@ class SyncWorker( // TODO add isDownloading // TODO add cancel only one file download - - downloadFileIds.clear() withContext(Dispatchers.Main) { notificationManager.showCompletionMessage(result) } @@ -102,12 +98,4 @@ class SyncWorker( } } } - - private fun setCurrentDownloadFileIds(fileDataStorageManager: FileDataStorageManager, file: OCFile) { - if (currentDownloadFolderId == null) { - currentDownloadFolderId = fileDataStorageManager.getTopParentId(file) - } - - downloadFileIds.add(file.fileId) - } }