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 fce42c0ba73f3c1deb4498de6eb5cca5535f12be..6f7e7c392e9704a6d66a8541db227af739fc1e41 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 95639fabdfe682a550d32d4f64442df38a7455af..466d9ae65039f2ace98e0ee334afc10a016c30dd 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 6f0af90f886959dd5cb4f8ff0e6a3a542c6bf853..18adb282a8422e9e46fee7d6b312123ebff803ed 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); } }