question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use `PagingEpoxyController` with a header?

See original GitHub issue

What I’d like to do: Display a list of items (this is a PagedList, because I use the paging lib to request data as I scroll) but also have a header at the top.

With a normal TypedEpoxyController, I can achieve this by having some state type that contains the header and the list, and I set it using TypedEpoxyController.setData().

However, inside the PagingEpoxyController, all I have the option for is submitList(pagedList) or submitList(itemList) and I’m not sure how to approach including a header in all of this. Any nudges in the right direction could help.

If I’m able to get this working, I’m more than happy to contribute back with a PR including samples of doing this.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
elihartcommented, Sep 26, 2018

I’ve just published 2.18.0 release, which includes a new, improve paged list support (created by Yigit from the Android team). Check out the wiki that I just updated too: https://github.com/airbnb/epoxy/wiki/Paging-Support

TLDR: extend PagedListEpoxyController to create your controller. override buildItemModel to define how each item in the paged list gets converted to an epoxy model. then override addModels to modify the items list to add headers or whatever other changes you want.

Edit: It seems like part of your confusion is a TypedEpoxyController vs a base EpoxyController. With the typed controller you specific all of your data via setData as a helper. In a basic controller, like the paging controller you have to set it manually. This could be anything you want, like a constructor param, or a simple field. Just call requestModelBuild if it ever changes. This doesn’t have to do with paging so much, its the same as a normal epoxy controller

1reaction
dkarataievcommented, Jul 2, 2019

What if I need not one but few headers ( for example - date header for the group of messages in chat). How I can achieve this with addModels?

Seems like something like that should work:

override fun addModels(models: List<EpoxyModel<*>>) {
        if (models.size == 3000) {
            pagingView {
                id("1 header")
                name("showing ${models.size} items")
            }
            super.addModels(models.subList(0, 1000))

            pagingView {
                id("2 header")
                name("showing ${models.size} items")
            }
            super.addModels(models.subList(1000, 2000))

            pagingView {
                id("3 header")
                name("showing ${models.size} items")
            }
            super.addModels(models.subList(2000, 3000))
        }
    }
Read more comments on GitHub >

github_iconTop Results From Across the Web

2021 Android Guide: Paging 3 adding headers! - YouTube
This video completes our implementation of adding headers to our PagedList while working with the Paging 3 library!
Read more >
Exploring Paging3 — Part 2. Learn how to add header, footer ...
This article will learn how to add custom footers, headers, separators, and retry layouts to the paging adapter with code snippets. You'll also ......
Read more >
The Recyclerview List Refresh Incorretly When Using Paging ...
I have a RecyclerView with PagingEpoxyController, and when I insert some data to if you use equals, your object must properly override Object#equals() ......
Read more >
add list section headers with PagedListAdapter / PagedList
I'd like to headers in a list using the android.arch.paging components. ... Usually this would easy enough, just add different types for a ......
Read more >
sticky-header-linear-layout-manager - epoxy 4.5.0 javadoc
isStickyHeader to indicate which items are sticky. Example usage: class StickyHeaderController() : EpoxyController() { override fun isStickyHeader(position: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found