Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. abstract class BaseEpoxyHolder : EpoxyHolder() {
  2. lateinit var itemView: View
  3.  
  4. final override fun bindView(view: View?) {
  5. this.itemView = view!!
  6. onBindView(itemView)
  7. }
  8.  
  9. abstract fun onBindView(view: View)
  10. }
  11.  
  12. fun <V : View> BaseEpoxyHolder.viewId(id: Int)
  13. : ReadOnlyProperty<BaseEpoxyHolder, V> = Lazy { _, _ ->
  14. this.itemView.findViewById(id) as V
  15. }
  16.  
  17. private class Lazy<T, R>(private val initializer: (T, KProperty<*>) -> R) : ReadOnlyProperty<T, R> {
  18. private object EMPTY
  19.  
  20. private var value: Any? = EMPTY
  21.  
  22. override fun getValue(thisRef: T, property: KProperty<*>): R {
  23. if (value == EMPTY) {
  24. value = initializer(thisRef, property)
  25. }
  26. return value as R
  27. }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement