Closed Chimildic closed 2 years ago
Not sure on the usecase for such a setup. Seems like this is working around what the FastAdapter
offers, making it obsolete?
Anyways, there's the API used internally within the FastAdapter to get the item / adapter: https://github.com/mikepenz/FastAdapter/blob/develop/fastadapter/src/main/java/com/mikepenz/fastadapter/FastAdapter.kt#L946-L984
No sure that understand API, because item
is null in this case:
override fun onBindMany(viewHolder: RecyclerView.ViewHolder): List<View>? {
if (viewHolder !is BindingViewHolder<*>)
return null
return when (viewHolder.binding) {
is ToolboxOrderItemBinding -> {
val binding = viewHolder.binding as ToolboxOrderItemBinding
val item = FastAdapter.getHolderAdapterItem<ToolboxOrderItem>(viewHolder)
return item?.onBindMany(binding)
}
else -> null
}
}
@Chimildic well it's null if it was not yet bound by the FastAdapter
.
There is no other way to get the holder by the item otherwise.
Also please note that it will also be null
if it is currently not visible in the RV
. As the RecyclerView
will re-use ViewHolders
and dynamically bind and unbind the data as you scroll.
// item
class ToolboxOrder(
override val level: Int,
override var model: ToolboxOrderModel,
override var parent: IParentItem<*>?,
) : ModelAbstractBindingLevelItem<ToolboxOrderModel, ToolboxOrderBinding>(model),
ISubItem<BindingViewHolder<ToolboxOrderBinding>> {
// ...
companion object {
fun onBindMany(binding: ToolboxOrderBinding): List<View> {
return binding.run {
listOf(
// ...
)
}
}
}
}
// fragment
override fun onBindMany(viewHolder: RecyclerView.ViewHolder): List<View>? {
if (viewHolder !is BindingViewHolder<*>)
return null
return when (viewHolder.binding) {
is ToolboxOrderBinding ->
ToolboxOrder.onBindMany(viewHolder.binding as ToolboxOrderBinding)
else -> null
}
}
Bind logic inside
Fragment
I would like to incapsulate list of view inside
Item
. Something like this:But is there way get
Item
fromViewHolder
? In order to callitem.onBindMany(viewHolder.binding)
Checklist