Created
June 28, 2017 03:35
Revisions
-
twocity created this gist
Jun 28, 2017 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ abstract class BaseEpoxyHolder : EpoxyHolder() { lateinit var itemView: View final override fun bindView(view: View?) { this.itemView = view!! onBindView(itemView) } abstract fun onBindView(view: View) } fun <V : View> BaseEpoxyHolder.viewId(id: Int) : ReadOnlyProperty<BaseEpoxyHolder, V> = Lazy { _, _ -> this.itemView.findViewById(id) as V } private class Lazy<T, R>(private val initializer: (T, KProperty<*>) -> R) : ReadOnlyProperty<T, R> { private object EMPTY private var value: Any? = EMPTY override fun getValue(thisRef: T, property: KProperty<*>): R { if (value == EMPTY) { value = initializer(thisRef, property) } return value as R } } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ class ItemModelHolder : BaseEpoxyHolder() { val draweeView: SimpleDraweeView by viewId(R.id.image_home_recommend_product) val titleView: TextView by viewId(R.id.text_home_recommend_product_title) override fun onBindView(view: View) { draweeView.aspectRatio = 16.0f / 9.0f } }