sockeqwe/AdapterDelegates

The adapter creates all list elements at once.

Vanek1756 opened this issue · 0 comments

Hi!
My adapter looks like this:

private val adapter by lazy {
         AsyncListDiffDelegationAdapter(
             anotherAdapter(),
             anotherAdapter2(),
             anotherAdapter3(),
             sportContentAdapterDelegate() // problematic delegate
         )
     }

sportContentAdapterDelegate - accepts the Content model as input:

data class Content(
    val id: Int,
    val name: String,
    val isExpanded,
    val entity: List<League>
)

sportContentAdapterDelegate - Creates an internal RecyclerView and has its own adapter that looks like this:

val adapter = AsyncListDiffDelegationAdapter(
         sportLeagueExpandedAdapterDelegate()
     )

sportLeagueExpandedAdapterDelegate - accepts the League model as input:

data class League(
    val id: Int,
    val name: String,
    val isExpanded: Boolean,
    val entity: List<Event>
)

sportLeagueExpandedAdapterDelegate - Creates an internal RecyclerView and has its own adapter that looks like this:

val adapter = AsyncListDiffDelegationAdapter(
         eventItemAdapterDelegate()
     )

sportLeagueExpandedAdapterDelegate - accepts the Event model as input:

data class Event(
    val id: Int,
    val name: String,
    val startAt: String
)

eventItemAdapterDelegate - creates a custom design element

Situation:
There is a list of 30 Content models, all elements have the field isExpanded = false.

Expected behavior:
RecyclerView creates only the first 8 Content elements that are visible on the screen, each subsequent one will be created during scrolling, internal elements will be created when the isExpanded field becomes true.

Actual behavior:
RecyclerView will create all 30 Content elements at once, creates all internal League elements of each Content element, and accordingly creates all internal Event elements of the League element.

Q: Why does RecyclerView create everything at once, so how do I fix it?