Skip to content

Commit

Permalink
* Do not destroy action mode if app goes to background
Browse files Browse the repository at this point in the history
* Long pressing on an item should also select it
* Navigating back while in action mode should destroy it first
  • Loading branch information
tuancoltech committed Oct 26, 2024
1 parent 78aa757 commit c0ef5dd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -307,10 +312,6 @@ class NotesFragment: BaseFragment() {
notesAdapter?.notifyItemChanged(playingAudioPosition)
}
}

if (mIsActionMode) {
toggleActionMode()
}
}

override fun onPause() {
Expand Down Expand Up @@ -411,7 +412,7 @@ class NotesFragment: BaseFragment() {
}
}

private fun toggleActionMode() {
private fun toggleActionMode(pos: Int = -1) {
if (mIsActionMode) {
binding.groupActionModeTexts.gone()
binding.layoutBottomControl.visible()
Expand Down Expand Up @@ -439,7 +440,7 @@ class NotesFragment: BaseFragment() {
showBatchDeletionDialog()
}
}
(binding.rvPinnedNotes.adapter as? NotesListAdapter)?.toggleActionMode()
(binding.rvPinnedNotes.adapter as? NotesListAdapter)?.toggleActionMode(pos)
mIsActionMode = !mIsActionMode
}

Expand Down Expand Up @@ -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()
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<androidx.appcompat.widget.AppCompatImageView
android:layout_width="@dimen/home_toolbar_icon_size"
Expand Down

0 comments on commit c0ef5dd

Please sign in to comment.