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/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index 55fb0fe1..7b0eb476 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -3,7 +3,8 @@ android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto" - xmlns:tools="http://schemas.android.com/tools"> + xmlns:tools="http://schemas.android.com/tools" + android:animateLayoutChanges="true">