Loading app/src/main/java/it/niedermann/owncloud/notes/AppendToNoteActivity.java +1 −1 Original line number Diff line number Diff line Loading @@ -37,7 +37,7 @@ public class AppendToNoteActivity extends MainActivity { @Override public void onNoteClick(int position, View v) { if (!TextUtils.isEmpty(receivedText)) { final LiveData<Note> fullNote$ = mainViewModel.getFullNote(((Note) adapter.getItem(position)).getId()); final LiveData<Note> fullNote$ = mainViewModel.getFullNote$(((Note) adapter.getItem(position)).getId()); fullNote$.observe(this, (fullNote) -> { fullNote$.removeObservers(this); final String oldContent = fullNote.getContent(); Loading app/src/main/java/it/niedermann/owncloud/notes/main/MainViewModel.java +20 −23 Original line number Diff line number Diff line Loading @@ -528,10 +528,15 @@ public class MainViewModel extends AndroidViewModel { return db.addAccount(url, username, accountName, capabilities); } public LiveData<Note> getFullNote(long id) { public LiveData<Note> getFullNote$(long id) { return map(getFullNotesWithCategory(Collections.singleton(id)), input -> input.get(0)); } @WorkerThread public Note getFullNote(long id) { return db.getNoteDao().getNoteById(id); } public LiveData<List<Note>> getFullNotesWithCategory(@NonNull Collection<Long> ids) { return switchMap(getCurrentAccount(), currentAccount -> { if (currentAccount == null) { Loading Loading @@ -579,12 +584,8 @@ public class MainViewModel extends AndroidViewModel { return db.getAccountDao().countAccounts$(); } public LiveData<String> collectNoteContents(List<Long> noteIds) { return switchMap(getCurrentAccount(), currentAccount -> { if (currentAccount != null) { Log.v(TAG, "[collectNoteContents] - currentAccount: " + currentAccount.getAccountName()); final MutableLiveData<String> collectedContent$ = new MutableLiveData<>(); new Thread(() -> { @WorkerThread public String collectNoteContents(@NonNull List<Long> noteIds) { final StringBuilder noteContents = new StringBuilder(); for (Long noteId : noteIds) { final Note fullNote = db.getNoteDao().getNoteById(noteId); Loading @@ -596,10 +597,6 @@ public class MainViewModel extends AndroidViewModel { noteContents.append(tempFullNote); } } }).start(); return collectedContent$; } return new MutableLiveData<>(null); }); return noteContents.toString(); } } No newline at end of file app/src/main/java/it/niedermann/owncloud/notes/main/MultiSelectedActionModeCallback.java +14 −14 Original line number Diff line number Diff line Loading @@ -137,18 +137,18 @@ public class MultiSelectedActionModeCallback implements Callback { for (Long sel : tracker.getSelection()) { selection.add(sel); } // FIXME use title if only one final String subject = context.getResources().getQuantityString(R.plurals.share_multiple, selection.size(), selection.size()); // final String subject = (selection.size() == 1) // ? ((Note) adapter.getItem(adapter.getSelected().get(0))).getTitle() // : context.getResources().getQuantityString(R.plurals.share_multiple, adapter.getSelected().size(), adapter.getSelected().size()); final LiveData<String> contentCollector = mainViewModel.collectNoteContents(selection); contentCollector.observe(lifecycleOwner, (next) -> { contentCollector.removeObservers(lifecycleOwner); ShareUtil.openShareDialog(context, subject, next); tracker.clearSelection(); }); new Thread(() -> { if (selection.size() == 1) { final Note note = mainViewModel.getFullNote(selection.get(0)); ShareUtil.openShareDialog(context, note.getTitle(), note.getContent()); } else { ShareUtil.openShareDialog(context, context.getResources().getQuantityString(R.plurals.share_multiple, selection.size(), selection.size()), mainViewModel.collectNoteContents(selection)); } }).start(); return true; } else if (itemId == R.id.menu_category) {// TODO detect whether all selected notes do have the same category - in this case preselect it final LiveData<Account> accountLiveData = mainViewModel.getCurrentAccount(); Loading app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NotesListViewItemTouchHelper.java +1 −1 Original line number Diff line number Diff line Loading @@ -73,7 +73,7 @@ public class NotesListViewItemTouchHelper extends ItemTouchHelper { case ItemTouchHelper.LEFT: viewHolder.setIsRecyclable(false); final Note dbNoteWithoutContent = (Note) adapter.getItem(viewHolder.getLayoutPosition()); final LiveData<Note> dbNoteLiveData = mainViewModel.getFullNote(dbNoteWithoutContent.getId()); final LiveData<Note> dbNoteLiveData = mainViewModel.getFullNote$(dbNoteWithoutContent.getId()); dbNoteLiveData.observe(lifecycleOwner, (dbNote) -> { dbNoteLiveData.removeObservers(lifecycleOwner); tracker.deselect(dbNote.getId()); Loading Loading
app/src/main/java/it/niedermann/owncloud/notes/AppendToNoteActivity.java +1 −1 Original line number Diff line number Diff line Loading @@ -37,7 +37,7 @@ public class AppendToNoteActivity extends MainActivity { @Override public void onNoteClick(int position, View v) { if (!TextUtils.isEmpty(receivedText)) { final LiveData<Note> fullNote$ = mainViewModel.getFullNote(((Note) adapter.getItem(position)).getId()); final LiveData<Note> fullNote$ = mainViewModel.getFullNote$(((Note) adapter.getItem(position)).getId()); fullNote$.observe(this, (fullNote) -> { fullNote$.removeObservers(this); final String oldContent = fullNote.getContent(); Loading
app/src/main/java/it/niedermann/owncloud/notes/main/MainViewModel.java +20 −23 Original line number Diff line number Diff line Loading @@ -528,10 +528,15 @@ public class MainViewModel extends AndroidViewModel { return db.addAccount(url, username, accountName, capabilities); } public LiveData<Note> getFullNote(long id) { public LiveData<Note> getFullNote$(long id) { return map(getFullNotesWithCategory(Collections.singleton(id)), input -> input.get(0)); } @WorkerThread public Note getFullNote(long id) { return db.getNoteDao().getNoteById(id); } public LiveData<List<Note>> getFullNotesWithCategory(@NonNull Collection<Long> ids) { return switchMap(getCurrentAccount(), currentAccount -> { if (currentAccount == null) { Loading Loading @@ -579,12 +584,8 @@ public class MainViewModel extends AndroidViewModel { return db.getAccountDao().countAccounts$(); } public LiveData<String> collectNoteContents(List<Long> noteIds) { return switchMap(getCurrentAccount(), currentAccount -> { if (currentAccount != null) { Log.v(TAG, "[collectNoteContents] - currentAccount: " + currentAccount.getAccountName()); final MutableLiveData<String> collectedContent$ = new MutableLiveData<>(); new Thread(() -> { @WorkerThread public String collectNoteContents(@NonNull List<Long> noteIds) { final StringBuilder noteContents = new StringBuilder(); for (Long noteId : noteIds) { final Note fullNote = db.getNoteDao().getNoteById(noteId); Loading @@ -596,10 +597,6 @@ public class MainViewModel extends AndroidViewModel { noteContents.append(tempFullNote); } } }).start(); return collectedContent$; } return new MutableLiveData<>(null); }); return noteContents.toString(); } } No newline at end of file
app/src/main/java/it/niedermann/owncloud/notes/main/MultiSelectedActionModeCallback.java +14 −14 Original line number Diff line number Diff line Loading @@ -137,18 +137,18 @@ public class MultiSelectedActionModeCallback implements Callback { for (Long sel : tracker.getSelection()) { selection.add(sel); } // FIXME use title if only one final String subject = context.getResources().getQuantityString(R.plurals.share_multiple, selection.size(), selection.size()); // final String subject = (selection.size() == 1) // ? ((Note) adapter.getItem(adapter.getSelected().get(0))).getTitle() // : context.getResources().getQuantityString(R.plurals.share_multiple, adapter.getSelected().size(), adapter.getSelected().size()); final LiveData<String> contentCollector = mainViewModel.collectNoteContents(selection); contentCollector.observe(lifecycleOwner, (next) -> { contentCollector.removeObservers(lifecycleOwner); ShareUtil.openShareDialog(context, subject, next); tracker.clearSelection(); }); new Thread(() -> { if (selection.size() == 1) { final Note note = mainViewModel.getFullNote(selection.get(0)); ShareUtil.openShareDialog(context, note.getTitle(), note.getContent()); } else { ShareUtil.openShareDialog(context, context.getResources().getQuantityString(R.plurals.share_multiple, selection.size(), selection.size()), mainViewModel.collectNoteContents(selection)); } }).start(); return true; } else if (itemId == R.id.menu_category) {// TODO detect whether all selected notes do have the same category - in this case preselect it final LiveData<Account> accountLiveData = mainViewModel.getCurrentAccount(); Loading
app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NotesListViewItemTouchHelper.java +1 −1 Original line number Diff line number Diff line Loading @@ -73,7 +73,7 @@ public class NotesListViewItemTouchHelper extends ItemTouchHelper { case ItemTouchHelper.LEFT: viewHolder.setIsRecyclable(false); final Note dbNoteWithoutContent = (Note) adapter.getItem(viewHolder.getLayoutPosition()); final LiveData<Note> dbNoteLiveData = mainViewModel.getFullNote(dbNoteWithoutContent.getId()); final LiveData<Note> dbNoteLiveData = mainViewModel.getFullNote$(dbNoteWithoutContent.getId()); dbNoteLiveData.observe(lifecycleOwner, (dbNote) -> { dbNoteLiveData.removeObservers(lifecycleOwner); tracker.deselect(dbNote.getId()); Loading