Skip to content

Nullable items property in AbsDelegationAdapter after 4.3.2. #110

@denisstarodubov

Description

@denisstarodubov

Hi!
Release 4.3.2 added the @nullable annotation for the items property in the AbsDelegationAdapter class. In this regard, all the adapters in our project has been broken. All of them were built according to the following pattern:

internal class TestAdapter : ListDelegationAdapter<List<TestItem>>() {

    init {
        items = listOf()
        delegatesManager
            .addDelegate(TestDelegate())
    }

    fun setData(list: List<TestItem>) {
        val oldData = items
        items = list
        dispatchUpdates(oldData)
    }

    private fun dispatchUpdates(oldData: List<TestItem>) {
        Diffutil
            .calculateDiff(TestDiffCallback(items, oldData), false)
            .dispatchUpdatesTo(this)
    }
}

This approach has been used in several different projects that I have worked on.
After the update, this approach stopped working, since now we are operating on a nullable items list:

Screenshot 2022-08-31 at 14 42 23

I have not found an example in Readme how to use ListDelegationAdapter + DiffUtil when list is nullable.

It is possible to check for null each time or write requireNotNull(items) / items!!, but in this case a lot of adapters has to be rewritten.

Is there any correct way to work with ListDelegationAdapter + DiffUtil?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions