From f1cbb590eb6536db23208cb6f800cedca8a9c4a4 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Thu, 12 Dec 2024 16:00:03 +0100 Subject: [PATCH] fix code analytics Signed-off-by: alperozturk --- .../client/jobs/BackgroundJobManager.kt | 2 +- .../client/jobs/BackgroundJobManagerImpl.kt | 3 +-- .../client/jobs/download/FileDownloadHelper.kt | 4 ++-- .../com/nextcloud/client/jobs/sync/SyncWorker.kt | 16 +++++++++++----- .../operations/SynchronizeFolderOperation.java | 7 ++----- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManager.kt b/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManager.kt index d65b20ff62..6c967e1441 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManager.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManager.kt @@ -172,5 +172,5 @@ interface BackgroundJobManager { fun startPeriodicallyOfflineOperation() fun scheduleInternal2WaySync(intervalMinutes: Long) fun cancelAllFilesDownloadJobs() - fun syncFolder(filePaths: List, topParentPath: String) + fun syncFolder(filePaths: List) } diff --git a/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManagerImpl.kt b/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManagerImpl.kt index d4f79c4847..be7d333b61 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManagerImpl.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManagerImpl.kt @@ -715,10 +715,9 @@ internal class BackgroundJobManagerImpl( workManager.enqueueUniquePeriodicWork(JOB_INTERNAL_TWO_WAY_SYNC, ExistingPeriodicWorkPolicy.UPDATE, request) } - override fun syncFolder(filePaths: List, topParentPath: String) { + override fun syncFolder(filePaths: List) { val data = Data.Builder() .putStringArray(SyncWorker.FILE_PATHS, filePaths.toTypedArray()) - .putString(SyncWorker.TOP_PARENT_PATH, topParentPath) .build() val request = oneTimeRequestBuilder(SyncWorker::class, JOB_SYNC_FOLDER) diff --git a/app/src/main/java/com/nextcloud/client/jobs/download/FileDownloadHelper.kt b/app/src/main/java/com/nextcloud/client/jobs/download/FileDownloadHelper.kt index 3e231124ae..347d9bc152 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/download/FileDownloadHelper.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/download/FileDownloadHelper.kt @@ -138,7 +138,7 @@ class FileDownloadHelper { ) } - fun syncFolder(filePaths: List, topParentPath: String) { - backgroundJobManager.syncFolder(filePaths, topParentPath) + fun syncFolder(filePaths: List) { + backgroundJobManager.syncFolder(filePaths) } } 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 b9485e3aee..215421ef16 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 @@ -31,7 +31,6 @@ class SyncWorker( private const val TAG = "SyncWorker" const val FILE_PATHS = "FILE_PATHS" - const val TOP_PARENT_PATH = "TOP_PARENT_PATH" const val SYNC_WORKER_COMPLETION_BROADCAST = "SYNC_WORKER_COMPLETION_BROADCAST" const val FILE_DOWNLOAD_COMPLETION_BROADCAST = "FILE_DOWNLOAD_COMPLETION_BROADCAST" @@ -58,18 +57,19 @@ class SyncWorker( return withContext(Dispatchers.IO) { Log_OC.d(TAG, "SyncWorker started") val filePaths = inputData.getStringArray(FILE_PATHS) - val topParentPath = inputData.getString(TOP_PARENT_PATH) - if (filePaths.isNullOrEmpty() || topParentPath.isNullOrEmpty()) { + if (filePaths.isNullOrEmpty()) { return@withContext Result.failure() } + val fileDataStorageManager = FileDataStorageManager(user, context.contentResolver) + + // Add the topParentPath to mark the sync icon on the selected folder. + val topParentPath = getTopParentPath(fileDataStorageManager, filePaths.first()) downloadingFilePaths = ArrayList(filePaths.toList()).apply { add(topParentPath) } - val fileDataStorageManager = FileDataStorageManager(user, context.contentResolver) - val account = user.toOwnCloudAccount() val client = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(account, context) @@ -115,6 +115,12 @@ class SyncWorker( } } + private fun getTopParentPath(fileDataStorageManager: FileDataStorageManager, firstFilePath: String): String { + val firstFile = fileDataStorageManager.getFileByDecryptedRemotePath(firstFilePath) + val topParentFile = fileDataStorageManager.getTopParent(firstFile) + return topParentFile.decryptedRemotePath + } + /** * It is used to remove the sync icon next to the file in the folder. */ diff --git a/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java b/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java index a2e79d350e..4e3b0fa984 100644 --- a/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java @@ -40,6 +40,7 @@ import java.util.List; import java.util.Map; import java.util.Vector; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Consumer; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; @@ -502,15 +503,11 @@ public class SynchronizeFolderOperation extends SyncOperation { } else { final var filePaths = new ArrayList(); mFilesForDirectDownload.forEach(file -> filePaths.add(file.getDecryptedRemotePath())); - if (filePaths.isEmpty()) { return; } - final var storageManager = getStorageManager(); - final OCFile firstFile = storageManager.getFileByDecryptedRemotePath(filePaths.get(0)); - final OCFile topParent = storageManager.getTopParent(firstFile); - fileDownloadHelper.syncFolder(filePaths, topParent.getDecryptedRemotePath()); + fileDownloadHelper.syncFolder(filePaths); } }