Loading app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java +9 −2 Original line number Diff line number Diff line Loading @@ -783,8 +783,15 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A @Override public void onNoteFavoriteClick(int position, View view) { final var toggleLiveData = mainViewModel.toggleFavoriteAndSync(((Note) adapter.getItem(position))); toggleLiveData.observe(this, (next) -> toggleLiveData.removeObservers(this)); if (!(adapter.getItem(position) instanceof Note note)) { return; } final var toggleLiveData = mainViewModel.toggleFavoriteAndSync(note); toggleLiveData.observe(this, (next) -> {{ toggleLiveData.removeObservers(this); adapter.notifyItemChanged(position); }}); } @Override Loading app/src/main/java/it/niedermann/owncloud/notes/main/MainViewModel.java +7 −7 Original line number Diff line number Diff line Loading @@ -514,14 +514,14 @@ public class MainViewModel extends AndroidViewModel { } public LiveData<Void> toggleFavoriteAndSync(Note note) { return switchMap(getCurrentAccount(), currentAccount -> { final var currentAccount = getCurrentAccount().getValue(); if (currentAccount != null) { Log.v(TAG, "[toggleFavoriteAndSync] - currentAccount: " + currentAccount.getAccountName()); repo.toggleFavoriteAndSync(currentAccount, note); } return new MutableLiveData<>(null); }); } public LiveData<Void> deleteNoteAndSync(long id) { Loading app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java +2 −3 Original line number Diff line number Diff line Loading @@ -540,7 +540,6 @@ public class NotesRepository { .collect(toMap(Note::getRemoteId, Note::getId)); } // FIXME: RACE CONDITION @AnyThread public void toggleFavoriteAndSync(Account account, Note note) { executor.submit(() -> { Loading @@ -553,8 +552,8 @@ public class NotesRepository { if (response.isSuccessful()) { final var updatedNote = response.body(); if (updatedNote != null) { db.getNoteDao().updateNote(updatedNote); scheduleSync(account, true); //db.getNoteDao().updateNote(note); scheduleSync(account, false); } } } catch (Exception e) { Loading Loading
app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java +9 −2 Original line number Diff line number Diff line Loading @@ -783,8 +783,15 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A @Override public void onNoteFavoriteClick(int position, View view) { final var toggleLiveData = mainViewModel.toggleFavoriteAndSync(((Note) adapter.getItem(position))); toggleLiveData.observe(this, (next) -> toggleLiveData.removeObservers(this)); if (!(adapter.getItem(position) instanceof Note note)) { return; } final var toggleLiveData = mainViewModel.toggleFavoriteAndSync(note); toggleLiveData.observe(this, (next) -> {{ toggleLiveData.removeObservers(this); adapter.notifyItemChanged(position); }}); } @Override Loading
app/src/main/java/it/niedermann/owncloud/notes/main/MainViewModel.java +7 −7 Original line number Diff line number Diff line Loading @@ -514,14 +514,14 @@ public class MainViewModel extends AndroidViewModel { } public LiveData<Void> toggleFavoriteAndSync(Note note) { return switchMap(getCurrentAccount(), currentAccount -> { final var currentAccount = getCurrentAccount().getValue(); if (currentAccount != null) { Log.v(TAG, "[toggleFavoriteAndSync] - currentAccount: " + currentAccount.getAccountName()); repo.toggleFavoriteAndSync(currentAccount, note); } return new MutableLiveData<>(null); }); } public LiveData<Void> deleteNoteAndSync(long id) { Loading
app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java +2 −3 Original line number Diff line number Diff line Loading @@ -540,7 +540,6 @@ public class NotesRepository { .collect(toMap(Note::getRemoteId, Note::getId)); } // FIXME: RACE CONDITION @AnyThread public void toggleFavoriteAndSync(Account account, Note note) { executor.submit(() -> { Loading @@ -553,8 +552,8 @@ public class NotesRepository { if (response.isSuccessful()) { final var updatedNote = response.body(); if (updatedNote != null) { db.getNoteDao().updateNote(updatedNote); scheduleSync(account, true); //db.getNoteDao().updateNote(note); scheduleSync(account, false); } } } catch (Exception e) { Loading