Created
April 5, 2020 13:34
-
-
Save klukwist/38375f692cee9f4ff1913ae6142db652 to your computer and use it in GitHub Desktop.
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 ProstoAdapter<TBinding : ViewDataBinding, TData> : RecyclerView.Adapter<ProstoHolder<TBinding>>() { | |
abstract val viewModel: ProstoViewModel<TData> | |
abstract val layoutId: Int | |
private var dataSize: Int = 0 | |
open fun setData(data: List<TData>) { | |
this.dataSize = data.size | |
viewModel.data = data | |
notifyDataSetChanged() | |
} | |
open var onBind: ((ProstoHolder<TBinding>) -> Unit)? = null | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ProstoHolder<TBinding> = | |
ProstoHolder.create(parent, layoutId) | |
override fun getItemCount(): Int = dataSize | |
override fun onBindViewHolder(holder: ProstoHolder<TBinding>, position: Int) { | |
holder.bind(viewModel, position) | |
onBind?.invoke(holder) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment