ritesh
03/27/2020, 12:28 PMclass KnowledgeArticleListController : Typed2EpoxyController<List<Article>, KnowledgeArticleListActionHandler>() {
override fun setDebugLoggingEnabled(enabled: Boolean) {
super.setDebugLoggingEnabled(true)
}
override fun buildModels(data: List<Article>, listener: KnowledgeArticleListActionHandler) {
data.forEachIndexed { index, article ->
knowledgeArticleListItemView {
id(article.id)
article(article)
listener(listener)
lastItem(index == data.lastIndex)
}
}
}
}
@EpoxyModelClass(layout = R.layout.knowledge_article_list_item)
abstract class KnowledgeArticleListItemView : EpoxyModelWithHolder<ViewViewHolder>() {
@EpoxyAttribute
var category: Category? = null
@EpoxyAttribute
var article: Article? = null
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash)
lateinit var listener: KnowledgeArticleListActionHandler
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash)
var lastItem: Boolean = false
override fun bind(holder: ViewViewHolder) {
if (category != null) {
} else if (article != null) {
}
holder.knowledgeArticleListItemCell.showTopBorder = false
// don't show bottom border if last item, toolbar border is there
holder.knowledgeArticleListItemCell.showBottomBorder = !lastItem
}
override fun unbind(holder: ViewViewHolder) {
holder.knowledgeArticleListItemCell.setOnClickListener(null)
}
}
class ViewViewHolder : KotlinEpoxyHolder() {
val knowledgeArticleListItemCell by bind<StandardCell>(R.id.knowledgeArticleListItemCell)
}
dewildte
03/27/2020, 3:26 PMritesh
03/27/2020, 3:42 PMepoxycontroller.setData(newData)
and runs diffutil and appends newData to old data or i need to manage the old state and give old+new data to setData(). @dewildtedewildte
03/27/2020, 3:44 PMrequestModelBuild()
This method will update the list of models.dewildte
03/27/2020, 3:45 PMdewildte
03/27/2020, 3:46 PMrequestModelBuild
.ritesh
03/27/2020, 4:25 PMdewildte
03/27/2020, 5:31 PMdewildte
03/27/2020, 5:31 PMdewildte
03/27/2020, 5:32 PMritesh
03/27/2020, 5:46 PMexpoxyController.setData(newData)
and was hoping, epoxy adapter will do oldData+newData
and do the diff on it. I ended up maintaning old state in viewmodel and adding the newData to oldData and then passing it to epoxyController
Nadir N Williams
04/03/2020, 6:27 PMEpoxyAdapter
you should have access to protected methods like addModels()
which should append to your list. May need to call notifyDataSetChanged()
after.
But IMO think your data should be held in another layer and you should just pass the entire list everytime since the diffing tools within the adapter are optimized to not redraw views that are still valid.Achraf Amil
04/06/2020, 9:45 PM