From a34134526af4808b29c899104f88a75e51fa2e8c Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Fri, 14 Jul 2023 13:11:44 +0600 Subject: [PATCH] 1351-Improve_swipeLoader_ux issue: https://gitlab.e.foundation/e/os/backlog/-/issues/1351 We only want to show the MainActivity's swipeRefreshLayout's loader to be shown when user pull down for manual refresh for better UX. & there was a bug, for which some cases, this loader liveData's value is not updated if any unwanted exception occurs. some error happened in between the operation. --- .../owncloud/notes/main/MainActivity.java | 4 ++++ .../owncloud/notes/main/MainViewModel.java | 1 + .../notes/persistence/NotesRepository.java | 19 +++++++++++++++---- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java index fce42c0ba..6f7e7c392 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java @@ -336,6 +336,8 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A .setAnchorView(binding.activityNotesListView.fabCreate) .show(); } + + swipeRefreshLayout.setRefreshing(false); }); } }); @@ -376,6 +378,8 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A @Override public void onError(@NonNull Throwable t) { t.printStackTrace(); + + runOnUiThread(() -> swipeRefreshLayout.setRefreshing(false)); } }); } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/main/MainViewModel.java b/app/src/main/java/it/niedermann/owncloud/notes/main/MainViewModel.java index 95639fabd..466d9ae65 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/main/MainViewModel.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/main/MainViewModel.java @@ -386,6 +386,7 @@ public class MainViewModel extends AndroidViewModel { @Override public void onSuccess(Void v) { Log.i(TAG, "[synchronizeCapabilitiesAndNotes] Synchronize notes for " + localAccount.getAccountName()); + repo.updateSyncStatus(true); synchronizeNotes(localAccount, callback); } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java index 6f0af90f8..18adb282a 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java @@ -819,6 +819,10 @@ public class NotesRepository { } } + public void updateSyncStatus(boolean status) { + syncStatus.postValue(status); + } + /** * Schedules a synchronization and start it directly, if the network is connected and no * synchronization is currently running. @@ -828,10 +832,9 @@ public class NotesRepository { public synchronized void scheduleSync(@Nullable Account account, boolean onlyLocalChanges) { if (account == null) { Log.i(TAG, SingleSignOnAccount.class.getSimpleName() + " is null. Is this a local account?"); + syncStatus.postValue(false); } else { - if (syncActive.get(account.getId()) == null) { - syncActive.put(account.getId(), false); - } + syncActive.putIfAbsent(account.getId(), false); Log.d(TAG, "Sync requested (" + (onlyLocalChanges ? "onlyLocalChanges" : "full") + "; " + (Boolean.TRUE.equals(syncActive.get(account.getId())) ? "sync active" : "sync NOT active") + ") ..."); if (AccountSyncUtil.isSyncEnable(context, account)) { if (isSyncPossible() && (!Boolean.TRUE.equals(syncActive.get(account.getId())) || onlyLocalChanges)) { @@ -841,7 +844,6 @@ public class NotesRepository { final NotesServerSyncTask syncTask = new NotesServerSyncTask(context, this, account, onlyLocalChanges, apiProvider) { @Override void onPreExecute() { - syncStatus.postValue(true); if (!syncScheduled.containsKey(localAccount.getId()) || syncScheduled.get(localAccount.getId()) == null) { syncScheduled.put(localAccount.getId(), false); } @@ -884,6 +886,7 @@ public class NotesRepository { } catch (NextcloudFilesAppAccountNotFoundException e) { Log.e(TAG, "... Could not find " + SingleSignOnAccount.class.getSimpleName() + " for account name " + account.getAccountName()); e.printStackTrace(); + syncStatus.postValue(false); } } else if (!onlyLocalChanges) { Log.d(TAG, "... scheduled"); @@ -898,6 +901,8 @@ public class NotesRepository { Log.w(TAG, "List of push-callbacks was set for account \"" + account.getAccountName() + "\" but it was null"); } } + + syncStatus.postValue(false); } else { Log.d(TAG, "... do nothing"); if (callbacksPush.containsKey(account.getId()) && callbacksPush.get(account.getId()) != null) { @@ -910,8 +915,14 @@ public class NotesRepository { Log.w(TAG, "List of push-callbacks was set for account \"" + account.getAccountName() + "\" but it was null"); } } + + syncStatus.postValue(false); } + + return; } + + syncStatus.postValue(false); } } -- GitLab