Skip to content

Instantly share code, notes, and snippets.

@programmerr47
Created December 29, 2019 11:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save programmerr47/561d1f48bdeca6d086ae9908da27612f to your computer and use it in GitHub Desktop.
Save programmerr47/561d1f48bdeca6d086ae9908da27612f to your computer and use it in GitHub Desktop.
ResViewHolder that inherits ResourceManager's behavior and ExtensionViewHolder for everything in life :)
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