diff options
author | Niedermann IT-Dienstleistungen <stefan-niedermann@users.noreply.github.com> | 2021-05-24 17:16:20 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-24 17:16:20 +0300 |
commit | 2a542dbd950b098cbd3a43af681f18ccd899a27d (patch) | |
tree | b9d61ab6a1ef2e3759f521be7e87e39df22b6d74 /app/src/main/java/it/niedermann/owncloud/notes | |
parent | 695dbf280ddd746538598ac94d7d3c9aa44c107d (diff) |
Fix moving note to another account (#1235)
- Moving from within a note using the 3-dots-menu did not work at all because no account was passed to the chooser
- Moving a note does no longer require to re-read the full content. This is already done by `MainViewModel`. The method expects the full note to be passed
Diffstat (limited to 'app/src/main/java/it/niedermann/owncloud/notes')
4 files changed, 11 insertions, 18 deletions
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/edit/BaseNoteFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/edit/BaseNoteFragment.java index 78f20b17..0a2713eb 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/edit/BaseNoteFragment.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/edit/BaseNoteFragment.java @@ -24,6 +24,7 @@ import androidx.core.content.ContextCompat; import androidx.fragment.app.DialogFragment; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; +import androidx.lifecycle.LiveData; import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException; import com.nextcloud.android.sso.exceptions.NoCurrentAccountSelectedException; @@ -240,7 +241,7 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego } else if (itemId == R.id.menu_move) { new Thread(() -> { AccountPickerDialogFragment - .newInstance(new ArrayList<>(), note.getAccountId()) + .newInstance(new ArrayList<>(repo.getAccounts()), note.getAccountId()) .show(requireActivity().getSupportFragmentManager(), BaseNoteFragment.class.getSimpleName()); }).start(); return true; @@ -372,7 +373,8 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego } public void moveNote(Account account) { - repo.moveNoteToAnotherAccount(account, note); + final LiveData<Note> moveLiveData = repo.moveNoteToAnotherAccount(account, note); + moveLiveData.observe(this, (v) -> moveLiveData.removeObservers(this)); listener.close(); } 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 9c0296a1..55b45e73 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 @@ -488,7 +488,7 @@ public class MainViewModel extends AndroidViewModel { }); } - public LiveData<Note> moveNoteToAnotherAccount(Account account, Long noteId) { + public LiveData<Note> moveNoteToAnotherAccount(Account account, long noteId) { return switchMap(repo.getNoteById$(noteId), (note) -> { Log.v(TAG, "[moveNoteToAnotherAccount] - note: " + note); return repo.moveNoteToAnotherAccount(account, note); 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 c9598ba6..e20b684f 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 @@ -67,7 +67,6 @@ import static android.os.Build.VERSION.SDK_INT; import static android.os.Build.VERSION_CODES.O; import static androidx.lifecycle.Transformations.distinctUntilChanged; import static androidx.lifecycle.Transformations.map; -import static androidx.lifecycle.Transformations.switchMap; import static it.niedermann.owncloud.notes.edit.EditNoteActivity.ACTION_SHORTCUT; import static it.niedermann.owncloud.notes.shared.util.NoteUtil.generateNoteExcerpt; import static it.niedermann.owncloud.notes.widget.notelist.NoteListWidget.updateNoteListWidgets; @@ -402,10 +401,12 @@ public class NotesRepository { @MainThread public LiveData<Note> moveNoteToAnotherAccount(Account account, @NonNull Note note) { - return switchMap(db.getNoteDao().getContent$(note.getId()), (content) -> { - final Note fullNote = new Note(null, note.getModified(), note.getTitle(), content, note.getCategory(), note.getFavorite(), null); - deleteNoteAndSync(account, note.getId()); - return addNoteAndSync(account, fullNote); + final Note fullNote = new Note(null, note.getModified(), note.getTitle(), note.getContent(), note.getCategory(), note.getFavorite(), null); + deleteNoteAndSync(account, note.getId()); + return map(addNoteAndSync(account, fullNote), (createdNote) -> { + db.getNoteDao().updateStatus(createdNote.getId(), DBStatus.LOCAL_EDITED); + createdNote.setStatus(DBStatus.LOCAL_EDITED); + return createdNote; }); } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/NoteDao.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/NoteDao.java index a81c882a..ca111727 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/NoteDao.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/NoteDao.java @@ -29,11 +29,7 @@ public interface NoteDao { @Update(onConflict = OnConflictStrategy.REPLACE) int updateNote(Note newNote); - @Query("DELETE FROM NOTE WHERE accountId = :accountId") - int deleteByAccountId(Long accountId); - String getNoteById = "SELECT * FROM NOTE WHERE id = :id"; - String getContent = "SELECT content FROM NOTE WHERE id = :id"; String count = "SELECT COUNT(*) FROM NOTE WHERE status != 'LOCAL_DELETED' AND accountId = :accountId"; String countFavorites = "SELECT COUNT(*) FROM NOTE WHERE status != 'LOCAL_DELETED' AND accountId = :accountId AND favorite = 1"; String searchRecentByModified = "SELECT id, remoteId, accountId, title, favorite, excerpt, modified, category, status, '' as eTag, '' as content, 0 as scrollY FROM NOTE WHERE accountId = :accountId AND status != 'LOCAL_DELETED' AND (title LIKE :query OR content LIKE :query) ORDER BY favorite DESC, modified DESC"; @@ -66,12 +62,6 @@ public interface NoteDao { @Query(countFavorites) Integer countFavorites(long accountId); - @Query(getContent) - LiveData<String> getContent$(Long id); - - @Query(getContent) - String getContent(Long id); - @Query(searchRecentByModified) LiveData<List<Note>> searchRecentByModified$(long accountId, String query); |