fix code analytics

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-12-12 16:00:03 +01:00 committed by Alper Öztürk
parent c5e441a51d
commit f1cbb590eb
5 changed files with 17 additions and 15 deletions

View file

@ -172,5 +172,5 @@ interface BackgroundJobManager {
fun startPeriodicallyOfflineOperation()
fun scheduleInternal2WaySync(intervalMinutes: Long)
fun cancelAllFilesDownloadJobs()
fun syncFolder(filePaths: List<String>, topParentPath: String)
fun syncFolder(filePaths: List<String>)
}

View file

@ -715,10 +715,9 @@ internal class BackgroundJobManagerImpl(
workManager.enqueueUniquePeriodicWork(JOB_INTERNAL_TWO_WAY_SYNC, ExistingPeriodicWorkPolicy.UPDATE, request)
}
override fun syncFolder(filePaths: List<String>, topParentPath: String) {
override fun syncFolder(filePaths: List<String>) {
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)

View file

@ -138,7 +138,7 @@ class FileDownloadHelper {
)
}
fun syncFolder(filePaths: List<String>, topParentPath: String) {
backgroundJobManager.syncFolder(filePaths, topParentPath)
fun syncFolder(filePaths: List<String>) {
backgroundJobManager.syncFolder(filePaths)
}
}

View file

@ -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.
*/

View file

@ -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<String>();
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);
}
}