Skip to content

Commit

Permalink
Ensure unique additions based on index for persistent menu
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham1g5 committed Nov 6, 2024
1 parent 62adf0b commit b3af85f
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,17 @@ class PersistentMenuHelper(val isPersistentMenuEnabled: Boolean) {
private fun addPersistentCommand(command: PersistentCommand) {
// currentMenu!=null implies that we must have added items to persistent menu
check(currentMenu == null || persistentMenu.size > 0)
if (currentMenu == null) {
persistentMenu.add(command)
} else {
currentMenu!!.addCommand(command)
if (isCommandNotPresent(command)) {
if (currentMenu == null) {
persistentMenu.add(command)
} else {
currentMenu!!.addCommand(command)
}
}
}

private fun isCommandNotPresent(command: PersistentCommand): Boolean {
val currentCommands = if (currentMenu == null) persistentMenu else currentMenu!!.commands
return currentCommands.firstOrNull { persistentCommand -> persistentCommand.index == command.index } == null
}
}

0 comments on commit b3af85f

Please sign in to comment.