From 859d8a3a567f9d05e4ea26eb530a242a316b5a3e Mon Sep 17 00:00:00 2001 From: "Jan C. Borchardt" <925062+jancborchardt@users.noreply.github.com> Date: Mon, 16 Nov 2026 14:27:27 +0100 Subject: [PATCH] feat(list): add favorite, category and delete to note actions menu Assisted-by: ClaudeCode:claude-opus-5-5 AI-assistant: Claude Code 2.1.325 (Claude Opus 5.5) Signed-off-by: Jan C. Borchardt <925062+jancborchardt@users.noreply.github.com> --- .../edit/category/CategoryDialogFragment.java | 2 +- .../itemactions/ItemActionBottomSheet.kt | 10 +++- .../owncloud/notes/itemactions/NoteAction.kt | 4 ++ .../owncloud/notes/main/MainActivity.java | 43 ++++++++++++++++- .../list/NotesListViewItemTouchHelper.java | 47 +++++++++++-------- .../res/layout/dialog_change_category.xml | 2 +- app/src/main/res/values/ids.xml | 4 ++ app/src/main/res/values/strings.xml | 6 ++- 8 files changed, 93 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/edit/category/CategoryDialogFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/edit/category/CategoryDialogFragment.java index ebc0c73bd..12610a52d 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/edit/category/CategoryDialogFragment.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/edit/category/CategoryDialogFragment.java @@ -157,7 +157,7 @@ public void afterTextChanged(Editable s) { }); final MaterialAlertDialogBuilder alertDialogBuilder = new MaterialAlertDialogBuilder(requireContext()) - .setTitle(R.string.change_category_title) + .setTitle(R.string.action_edit_category) .setView(dialogView) .setCancelable(true) .setPositiveButton(R.string.action_edit_save, (dialog, which) -> listener.onCategoryChosen(editCategory.getText().toString())) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/itemactions/ItemActionBottomSheet.kt b/app/src/main/java/it/niedermann/owncloud/notes/itemactions/ItemActionBottomSheet.kt index 4cb7a49ab..547547a1c 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/itemactions/ItemActionBottomSheet.kt +++ b/app/src/main/java/it/niedermann/owncloud/notes/itemactions/ItemActionBottomSheet.kt @@ -42,8 +42,11 @@ class ItemActionBottomSheet( setTitle() addActions( listOf( + if (note.favorite) NoteAction.UNFAVORITE else NoteAction.FAVORITE, + NoteAction.EDIT_CATEGORY, NoteAction.SEE_DETAILS, - NoteAction.SEND_SHARE + NoteAction.SEND_SHARE, + NoteAction.DELETE ) ) @@ -73,6 +76,7 @@ class ItemActionBottomSheet( when (action) { NoteAction.SEE_DETAILS -> openInfo(ItemDetailsActivity.PAGE.ACTIVITIES) NoteAction.SEND_SHARE -> openInfo(ItemDetailsActivity.PAGE.SHARE) + else -> (activity as? Listener)?.onNoteActionSelected(note, action) } dismiss() } @@ -101,6 +105,10 @@ class ItemActionBottomSheet( } + interface Listener { + fun onNoteActionSelected(note: Note, action: NoteAction) + } + companion object { @JvmField val TAG: String = ItemActionBottomSheet::class.simpleName ?: "ItemActionBottomSheet" diff --git a/app/src/main/java/it/niedermann/owncloud/notes/itemactions/NoteAction.kt b/app/src/main/java/it/niedermann/owncloud/notes/itemactions/NoteAction.kt index bbefa9e53..d5f2e3e2e 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/itemactions/NoteAction.kt +++ b/app/src/main/java/it/niedermann/owncloud/notes/itemactions/NoteAction.kt @@ -17,6 +17,10 @@ enum class NoteAction( @param:StringRes val title: Int, @param:DrawableRes val icon: Int ) { + FAVORITE(R.id.action_favorite, R.string.action_favorite, R.drawable.ic_star_border_white_24dp), + UNFAVORITE(R.id.action_unfavorite, R.string.action_unfavorite, R.drawable.ic_star_white_24dp), + EDIT_CATEGORY(R.id.action_edit_category, R.string.action_edit_category, R.drawable.ic_folder_grey600_24dp), SEE_DETAILS(R.id.action_see_details, R.string.action_see_details, R.drawable.ic_info_outline_grey600_24dp), SEND_SHARE(R.id.action_send_share, R.string.action_send_share, R.drawable.ic_share_white_24dp), + DELETE(R.id.action_delete, R.string.action_delete_note, R.drawable.ic_delete_grey600_24dp), } \ No newline at end of file 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 73686517a..1a677efcb 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 @@ -82,6 +82,7 @@ import java.net.HttpURLConnection; import java.util.LinkedList; +import java.util.List; import java.util.Objects; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -104,6 +105,7 @@ import it.niedermann.owncloud.notes.exception.IntendedOfflineException; import it.niedermann.owncloud.notes.importaccount.ImportAccountActivity; import it.niedermann.owncloud.notes.itemactions.ItemActionBottomSheet; +import it.niedermann.owncloud.notes.itemactions.NoteAction; import it.niedermann.owncloud.notes.main.items.ItemAdapter; import it.niedermann.owncloud.notes.main.items.grid.GridItemDecoration; import it.niedermann.owncloud.notes.main.items.list.NotesListViewItemTouchHelper; @@ -127,7 +129,7 @@ import it.niedermann.owncloud.notes.shared.util.NoteUtil; import it.niedermann.owncloud.notes.shared.util.ShareUtil; -public class MainActivity extends LockedActivity implements NoteClickListener, AccountPickerListener, AccountSwitcherListener, CategoryDialogFragment.CategoryDialogListener { +public class MainActivity extends LockedActivity implements NoteClickListener, AccountPickerListener, AccountSwitcherListener, CategoryDialogFragment.CategoryDialogListener, ItemActionBottomSheet.Listener { private static final String TAG = MainActivity.class.getSimpleName(); @@ -145,6 +147,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A private static final int REQUEST_CODE_CREATE_NOTE = 0; private static final int REQUEST_CODE_SERVER_SETTINGS = 1; + private static final String STATE_CATEGORY_NOTE_ID = "categoryNoteId"; protected ItemAdapter adapter; private NavigationAdapter adapterCategories; @@ -161,6 +164,8 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A private SwipeRefreshLayout swipeRefreshLayout; private RecyclerView listView; private ActionMode mActionMode; + @Nullable + private Long categoryNoteId; boolean canMoveNoteToAnotherAccounts = false; @@ -494,6 +499,17 @@ public void onError(@NonNull Throwable t) { protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); mainViewModel.restoreInstanceState(); + if (savedInstanceState.containsKey(STATE_CATEGORY_NOTE_ID)) { + categoryNoteId = savedInstanceState.getLong(STATE_CATEGORY_NOTE_ID); + } + } + + @Override + protected void onSaveInstanceState(@NonNull Bundle outState) { + super.onSaveInstanceState(outState); + if (categoryNoteId != null) { + outState.putLong(STATE_CATEGORY_NOTE_ID, categoryNoteId); + } } private void handleEcosystemIntent(Intent intent) { @@ -926,6 +942,22 @@ public void openInfoBottomSheet(int position) { } } + @Override + public void onNoteActionSelected(@NonNull Note note, @NonNull NoteAction action) { + switch (action) { + case FAVORITE, UNFAVORITE -> mainViewModel.toggleFavoriteAndSync(note); + case EDIT_CATEGORY -> { + categoryNoteId = note.getId(); + CategoryDialogFragment + .newInstance(note.getAccountId(), note.getCategory()) + .show(getSupportFragmentManager(), CategoryDialogFragment.class.getSimpleName()); + } + case DELETE -> NotesListViewItemTouchHelper.deleteNoteWithUndo(this, mainViewModel, this, coordinatorLayout, fabCreate, note.getId()); + default -> { + } + } + } + private void updateToolbars(boolean enableSearch) { activityBinding.searchBar.searchBarWrapper.setVisibility(enableSearch ? GONE : VISIBLE); activityBinding.searchToolbar.setVisibility(enableSearch ? VISIBLE : GONE); @@ -964,7 +996,14 @@ public void onAccountPicked(@NonNull Account account) { @Override public void onCategoryChosen(String category) { - final var categoryLiveData = mainViewModel.setCategory(tracker.getSelection(), category); + final Iterable noteIds; + if (tracker.hasSelection() || categoryNoteId == null) { + noteIds = tracker.getSelection(); + } else { + noteIds = List.of(categoryNoteId); + } + categoryNoteId = null; + final var categoryLiveData = mainViewModel.setCategory(noteIds, category); categoryLiveData.observe(this, (next) -> categoryLiveData.removeObservers(this)); tracker.clearSelection(); } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NotesListViewItemTouchHelper.java b/app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NotesListViewItemTouchHelper.java index a0b17e285..477f3acbf 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NotesListViewItemTouchHelper.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NotesListViewItemTouchHelper.java @@ -80,25 +80,10 @@ public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) switch (direction) { case ItemTouchHelper.LEFT -> { viewHolder.setIsRecyclable(false); - final var dbNoteWithoutContent = (Note) adapter.getItem(viewHolder.getLayoutPosition()); - final var dbNoteLiveData = mainViewModel.getFullNote$(dbNoteWithoutContent.getId()); - dbNoteLiveData.observe(lifecycleOwner, (dbNote) -> { - dbNoteLiveData.removeObservers(lifecycleOwner); - tracker.deselect(dbNote.getId()); - final var deleteLiveData = mainViewModel.deleteNoteAndSync(dbNote.getId()); - deleteLiveData.observe(lifecycleOwner, (next) -> deleteLiveData.removeObservers(lifecycleOwner)); - Log.v(TAG, "Item deleted through swipe ----------------------------------------------"); - BrandedSnackbar.make(view, context.getString(R.string.action_note_deleted, dbNote.getTitle()), UNDO_DURATION) - .setAnchorView(anchorView) - .setAction(R.string.action_undo, (View v) -> { - final var undoLiveData = mainViewModel.addNoteAndSync(dbNote); - undoLiveData.observe(lifecycleOwner, (o) -> undoLiveData.removeObservers(lifecycleOwner)); - BrandedSnackbar.make(view, context.getString(R.string.action_note_restored, dbNote.getTitle()), Snackbar.LENGTH_SHORT) - .setAnchorView(anchorView) - .show(); - }) - .show(); - }); + final var note = (Note) adapter.getItem(viewHolder.getLayoutPosition()); + tracker.deselect(note.getId()); + Log.v(TAG, "Item deleted through swipe ----------------------------------------------"); + deleteNoteWithUndo(context, mainViewModel, lifecycleOwner, view, anchorView, note.getId()); } case ItemTouchHelper.RIGHT -> { viewHolder.setIsRecyclable(false); @@ -148,4 +133,28 @@ public float getSwipeEscapeVelocity(float defaultValue) { } }); } + + public static void deleteNoteWithUndo(@NonNull Context context, + @NonNull MainViewModel mainViewModel, + @NonNull LifecycleOwner lifecycleOwner, + @NonNull View view, + @NonNull View anchorView, + long noteId) { + final var dbNoteLiveData = mainViewModel.getFullNote$(noteId); + dbNoteLiveData.observe(lifecycleOwner, (dbNote) -> { + dbNoteLiveData.removeObservers(lifecycleOwner); + final var deleteLiveData = mainViewModel.deleteNoteAndSync(dbNote.getId()); + deleteLiveData.observe(lifecycleOwner, (next) -> deleteLiveData.removeObservers(lifecycleOwner)); + BrandedSnackbar.make(view, context.getString(R.string.action_note_deleted, dbNote.getTitle()), UNDO_DURATION) + .setAnchorView(anchorView) + .setAction(R.string.action_undo, (View v) -> { + final var undoLiveData = mainViewModel.addNoteAndSync(dbNote); + undoLiveData.observe(lifecycleOwner, (o) -> undoLiveData.removeObservers(lifecycleOwner)); + BrandedSnackbar.make(view, context.getString(R.string.action_note_restored, dbNote.getTitle()), Snackbar.LENGTH_SHORT) + .setAnchorView(anchorView) + .show(); + }) + .show(); + }); + } } diff --git a/app/src/main/res/layout/dialog_change_category.xml b/app/src/main/res/layout/dialog_change_category.xml index c520be054..477d86175 100644 --- a/app/src/main/res/layout/dialog_change_category.xml +++ b/app/src/main/res/layout/dialog_change_category.xml @@ -20,7 +20,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="@dimen/spacer_1x" - android:hint="@string/change_category_title" + android:hint="@string/category_name" android:labelFor="@id/search"> + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a8bf9b3f1..7ab2e04c4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -39,7 +39,7 @@ Search in %1$s Search all notes - Choose a category + Category name com.nextcloud.android.providers.UsersAndGroupsSearchProvider @@ -567,5 +567,9 @@ Details Send/share + Add to favorites + Remove from favorites + Edit category + Delete note