Skip to content

Instantly share code, notes, and snippets.

@gastsail
Created June 27, 2020 18:33
Show Gist options
  • Save gastsail/d7997ba4452c0b77935f6f98ff4946b5 to your computer and use it in GitHub Desktop.
Save gastsail/d7997ba4452c0b77935f6f98ff4946b5 to your computer and use it in GitHub Desktop.
class BaseGridConcatAdapter(private val context: Context, private val animalAdapter: AnimalAdapter,private val spanCount:Int) :
RecyclerView.Adapter<BaseConcatHolder<*>>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseConcatHolder<*> {
val view = LayoutInflater.from(context).inflate(R.layout.animal_concat_row,parent,false)
view.rv_animal_concat.layoutManager = GridLayoutManager(context, spanCount)
return ConcatViewHolder(view)
}
override fun getItemCount(): Int = 1
override fun onBindViewHolder(holder: BaseConcatHolder<*>, position: Int) {
when(holder){
is ConcatViewHolder -> holder.bind(animalAdapter)
else -> throw IllegalArgumentException("No viewholder to show this data, did you forgot to add it to the onBindViewHolder?")
}
}
inner class ConcatViewHolder(itemView: View): BaseConcatHolder<AnimalAdapter>(itemView){
override fun bind(adapter: AnimalAdapter) {
itemView.rv_animal_concat.adapter = adapter
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment