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