From e53801957c30d286736aeb0ab18489adf5649b22 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Fri, 19 Feb 2021 13:36:39 +0000 Subject: [PATCH] Add subscribeToChanges/unsubscribeToChanges to VectorPreferences --- .../app/features/settings/VectorPreferences.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt b/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt index d3ef36a80b..a0fe525d3e 100755 --- a/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt +++ b/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt @@ -239,6 +239,20 @@ class VectorPreferences @Inject constructor(private val context: Context) { } private val defaultPrefs = DefaultSharedPreferences.getInstance(context) + + /** + * Allow subscribing and unsubscribing to configuration changes. This is + * particularly useful when you need to be notified of a configuration change + * in a background service, e.g. for the P2P demos. + */ + + public fun subscribeToChanges(listener: SharedPreferences.OnSharedPreferenceChangeListener) { + defaultPrefs.registerOnSharedPreferenceChangeListener(listener) + } + + public fun unsubscribeToChanges(listener: SharedPreferences.OnSharedPreferenceChangeListener) { + defaultPrefs.unregisterOnSharedPreferenceChangeListener(listener) + } /** * Clear the preferences.