Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: tobiasKaminsky <[email protected]>
  • Loading branch information
tobiasKaminsky committed Jul 19, 2024
1 parent 0bf7ca2 commit ea6088e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class BackgroundJobFactory @Inject constructor(
return InternalTwoWaySyncWork(
context,
params,
accountManager.user,
accountManager,
powerManagementService,
connectivityService
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package com.nextcloud.client.jobs
import android.content.Context
import androidx.work.Worker
import androidx.work.WorkerParameters
import com.nextcloud.client.account.User
import com.nextcloud.client.account.UserAccountManager
import com.nextcloud.client.device.PowerManagementService
import com.nextcloud.client.network.ConnectivityService
import com.owncloud.android.datamodel.FileDataStorageManager
Expand All @@ -20,43 +20,54 @@ import com.owncloud.android.operations.SynchronizeFolderOperation
class InternalTwoWaySyncWork(
private val context: Context,
params: WorkerParameters,
private val user: User,
private val userAccountManager: UserAccountManager,
private val powerManagementService: PowerManagementService,
private val connectivityService: ConnectivityService
) : Worker(context, params) {
override fun doWork(): Result {
val fileDataStorageManager = FileDataStorageManager(user, context.contentResolver)
Log_OC.d(TAG, "Worker started!")




val folders = fileDataStorageManager.getInternalTwoWaySyncFolders(user)

var result = true

if (!powerManagementService.isPowerSavingEnabled ||
connectivityService.isConnected && !connectivityService.isInternetWalled) {

for (folder in folders) {
Log_OC.d(TAG, "Folder ${folder.remotePath}: started!")
val operation = SynchronizeFolderOperation(context, folder.remotePath, user, fileDataStorageManager)
.execute(context)
val users = userAccountManager.allUsers

for (user in users) {
val fileDataStorageManager = FileDataStorageManager(user, context.contentResolver)
val folders = fileDataStorageManager.getInternalTwoWaySyncFolders(user)

for (folder in folders) {
Log_OC.d(TAG, "Folder ${folder.remotePath}: started!")
val operation = SynchronizeFolderOperation(context, folder.remotePath, user, fileDataStorageManager)
.execute(context)

if (operation.isSuccess) {
Log_OC.d(TAG, "Folder ${folder.remotePath}: finished!")
} else {
Log_OC.d(TAG, "Folder ${folder.remotePath} failed!")
result = false
}

if (operation.isSuccess) {
Log_OC.d(TAG, "Folder ${folder.remotePath}: finished!")
} else {
Log_OC.d(TAG, "Folder ${folder.remotePath} failed!")
result = false
folder.internalFolderSyncResult = operation.code.toString()
folder.internalFolderSyncTimestamp = System.currentTimeMillis()
fileDataStorageManager.saveFile(folder)
}

folder.internalFolderSyncResult = operation.code.toString()
folder.internalFolderSyncTimestamp = System.currentTimeMillis()
fileDataStorageManager.saveFile(folder)
}
} else {
Log_OC.d(TAG, "Not starting due to constraints!")
}

return if (result) {
Log_OC.d(TAG, "Worker finished with success!")
Result.success()
} else {
Log_OC.d(TAG, "Worker finished with failure!")
Result.failure()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2480,4 +2480,18 @@ public List<OCFile> getInternalTwoWaySyncFolders(User user) {

return files;
}

public boolean isPartOfInternalTwoWaySync(OCFile file) {
if (file.isInternalFolderSync()) {
return true;
}

while (file != null && !OCFile.ROOT_PATH.equals(file.getDecryptedRemotePath())) {
if (file.isInternalFolderSync()) {
return true;
}
file = getFileById(file.getParentId());
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -562,10 +562,14 @@ public void updateFileDetails(boolean transferring, boolean refresh) {

binding.syncBlock.setVisibility(file.isFolder() ? View.VISIBLE : View.GONE);



binding.folderSyncButton.setChecked(file.isInternalFolderSync());
// TODO if any parent folder sync -> checked, but disabled
if (file.isInternalFolderSync()) {
binding.folderSyncButton.setChecked(file.isInternalFolderSync());
} else {
if (storageManager.isPartOfInternalTwoWaySync(file)) {
binding.folderSyncButton.setChecked(true);
binding.folderSyncButton.setEnabled(false);
}
}
}

setupViewPager();
Expand Down

0 comments on commit ea6088e

Please sign in to comment.