Skip to content

Commit 8b93ad4

Browse files
committed
feat(sync-all): show notifications
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
1 parent 883a319 commit 8b93ad4

1 file changed

Lines changed: 22 additions & 25 deletions

File tree

app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.nextcloud.client.account.User;
1818
import com.nextcloud.client.jobs.download.FileDownloadHelper;
1919
import com.nextcloud.client.jobs.folderDownload.FolderDownloadWorkerNotificationManager;
20+
import com.nextcloud.utils.extensions.ExtensionsKt;
2021
import com.owncloud.android.datamodel.FileDataStorageManager;
2122
import com.owncloud.android.datamodel.OCFile;
2223
import com.owncloud.android.datamodel.e2e.v1.decrypted.DecryptedFolderMetadataFileV1;
@@ -43,6 +44,8 @@
4344
import java.util.concurrent.atomic.AtomicBoolean;
4445

4546
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
47+
import kotlin.Unit;
48+
import kotlin.jvm.functions.Function0;
4649

4750
/**
4851
* Remote operation performing the synchronization of the list of files contained
@@ -93,8 +96,6 @@ public class SynchronizeFolderOperation extends SyncOperation {
9396

9497
final FolderDownloadWorkerNotificationManager notificationManager;
9598

96-
private boolean hasChildFolders = false;
97-
9899
/**
99100
* Creates a new instance of {@link SynchronizeFolderOperation}.
100101
*
@@ -399,7 +400,6 @@ private void updateLocalStateData(OCFile remoteFile, OCFile localFile, OCFile up
399400
@SuppressFBWarnings("JLM")
400401
private void syncFileOrFolder(OCFile remoteFile, OCFile localFile) throws OperationCancelledException {
401402
if (remoteFile.isFolder()) {
402-
hasChildFolders = true;
403403
synchronized (mCancellationRequested) {
404404
if (mCancellationRequested.get()) {
405405
throw new OperationCancelledException();
@@ -523,47 +523,44 @@ private void startDirectDownloads() {
523523
private void startContentSynchronizations(List<SynchronizeFileOperation> filesToSyncContents) throws OperationCancelledException {
524524
Log_OC.v(TAG, "Starting content synchronization... ");
525525

526-
RemoteOperationResult contentsResult;
527-
528526
int total = filesToSyncContents.size();
529-
int current = 0;
530-
boolean success = true;
531527
String folderName = mLocalFolder.getFileName();
532528

533-
for (SynchronizeFileOperation op: filesToSyncContents) {
529+
for (int current = 0; current < filesToSyncContents.size(); current++) {
534530
if (mCancellationRequested.get()) {
535531
throw new OperationCancelledException();
536532
}
537533

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();
540537

541-
final var file = op.getLocalFile();
542-
if (file != null) {
538+
if (result.isSuccess() && file != null) {
543539
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) {
549542
mConflictsFound++;
550543
} else {
551544
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();
555551
} else {
556-
Log_OC.e(TAG, "Error while synchronizing file : "
557-
+ contentsResult.getLogMessage());
552+
message = message + result.getLogMessage();
558553
}
554+
555+
Log_OC.e(TAG, message);
559556
}
560557
}
561558
}
562559

563-
if (!hasChildFolders) {
564-
notificationManager.showCompletionNotification(folderName, success);
560+
ExtensionsKt.mainThread(0L, () -> {
565561
notificationManager.dismiss();
566-
}
562+
return Unit.INSTANCE;
563+
});
567564
}
568565

569566

0 commit comments

Comments
 (0)