Skip to content

Commit

Permalink
fix code analytics
Browse files Browse the repository at this point in the history
Signed-off-by: alperozturk <[email protected]>
  • Loading branch information
alperozturk96 committed Dec 18, 2024
1 parent 61bbe47 commit 6566438
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
16 changes: 11 additions & 5 deletions app/src/main/java/com/nextcloud/client/jobs/sync/SyncWorker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)

Expand Down Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
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;

Expand Down Expand Up @@ -502,15 +503,11 @@ private void startDirectDownloads() {
} 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);
}
}

Expand Down

0 comments on commit 6566438

Please sign in to comment.