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

Commit 05fc0077 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add the addBefore and addAfer APIs" into main

parents b9c5698d ffef7e77
Loading
Loading
Loading
Loading
+14 −0
Original line number Original line Diff line number Diff line
@@ -54,6 +54,20 @@ class PreferenceHierarchy internal constructor(metadata: PreferenceMetadata) :
        children.add(PreferenceHierarchyNode(metadata))
        children.add(PreferenceHierarchyNode(metadata))
    }
    }


    /** Adds a preference to the hierarchy before a specific preference. */
    fun addBefore(key: String, metadata: PreferenceMetadata) {
        var foundIndex = children.indexOfFirst { it.metadata.key == key }
        if (foundIndex == -1) foundIndex = children.size
        children.add(foundIndex, PreferenceHierarchyNode(metadata))
    }

    /** Adds a preference to the hierarchy after a specific preference. */
    fun addAfter(key: String, metadata: PreferenceMetadata) {
        var foundIndex = children.indexOfFirst { it.metadata.key == key }
        if (foundIndex == -1) foundIndex = children.size else foundIndex++
        children.add(foundIndex, PreferenceHierarchyNode(metadata))
    }

    /** Adds a preference group to the hierarchy. */
    /** Adds a preference group to the hierarchy. */
    operator fun PreferenceGroup.unaryPlus() = PreferenceHierarchy(this).also { children.add(it) }
    operator fun PreferenceGroup.unaryPlus() = PreferenceHierarchy(this).also { children.add(it) }