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

Commit 5ddeabd3 authored by Jacky Wang's avatar Jacky Wang
Browse files

[Catalyst] Add PreferenceLifecycleContext.getKeyValueStore

The API allows to reuse existing KeyValueStore attached to the given
preference.

Bug: 332201912
Flag: EXEMPT library
Test: N/A
Change-Id: I14e1a2d26591163d0369a200b46fb7f017b51bb0
parent bfb0a089
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)