Skip to content

Commit 2701929

Browse files
committed
Fix longclick when same action is present multiple times
1 parent efceb87 commit 2701929

2 files changed

Lines changed: 27 additions & 27 deletions

File tree

app/src/main/java/com/philkes/notallyx/presentation/activity/note/EditActivity.kt

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,11 @@ abstract class EditActivity(private val type: Type) : LockedActivity<ActivityEdi
334334

335335
fun finishAfterDeleteForever() = super.finish()
336336

337-
private fun showActionSelectionDialog(oldAction: EditAction, isBottomBar: Boolean = false) {
337+
private fun showActionSelectionDialog(
338+
oldAction: EditAction,
339+
index: Int,
340+
isBottomBar: Boolean = false,
341+
) {
338342
val actions = EditAction.entries.filter { it != EditAction.RESTORE }
339343
ActionSelectionBottomSheet(
340344
actions,
@@ -349,7 +353,6 @@ abstract class EditActivity(private val type: Type) : LockedActivity<ActivityEdi
349353
)
350354
} else {
351355
val currentActions = prefs.editNoteActivityTopActions.value.toMutableList()
352-
val index = currentActions.indexOf(oldAction)
353356
if (
354357
index != -1 &&
355358
index < NotallyXPreferences.DEFAULT_EDIT_NOTE_TOP_ACTIONS.size
@@ -367,7 +370,6 @@ abstract class EditActivity(private val type: Type) : LockedActivity<ActivityEdi
367370
prefs.editNoteActivityBottomAction.save(newAction)
368371
} else {
369372
val currentActions = prefs.getSafeEditNoteActivityTopActions().toMutableList()
370-
val index = currentActions.indexOf(oldAction)
371373
if (index != -1) {
372374
currentActions[index] = newAction
373375
prefs.editNoteActivityTopActions.save(currentActions)
@@ -602,7 +604,7 @@ abstract class EditActivity(private val type: Type) : LockedActivity<ActivityEdi
602604
// Try to get the view for long click
603605
post {
604606
button.setOnLongClickListener {
605-
showActionSelectionDialog(action, isBottomBar = true)
607+
showActionSelectionDialog(action, index = 0, isBottomBar = true)
606608
true
607609
}
608610
}
@@ -937,22 +939,21 @@ abstract class EditActivity(private val type: Type) : LockedActivity<ActivityEdi
937939
private fun updateTopActions(topActions: List<EditAction>) {
938940
binding.Toolbar.menu.apply {
939941
clear()
940-
topActions.forEach { action ->
942+
topActions.forEachIndexed { idx, action ->
941943
val (title, icon) =
942944
action.getTitleAndIcon(
943945
notallyModel.pinned,
944946
notallyModel.viewMode.value,
945947
notallyModel.folder,
946948
notallyModel.type,
947949
)
948-
val menuItem =
949-
add(title, icon, MenuItem.SHOW_AS_ACTION_ALWAYS, itemId = action.itemId) {
950-
actionHandler.handleAction(action)
951-
}
950+
add(title, icon, MenuItem.SHOW_AS_ACTION_ALWAYS, itemId = idx) {
951+
actionHandler.handleAction(action)
952+
}
952953
// Try to get the view for long click
953954
binding.Toolbar.post {
954-
findViewById<View>(menuItem.itemId)?.setOnLongClickListener {
955-
showActionSelectionDialog(action)
955+
findViewById<View>(idx)?.setOnLongClickListener {
956+
showActionSelectionDialog(action, idx)
956957
true
957958
}
958959
}

app/src/main/java/com/philkes/notallyx/presentation/viewmodel/preference/Preference.kt

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -401,22 +401,21 @@ enum class BiometricLock(override val textResId: Int) : StaticTextProvider {
401401
override fun getText(context: Context): String = context.getString(textResId)
402402
}
403403

404-
enum class EditAction(override val textResId: Int, val drawableResId: Int, val itemId: Int) :
405-
StaticTextProvider {
406-
SEARCH(R.string.search, R.drawable.search, 1001),
407-
PIN(R.string.pin, R.drawable.pin, 1002),
408-
REMINDERS(R.string.reminders, R.drawable.notifications, 1003),
409-
LABELS(R.string.labels, R.drawable.label, 1004),
410-
CHANGE_COLOR(R.string.change_color, R.drawable.change_color, 1005),
411-
DUPLICATE(R.string.duplicate, R.drawable.content_copy, 1006),
412-
EXPORT(R.string.export, R.drawable.export, 1007),
413-
SHARE(R.string.share, R.drawable.share, 1008),
414-
DELETE(R.string.delete, R.drawable.delete, 1009),
415-
ARCHIVE(R.string.archive, R.drawable.archive, 1010),
416-
TOGGLE_VIEW_MODE(R.string.edit, R.drawable.visibility, 1011),
417-
CONVERT(R.string.convert_to_list_note, R.drawable.convert_to_text, 1012),
418-
DELETE_FOREVER(R.string.delete_forever, R.drawable.delete, 1014),
419-
RESTORE(R.string.restore, R.drawable.restore, 1015);
404+
enum class EditAction(override val textResId: Int, val drawableResId: Int) : StaticTextProvider {
405+
SEARCH(R.string.search, R.drawable.search),
406+
PIN(R.string.pin, R.drawable.pin),
407+
REMINDERS(R.string.reminders, R.drawable.notifications),
408+
LABELS(R.string.labels, R.drawable.label),
409+
CHANGE_COLOR(R.string.change_color, R.drawable.change_color),
410+
DUPLICATE(R.string.duplicate, R.drawable.content_copy),
411+
EXPORT(R.string.export, R.drawable.export),
412+
SHARE(R.string.share, R.drawable.share),
413+
DELETE(R.string.delete, R.drawable.delete),
414+
ARCHIVE(R.string.archive, R.drawable.archive),
415+
TOGGLE_VIEW_MODE(R.string.edit, R.drawable.visibility),
416+
CONVERT(R.string.convert_to_list_note, R.drawable.convert_to_text),
417+
DELETE_FOREVER(R.string.delete_forever, R.drawable.delete),
418+
RESTORE(R.string.restore, R.drawable.restore);
420419

421420
fun getTitleAndIcon(
422421
pinned: Boolean,

0 commit comments

Comments
 (0)