Skip to content

Commit d500c2a

Browse files
committed
Fix longclick when same action is present multiple times
1 parent e3b94ce commit d500c2a

3 files changed

Lines changed: 32 additions & 34 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ class MainActivity : LockedActivity<ActivityMainBinding>() {
429429
baseModel.deleteSelectedBaseNotes()
430430
Snackbar.make(
431431
findViewById(R.id.DrawerLayout),
432-
getQuantityString(R.plurals.deleted_selected_notes, 1),
432+
getQuantityString(R.plurals.deleted_selected_notes, removedNotes.size),
433433
Snackbar.LENGTH_SHORT,
434434
)
435435
.apply { setAction(R.string.undo) { baseModel.saveNotes(removedNotes) } }

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

Lines changed: 16 additions & 17 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,
@@ -348,12 +352,9 @@ abstract class EditActivity(private val type: Type) : LockedActivity<ActivityEdi
348352
NotallyXPreferences.DEFAULT_EDIT_NOTE_BOTTOM_ACTION
349353
)
350354
} else {
351-
val currentActions = prefs.editNoteActivityTopActions.value.toMutableList()
352-
val index = currentActions.indexOf(oldAction)
353-
if (
354-
index != -1 &&
355-
index < NotallyXPreferences.DEFAULT_EDIT_NOTE_TOP_ACTIONS.size
356-
) {
355+
val currentActions =
356+
prefs.getSafeEditNoteActivityTopActions().toMutableList()
357+
if (index in currentActions.indices) {
357358
currentActions[index] =
358359
NotallyXPreferences.DEFAULT_EDIT_NOTE_TOP_ACTIONS[index]
359360
prefs.editNoteActivityTopActions.save(currentActions)
@@ -367,8 +368,7 @@ abstract class EditActivity(private val type: Type) : LockedActivity<ActivityEdi
367368
prefs.editNoteActivityBottomAction.save(newAction)
368369
} else {
369370
val currentActions = prefs.getSafeEditNoteActivityTopActions().toMutableList()
370-
val index = currentActions.indexOf(oldAction)
371-
if (index != -1) {
371+
if (index in currentActions.indices) {
372372
currentActions[index] = newAction
373373
prefs.editNoteActivityTopActions.save(currentActions)
374374
}
@@ -602,7 +602,7 @@ abstract class EditActivity(private val type: Type) : LockedActivity<ActivityEdi
602602
// Try to get the view for long click
603603
post {
604604
button.setOnLongClickListener {
605-
showActionSelectionDialog(action, isBottomBar = true)
605+
showActionSelectionDialog(action, index = 0, isBottomBar = true)
606606
true
607607
}
608608
}
@@ -937,22 +937,21 @@ abstract class EditActivity(private val type: Type) : LockedActivity<ActivityEdi
937937
private fun updateTopActions(topActions: List<EditAction>) {
938938
binding.Toolbar.menu.apply {
939939
clear()
940-
topActions.forEach { action ->
940+
topActions.forEachIndexed { idx, action ->
941941
val (title, icon) =
942942
action.getTitleAndIcon(
943943
notallyModel.pinned,
944944
notallyModel.viewMode.value,
945945
notallyModel.folder,
946946
notallyModel.type,
947947
)
948-
val menuItem =
949-
add(title, icon, MenuItem.SHOW_AS_ACTION_ALWAYS, itemId = action.itemId) {
950-
actionHandler.handleAction(action)
951-
}
948+
add(title, icon, MenuItem.SHOW_AS_ACTION_ALWAYS, itemId = idx) {
949+
actionHandler.handleAction(action)
950+
}
952951
// Try to get the view for long click
953952
binding.Toolbar.post {
954-
findViewById<View>(menuItem.itemId)?.setOnLongClickListener {
955-
showActionSelectionDialog(action)
953+
findViewById<View>(idx)?.setOnLongClickListener {
954+
showActionSelectionDialog(action, idx)
956955
true
957956
}
958957
}

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)