Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 79936382 authored by Stefan Maftei's avatar Stefan Maftei
Browse files

[Expressive design] Notify only about changed items in SettingsPreferenceGroupAdapter



Bug:382425714
Test: visual in both showcase app and in Security & Privacy
Flag: EXEMPT recyclerview update
Change-Id: Ibd1a263cb677e01fb5f8bfafc4f1360052fd584d
Signed-off-by: default avatarStefan Maftei <smaftei@google.com>
parent b7b65626
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
@@ -95,8 +95,27 @@ open class SettingsPreferenceGroupAdapter(preferenceGroup: PreferenceGroup) :
        val oldList = ArrayList(mRoundCornerMappingList)
        mRoundCornerMappingList = ArrayList()
        mappingPreferenceGroup(mRoundCornerMappingList, mPreferenceGroup)

        if (mRoundCornerMappingList != oldList) {
            notifyDataSetChanged()
            notifyOnlyChangedItems(oldList, mRoundCornerMappingList)
        }
    }

    /** Notify any registered observers if the new list's items changed. */
    private fun notifyOnlyChangedItems(oldList: ArrayList<Int>, newList: ArrayList<Int>) {
        val minLength = minOf(oldList.size, newList.size)

        for (position in 0 until minLength) {
            if (oldList[position] != newList[position]) {
                notifyItemChanged(position)
            }
        }

        // If the remaining items are from the new list, notify about all of them
        val remainingItems = newList.size - minLength

        if (remainingItems > 0) {
            notifyItemRangeChanged(minLength, remainingItems)
        }
    }