Skip to content

Instantly share code, notes, and snippets.

@dragoncodes
Created September 30, 2019 06:58
Show Gist options
  • Save dragoncodes/bf3778542d081b7187743a1f73616728 to your computer and use it in GitHub Desktop.
Save dragoncodes/bf3778542d081b7187743a1f73616728 to your computer and use it in GitHub Desktop.
@DslMarker annotation class MenuConfigurationPart
@Suppress("unused")
fun menuConfig(builder: MenuConfiguration.() -> Unit) = MenuConfiguration(builder)
@MenuConfigurationPart
class MenuConfiguration(
inline val builder: MenuConfiguration.() -> Unit
)
{
lateinit var header: MenuHeader
lateinit var content: MenuContent
init
{
builder()
}
inline fun header(builder: MenuHeader.() -> Unit)
{
this.header = MenuHeader().apply(builder)
}
inline fun content(builder: MenuContent.() -> Unit)
{
this.content = MenuContent().apply(builder)
}
override fun equals(other: Any?): Boolean = TODO()
override fun hashCode(): Int = TODO()
}
@MenuConfigurationPart
class MenuHeader
{
lateinit var userEmail: () -> String
val viewControllers: MutableList<AViewController> = mutableListOf()
/**
* [SEPARATOR_SETTING_INVISIBLE] - no separator
* [SEPARATOR_SETTING_FULL_WIDTH] - full width separator
* [SEPARATOR_SETTING_MARGINS] - separator with margins
*/
@SeparatorWidthSetting
var separatorWidthSetting: Int = SEPARATOR_SETTING_INVISIBLE
var hasLogout = true
operator fun AViewController.unaryPlus()
{
viewControllers.add(this)
}
companion object
{
@IntDef(SEPARATOR_SETTING_INVISIBLE, SEPARATOR_SETTING_FULL_WIDTH, SEPARATOR_SETTING_MARGINS)
@Retention(AnnotationRetention.SOURCE)
annotation class SeparatorWidthSetting
const val SEPARATOR_SETTING_INVISIBLE = 0
const val SEPARATOR_SETTING_FULL_WIDTH = 1
const val SEPARATOR_SETTING_MARGINS = 2
}
}
@MenuConfigurationPart
class MenuContent
{
val items = mutableListOf<DiverseRecyclerAdapter.RecyclerItem<*, *>>()
operator fun DiverseRecyclerAdapter.RecyclerItem<*, *>?.unaryPlus()
{
this ?: return
items.add(this)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment