Comments (2)
DatabindingBinder:
package com.fyeo.util.mva3
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.annotation.LayoutRes
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import mva3.adapter.ItemBinder
abstract class DataBindingItemBinder<M, VDB : ViewDataBinding>(@LayoutRes private val layoutRes: Int) :
ItemBinder<M, DataBindingItemBinder.ViewHolder<M, VDB>>() {
override fun createViewHolder(parent: ViewGroup): ViewHolder<M, VDB> {
return createViewHolder(createBinding(parent))
}
override fun bindViewHolder(
holder: ViewHolder<M, VDB>,
item: M
) {
bindModel(item, holder)
holder.binding.executePendingBindings()
}
override fun bindViewHolder(
holder: ViewHolder<M, VDB>,
item: M,
payloads: MutableList<Any?>?
) {
bindModel(item, holder, payloads)
holder.binding.executePendingBindings()
}
private fun createViewHolder(binding: VDB): ViewHolder<M, VDB> {
return ViewHolder(binding)
}
protected abstract fun bindModel(item: M, holder: ViewHolder<M, VDB>)
protected open fun bindModel(
item: M,
holder: ViewHolder<M, VDB>,
payloads: MutableList<Any?>?
) {
bindModel(item, holder)
}
private fun createBinding(parent: ViewGroup): VDB {
val inflater = LayoutInflater.from(parent.context)
return DataBindingUtil.inflate(inflater, layoutRes, parent, false)
}
class ViewHolder<M, VDB : ViewDataBinding?>(binding: VDB) :
BindingViewHolder<M, VDB>(binding)
}
Databinding with DiffUtils support:
package com.fyeo.util.mva3
import android.view.ViewGroup
import androidx.databinding.ViewDataBinding
import mva3.adapter.ItemBinder
abstract class DBItemBinderWithPayload<M, VDB : ViewDataBinding?> :
ItemBinder<M, DBItemBinderWithPayload.ViewHolder<M?, VDB?>>() {
override fun createViewHolder(parent: ViewGroup): ViewHolder<M?, VDB?> {
return createViewHolder(createBinding(parent))
}
override fun bindViewHolder(
holder: ViewHolder<M?, VDB?>,
item: M
) {
bindModel(item, holder.binding!!)
holder.binding.executePendingBindings()
}
override fun bindViewHolder(
holder: ViewHolder<M?, VDB?>,
item: M,
payloads: MutableList<Any?>?
) {
bindModel(item, holder.binding!!, payloads)
holder.binding.executePendingBindings()
}
private fun createViewHolder(binding: VDB): ViewHolder<M?, VDB?> {
return ViewHolder(binding)
}
protected abstract fun bindModel(item: M, binding: VDB)
protected open fun bindModel(item: M, binding: VDB, payloads: MutableList<Any?>?) {
bindModel(item, binding)
}
protected abstract fun createBinding(parent: ViewGroup): VDB
class ViewHolder<M, VDB : ViewDataBinding?>(binding: VDB) :
BindingViewHolder<M, VDB>(binding)
}
BindingViewHolder.kt
abstract class BindingViewHolder<M, VDB : ViewDataBinding?>(val binding: VDB) :
ItemViewHolder<M>(binding!!.root)
from multiviewadapter.
+1 on this
Meanwhile, you can write some BindingAdapters to do the job.
from multiviewadapter.
Related Issues (20)
- Can I add multiple binder with same DataModel? HOT 2
- Failed to resolve: dev.ahamed.mva2:adapter:3.0.0-beta01 HOT 1
- Support for selectAll function into a Section HOT 1
- Support for select specific item from section HOT 3
- Does it have Firestore support? HOT 1
- Save persistent state HOT 1
- [Question] Disabling default animations
- InfiniteScroll not working for horizontal recycler view HOT 1
- Persistent item position in RecyclerView using drag and drop
- Unable to provide our own PositionType within a section.
- InfiniteLoadingHelper and StaggeredGridLayoutManager
- Layout manager: reverseLayout HOT 2
- IllegalStateException when loading items
- How can I update the item in a TreeSection?
- TreeSection.getChild(0) crashes! This actually return an item section.
- Section is already has a parent!
- Diffutil HOT 1
- MultiViewAdapter not working views are not showing up
- How to use another LayoutManager for sections? HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from multiviewadapter.