From e53801957c30d286736aeb0ab18489adf5649b22 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Fri, 19 Feb 2021 13:36:39 +0000 Subject: [PATCH 1/3] 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. From adc461d2f3c28bf95957caba357995561b6e30b8 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Fri, 19 Feb 2021 14:23:38 +0000 Subject: [PATCH 2/3] Update VectorPreferences.kt --- .../im/vector/app/features/settings/VectorPreferences.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 a0fe525d3e..fbd53f09c5 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 @@ -16,6 +16,7 @@ package im.vector.app.features.settings import android.content.Context +import android.content.SharedPreferences import android.media.RingtoneManager import android.net.Uri import android.provider.MediaStore @@ -246,11 +247,11 @@ class VectorPreferences @Inject constructor(private val context: Context) { * in a background service, e.g. for the P2P demos. */ - public fun subscribeToChanges(listener: SharedPreferences.OnSharedPreferenceChangeListener) { + fun subscribeToChanges(listener: SharedPreferences.OnSharedPreferenceChangeListener) { defaultPrefs.registerOnSharedPreferenceChangeListener(listener) } - public fun unsubscribeToChanges(listener: SharedPreferences.OnSharedPreferenceChangeListener) { + fun unsubscribeToChanges(listener: SharedPreferences.OnSharedPreferenceChangeListener) { defaultPrefs.unregisterOnSharedPreferenceChangeListener(listener) } From 2b403371a3370b073908581ebb09d9528c045722 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Fri, 19 Feb 2021 15:17:42 +0000 Subject: [PATCH 3/3] Update VectorPreferences.kt --- .../java/im/vector/app/features/settings/VectorPreferences.kt | 2 -- 1 file changed, 2 deletions(-) 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 fbd53f09c5..eba7403a05 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 @@ -246,11 +246,9 @@ class VectorPreferences @Inject constructor(private val context: Context) { * particularly useful when you need to be notified of a configuration change * in a background service, e.g. for the P2P demos. */ - fun subscribeToChanges(listener: SharedPreferences.OnSharedPreferenceChangeListener) { defaultPrefs.registerOnSharedPreferenceChangeListener(listener) } - fun unsubscribeToChanges(listener: SharedPreferences.OnSharedPreferenceChangeListener) { defaultPrefs.unregisterOnSharedPreferenceChangeListener(listener) }