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

Commit 38ee74bd authored by Jacky Wang's avatar Jacky Wang Committed by Android (Google) Code Review
Browse files

Merge "[Catalyst] Add PreferenceLifecycleContext.getKeyValueStore" into main

parents 65146ab4 5ddeabd3
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.content.ContextWrapper
import android.content.Intent
import android.os.Bundle
import androidx.lifecycle.LifecycleCoroutineScope
import com.android.settingslib.datastore.KeyValueStore
import kotlinx.coroutines.CoroutineScope

/**
@@ -157,6 +158,9 @@ abstract class PreferenceLifecycleContext(context: Context) : ContextWrapper(con
     */
    abstract fun <T : Any> requirePreference(key: String): T

    /** Returns the [KeyValueStore] attached to the preference of given key *on the same screen*. */
    abstract fun getKeyValueStore(key: String): KeyValueStore?

    /** Notifies that preference state of given key is changed and updates preference widget UI. */
    abstract fun notifyPreferenceChange(key: String)

+5 −0
Original line number Diff line number Diff line
@@ -67,6 +67,11 @@ class PreferenceScreenBindingHelper(

            override fun <T : Any> requirePreference(key: String) = findPreference<T>(key)!!

            override fun getKeyValueStore(key: String) =
                (findPreference<Preference>(key)?.preferenceDataStore
                        as? PreferenceDataStoreAdapter)
                    ?.keyValueStore

            override fun notifyPreferenceChange(key: String) =
                notifyChange(key, CHANGE_REASON_STATE)