Anyone faced this issue with epoxy. SetData on epo...
# android
r
Anyone faced this issue with epoxy. SetData on epoxy controller isn't appending to the old list but overwriting it.
Copy code
class 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)
      }
    }
  }
}
Copy code
@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)
}
d
What exactly is the issue here?
r
How am i supposed to append new data to the existing data. Like how we do in recyclerView, append new data and call notifyItemRangeInserted(). Does epoxy does it by default when i call
epoxycontroller.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(). @dewildte
d
Copy code
requestModelBuild()
This method will update the list of models.
That kicks off the diff and eventually updates the UI.
You update the list of articles then call
requestModelBuild
.
r
Yeah, and to do that. i need to update the models with oldData + newData. I was more hoping to just pass the newData to epoxy adapter and it will add the newData to it's oldData and run the diff. But, I need to have the state. calling setData() with old+new items worked for me.
d
Why do you need the old list?
The new list is good enough.
Are you saying that the new list does not contain the old items?
r
No, my next paginated list was only having new data, which i was passing to epoxy as
expoxyController.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
n
if you are extending
EpoxyAdapter
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.
1
✔️ 1
💯 1
a
+1 Nadir epoxy follows a compsable UI building pattern. You declare the way UI should be built from a set of data and let epoxy infer & diff for each submit. (just like with a ListAdapter)