-
-
Save programmerr47/561d1f48bdeca6d086ae9908da27612f to your computer and use it in GitHub Desktop.
ResViewHolder that inherits ResourceManager's behavior and ExtensionViewHolder for everything in life :)
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
open class ResViewHolder( | |
itemView: View, | |
resManager: ResourcesManager = AppResourcesManager(itemView.context) | |
) : RecyclerView.ViewHolder(itemView), ResourcesManager by resManager | |
open class ExtensionViewHolder<I>(override val containerView: View) : ResViewHolder(containerView), LayoutContainer { | |
var holdItem: I? = null | |
//This is needed, in case we moved xml into one module, but define delegates in other module | |
private val viewMap: MutableMap<Int, View> = HashMap() | |
fun <T> bind(@IdRes id: Int) = viewMap.getOrPut(id) { itemView.findViewById(id) } as T | |
inline infix fun View.bindClick( | |
crossinline onClick: (I) -> Unit | |
) = setOnClickListener { holdItem?.let(onClick) } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment