Created
June 28, 2017 03:35
-
-
Save twocity/b851144601b2bcb531512013675a8702 to your computer and use it in GitHub Desktop.
EpoxyHolder' views init
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
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 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
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 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment