|
17 | 17 | import com.nextcloud.client.account.User; |
18 | 18 | import com.nextcloud.client.jobs.download.FileDownloadHelper; |
19 | 19 | import com.nextcloud.client.jobs.folderDownload.FolderDownloadWorkerNotificationManager; |
| 20 | +import com.nextcloud.utils.extensions.ExtensionsKt; |
20 | 21 | import com.owncloud.android.datamodel.FileDataStorageManager; |
21 | 22 | import com.owncloud.android.datamodel.OCFile; |
22 | 23 | import com.owncloud.android.datamodel.e2e.v1.decrypted.DecryptedFolderMetadataFileV1; |
|
43 | 44 | import java.util.concurrent.atomic.AtomicBoolean; |
44 | 45 |
|
45 | 46 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; |
| 47 | +import kotlin.Unit; |
| 48 | +import kotlin.jvm.functions.Function0; |
46 | 49 |
|
47 | 50 | /** |
48 | 51 | * Remote operation performing the synchronization of the list of files contained |
@@ -93,8 +96,6 @@ public class SynchronizeFolderOperation extends SyncOperation { |
93 | 96 |
|
94 | 97 | final FolderDownloadWorkerNotificationManager notificationManager; |
95 | 98 |
|
96 | | - private boolean hasChildFolders = false; |
97 | | - |
98 | 99 | /** |
99 | 100 | * Creates a new instance of {@link SynchronizeFolderOperation}. |
100 | 101 | * |
@@ -399,7 +400,6 @@ private void updateLocalStateData(OCFile remoteFile, OCFile localFile, OCFile up |
399 | 400 | @SuppressFBWarnings("JLM") |
400 | 401 | private void syncFileOrFolder(OCFile remoteFile, OCFile localFile) throws OperationCancelledException { |
401 | 402 | if (remoteFile.isFolder()) { |
402 | | - hasChildFolders = true; |
403 | 403 | synchronized (mCancellationRequested) { |
404 | 404 | if (mCancellationRequested.get()) { |
405 | 405 | throw new OperationCancelledException(); |
@@ -523,47 +523,44 @@ private void startDirectDownloads() { |
523 | 523 | private void startContentSynchronizations(List<SynchronizeFileOperation> filesToSyncContents) throws OperationCancelledException { |
524 | 524 | Log_OC.v(TAG, "Starting content synchronization... "); |
525 | 525 |
|
526 | | - RemoteOperationResult contentsResult; |
527 | | - |
528 | 526 | int total = filesToSyncContents.size(); |
529 | | - int current = 0; |
530 | | - boolean success = true; |
531 | 527 | String folderName = mLocalFolder.getFileName(); |
532 | 528 |
|
533 | | - for (SynchronizeFileOperation op: filesToSyncContents) { |
| 529 | + for (int current = 0; current < filesToSyncContents.size(); current++) { |
534 | 530 | if (mCancellationRequested.get()) { |
535 | 531 | throw new OperationCancelledException(); |
536 | 532 | } |
537 | 533 |
|
538 | | - contentsResult = op.execute(mContext); |
539 | | - current++; |
| 534 | + final var synchronizeFileOperation = filesToSyncContents.get(current); |
| 535 | + final var result = synchronizeFileOperation.execute(mContext); |
| 536 | + final var file = synchronizeFileOperation.getLocalFile(); |
540 | 537 |
|
541 | | - final var file = op.getLocalFile(); |
542 | | - if (file != null) { |
| 538 | + if (result.isSuccess() && file != null) { |
543 | 539 | notificationManager.showProgressNotification(folderName, file.getFileName(), current, total); |
544 | | - } |
545 | | - |
546 | | - if (!contentsResult.isSuccess()) { |
547 | | - success = false; |
548 | | - if (contentsResult.getCode() == ResultCode.SYNC_CONFLICT) { |
| 540 | + } else { |
| 541 | + if (result.getCode() == ResultCode.SYNC_CONFLICT) { |
549 | 542 | mConflictsFound++; |
550 | 543 | } else { |
551 | 544 | mFailsInFileSyncsFound++; |
552 | | - if (contentsResult.getException() != null) { |
553 | | - Log_OC.e(TAG, "Error while synchronizing file : " |
554 | | - + contentsResult.getLogMessage(), contentsResult.getException()); |
| 545 | + |
| 546 | + String message = "Error while synchronizing file : "; |
| 547 | + |
| 548 | + if (result.getException() != null) { |
| 549 | + message = message + result.getLogMessage() + " Exception: " |
| 550 | + + result.getException().getMessage(); |
555 | 551 | } else { |
556 | | - Log_OC.e(TAG, "Error while synchronizing file : " |
557 | | - + contentsResult.getLogMessage()); |
| 552 | + message = message + result.getLogMessage(); |
558 | 553 | } |
| 554 | + |
| 555 | + Log_OC.e(TAG, message); |
559 | 556 | } |
560 | 557 | } |
561 | 558 | } |
562 | 559 |
|
563 | | - if (!hasChildFolders) { |
564 | | - notificationManager.showCompletionNotification(folderName, success); |
| 560 | + ExtensionsKt.mainThread(0L, () -> { |
565 | 561 | notificationManager.dismiss(); |
566 | | - } |
| 562 | + return Unit.INSTANCE; |
| 563 | + }); |
567 | 564 | } |
568 | 565 |
|
569 | 566 |
|
|
0 commit comments