Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. @DslMarker annotation class MenuConfigurationPart
  2.  
  3. @Suppress("unused")
  4. fun menuConfig(builder: MenuConfiguration.() -> Unit) = MenuConfiguration(builder)
  5.  
  6. @MenuConfigurationPart
  7. class MenuConfiguration(
  8. inline val builder: MenuConfiguration.() -> Unit
  9. )
  10. {
  11. lateinit var header: MenuHeader
  12.  
  13. lateinit var content: MenuContent
  14.  
  15. init
  16. {
  17. builder()
  18. }
  19.  
  20. inline fun header(builder: MenuHeader.() -> Unit)
  21. {
  22. this.header = MenuHeader().apply(builder)
  23. }
  24.  
  25. inline fun content(builder: MenuContent.() -> Unit)
  26. {
  27. this.content = MenuContent().apply(builder)
  28. }
  29.  
  30. override fun equals(other: Any?): Boolean = TODO()
  31.  
  32. override fun hashCode(): Int = TODO()
  33. }
  34.  
  35. @MenuConfigurationPart
  36. class MenuHeader
  37. {
  38. lateinit var userEmail: () -> String
  39.  
  40. val viewControllers: MutableList<AViewController> = mutableListOf()
  41.  
  42. /**
  43. * [SEPARATOR_SETTING_INVISIBLE] - no separator
  44. * [SEPARATOR_SETTING_FULL_WIDTH] - full width separator
  45. * [SEPARATOR_SETTING_MARGINS] - separator with margins
  46. */
  47. @SeparatorWidthSetting
  48. var separatorWidthSetting: Int = SEPARATOR_SETTING_INVISIBLE
  49.  
  50. var hasLogout = true
  51.  
  52. operator fun AViewController.unaryPlus()
  53. {
  54. viewControllers.add(this)
  55. }
  56.  
  57. companion object
  58. {
  59. @IntDef(SEPARATOR_SETTING_INVISIBLE, SEPARATOR_SETTING_FULL_WIDTH, SEPARATOR_SETTING_MARGINS)
  60. @Retention(AnnotationRetention.SOURCE)
  61. annotation class SeparatorWidthSetting
  62.  
  63. const val SEPARATOR_SETTING_INVISIBLE = 0
  64. const val SEPARATOR_SETTING_FULL_WIDTH = 1
  65. const val SEPARATOR_SETTING_MARGINS = 2
  66. }
  67. }
  68.  
  69. @MenuConfigurationPart
  70. class MenuContent
  71. {
  72. val items = mutableListOf<DiverseRecyclerAdapter.RecyclerItem<*, *>>()
  73.  
  74. operator fun DiverseRecyclerAdapter.RecyclerItem<*, *>?.unaryPlus()
  75. {
  76. this ?: return
  77.  
  78. items.add(this)
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement