Skip to content

Instantly share code, notes, and snippets.

@skydoves
Created March 16, 2018 02:34
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save skydoves/b61d1937526268255dd7c86c74ed51ba to your computer and use it in GitHub Desktop.
HistoryViewHolder
class HistoryViewHolder(view: View, val delegate: Delegate) : BaseViewHolder(view) {
interface Delegate {
fun onItemClicked(history: History)
fun onDeleteHistory(history: History)
}
private lateinit var history: History
private val binding by lazy { DataBindingUtil.bind<ItemHistoryBinding>(view) }
@Throws(Exception::class)
override fun bindData(data: Any) {
if(data is History) {
history = data
drawItemView()
}
}
private fun drawItemView() {
itemView.run {
binding.history = history
binding.executePendingBindings()
item_history_delete.setOnClickListener { delegate.onDeleteHistory(history) }
}
}
override fun onClick(view: View) {
delegate.onItemClicked(history)
}
override fun onLongClick(view: View): Boolean {
return false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment