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

Commit d047696a authored by Jacky Wang's avatar Jacky Wang
Browse files

[Catalyst] Add KeyedObservableDelegate and fix datastore binding issue

Bug: 374936314
Flag: EXEMPT library
Test: manual
Change-Id: I987b32efc607bb922d461cc257ebc142ed0c4958
parent 3f492ab2
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ import java.util.concurrent.Executor
 * Adapter of [Handler] and [Executor], where the task is executed on handler with given looper.
 *
 * When current looper is same with the given looper, task passed to [Executor.execute] will be
 * executed immediately to improve better performance.
 * executed immediately to achieve better performance.
 *
 * @param looper Looper of the handler.
 */
+4 −0
Original line number Diff line number Diff line
@@ -114,6 +114,10 @@ interface KeyedObservable<K> {
    fun notifyChange(key: K, reason: Int)
}

/** Delegation of [KeyedObservable]. */
open class KeyedObservableDelegate<K>(delegate: KeyedObservable<K>) :
    KeyedObservable<K> by delegate

/** A thread safe implementation of [KeyedObservable]. */
open class KeyedDataObservable<K> : KeyedObservable<K> {
    // Instead of @GuardedBy("this"), guarded by itself because KeyedDataObservable object could be
+2 −1
Original line number Diff line number Diff line
@@ -237,7 +237,8 @@ class PreferenceScreenBindingHelper(
                } else {
                    preferences[preference.key]?.let {
                        preferenceBindingFactory.bind(preference, it)
                        (it as? PersistentPreference<*>)?.storage(context)?.let { storage ->
                        val metadata = it.metadata
                        (metadata as? PersistentPreference<*>)?.storage(context)?.let { storage ->
                            preference.preferenceDataStore =
                                storages.getOrPut(storage) { PreferenceDataStoreAdapter(storage) }
                        }