Last active
August 5, 2021 01:24
-
-
Save darylsze/3588b5a3428ed48c87db509d14a32938 to your computer and use it in GitHub Desktop.
Kotlin DSL to runtime build a configuration-easy menu by enum options. You can control a set of configuration for each menu item, including prerequisite condition, ordering, general callback or individual callback.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun onCreate() { | |
baseViewHolder.menu { | |
validate { | |
match(isAdmin) { | |
addItem(MenuOption.PIN) | |
} | |
} | |
addItem(MenuOption.COPY) | |
validate { | |
match(isLoggedIn) { | |
addItem(MenuOption.BOOKMARK) | |
} | |
match(isLoggedIn && _model.isSent) { | |
addItem(MenuOption.REPLY) | |
} | |
} | |
addItem(MenuOption.REPORT) | |
validate { | |
match(Env.isDebug) { | |
addItem(MenuOption.DEBUG) | |
} | |
} | |
addCommonCallback { menuOption -> | |
onMenuItemClickListener?.invoke(_model, menuOption) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment