From b85a4acf3f8f6c700184f157229fc9ab2b9988ff Mon Sep 17 00:00:00 2001 From: tuancoltech Date: Sat, 26 Oct 2024 22:36:53 +0700 Subject: [PATCH] * Do not destroy action mode if app goes to background * Long pressing on an item should also select it * Navigating back while in action mode should destroy it first * Update ripple effect for note item --- .../arkmemo/ui/adapters/NotesListAdapter.kt | 12 +++++++++--- .../arkmemo/ui/fragments/NotesFragment.kt | 19 ++++++++++++------- .../main/res/drawable/ripple_note_item.xml | 9 +++++++++ app/src/main/res/layout/adapter_text_note.xml | 2 +- app/src/main/res/layout/fragment_home.xml | 3 ++- 5 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 app/src/main/res/drawable/ripple_note_item.xml diff --git a/app/src/main/java/dev/arkbuilders/arkmemo/ui/adapters/NotesListAdapter.kt b/app/src/main/java/dev/arkbuilders/arkmemo/ui/adapters/NotesListAdapter.kt index fa568624..f99403cc 100644 --- a/app/src/main/java/dev/arkbuilders/arkmemo/ui/adapters/NotesListAdapter.kt +++ b/app/src/main/java/dev/arkbuilders/arkmemo/ui/adapters/NotesListAdapter.kt @@ -204,10 +204,16 @@ class NotesListAdapter( this.notes = notes.toMutableList() } - fun toggleActionMode() { + fun toggleActionMode(pos: Int) { mActionMode = !mActionMode - notes.forEach { it.selected = false } - selectedNoteCount.postValue(0) + var selectedCount = 0 + notes.forEachIndexed { index, note -> + note.selected = mActionMode && index == pos + if (index == pos) { + selectedCount ++ + } + } + selectedNoteCount.postValue(selectedCount) notifyDataSetChanged() } diff --git a/app/src/main/java/dev/arkbuilders/arkmemo/ui/fragments/NotesFragment.kt b/app/src/main/java/dev/arkbuilders/arkmemo/ui/fragments/NotesFragment.kt index cba37b5c..b597b463 100644 --- a/app/src/main/java/dev/arkbuilders/arkmemo/ui/fragments/NotesFragment.kt +++ b/app/src/main/java/dev/arkbuilders/arkmemo/ui/fragments/NotesFragment.kt @@ -228,7 +228,12 @@ class NotesFragment: BaseFragment() { observePlayerSideEffect() notesAdapter?.setActivity(activity) notesAdapter?.onItemLongPressed = {pos, note -> - toggleActionMode() + toggleActionMode(pos = pos) + } + notesAdapter?.onItemClicked = { + if (mIsActionMode) { + toggleActionMode() + } } binding.rvPinnedNotes.apply { this.layoutManager = layoutManager @@ -307,10 +312,6 @@ class NotesFragment: BaseFragment() { notesAdapter?.notifyItemChanged(playingAudioPosition) } } - - if (mIsActionMode) { - toggleActionMode() - } } override fun onPause() { @@ -411,7 +412,7 @@ class NotesFragment: BaseFragment() { } } - private fun toggleActionMode() { + private fun toggleActionMode(pos: Int = -1) { if (mIsActionMode) { binding.groupActionModeTexts.gone() binding.layoutBottomControl.visible() @@ -439,7 +440,7 @@ class NotesFragment: BaseFragment() { showBatchDeletionDialog() } } - (binding.rvPinnedNotes.adapter as? NotesListAdapter)?.toggleActionMode() + (binding.rvPinnedNotes.adapter as? NotesListAdapter)?.toggleActionMode(pos) mIsActionMode = !mIsActionMode } @@ -506,6 +507,10 @@ class NotesFragment: BaseFragment() { binding.edtSearch.text.clear() binding.edtSearch.clearFocus() binding.rvPinnedNotes.layoutManager?.scrollToPosition(lastNoteItemPosition) + + } else if (mIsActionMode) { + toggleActionMode() + } else { activity.onBackPressedDispatcher.onBackPressed() } diff --git a/app/src/main/res/drawable/ripple_note_item.xml b/app/src/main/res/drawable/ripple_note_item.xml new file mode 100644 index 00000000..4aa0a653 --- /dev/null +++ b/app/src/main/res/drawable/ripple_note_item.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/adapter_text_note.xml b/app/src/main/res/layout/adapter_text_note.xml index c79996c2..ee321924 100644 --- a/app/src/main/res/layout/adapter_text_note.xml +++ b/app/src/main/res/layout/adapter_text_note.xml @@ -6,7 +6,7 @@ xmlns:tools="http://schemas.android.com/tools" android:clickable="true" android:layout_marginBottom="@dimen/note_item_padding" - android:foreground="?attr/selectableItemBackgroundBorderless"> + android:background="@drawable/ripple_note_item"> + xmlns:tools="http://schemas.android.com/tools" + android:animateLayoutChanges="true">