Last active
October 30, 2018 10:04
-
-
Save bitvale/08d163baf36f833b5f7f14bc46e860bc 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 BaseRecyclerAdapter<T, VH : BaseViewHolder<T>> : RecyclerView.Adapter<VH>() { | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH { | |
val inflater = LayoutInflater.from(parent.context) | |
val binding: ViewDataBinding = DataBindingUtil.inflate(inflater, viewType, parent, false) | |
return createViewHolder(binding) | |
} | |
override fun onBindViewHolder(holder: VH, position: Int) { | |
val obj = getObjectForPosition(position) | |
holder.bind(obj) | |
} | |
override fun getItemViewType(position: Int) = getLayoutIdForPosition(position) | |
abstract fun getObjectForPosition(position: Int): T | |
abstract fun createViewHolder(binding: ViewDataBinding): VH | |
@LayoutRes | |
abstract fun getLayoutIdForPosition(position: Int): Int | |
abstract fun replaceData(data: List<T>) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment