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

Commit 30ac3aaa authored by Jacky Wang's avatar Jacky Wang
Browse files

[Catalyst] Add more callbacks to PreferenceFragment

Bug: 423781851
Flag: EXEMPT library
Test: manual
Change-Id: Ibff32f37d95402edf2db951a2b69031080fa2f27
parent 458aabf3
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -115,6 +115,7 @@ open class PreferenceFragment :
        fun createPreferenceScreenFromResource() =
            factory.inflate(getPreferenceScreenResId(context))?.also {
                Log.i(TAG, "Load screen " + it.key + " from resource")
                onPreferenceScreenCreatedFromResource(it)
            }

        val screenCreator =
@@ -153,6 +154,9 @@ open class PreferenceFragment :
        return preferenceScreen
    }

    /** Callbacks when the [PreferenceScreen] is just created from XML resource by catalyst. */
    protected open fun onPreferenceScreenCreatedFromResource(preferenceScreen: PreferenceScreen) {}

    internal fun newPreferenceHierarchy(
        context: Context,
        coroutineScope: CoroutineScope,
@@ -263,10 +267,15 @@ open class PreferenceFragment :
        preferenceScreenBindingHelper?.onActivityResult(requestCode, resultCode, data)
    }

    protected fun getPreferenceKeysInHierarchy(): Set<String> =
    /**
     * Returns the preference keys in the catalyst preference hierarchy.
     *
     * Note: async hierarchy is not included, subclass should override to add async preference keys.
     */
    protected open fun getPreferenceKeysInHierarchy(): MutableSet<String> =
        preferenceScreenBindingHelper?.let {
            mutableSetOf<String>().apply { it.forEachRecursively { add(it.metadata.bindingKey) } }
        } ?: setOf()
        } ?: mutableSetOf()

    companion object {
        private const val TAG = "PreferenceFragment"