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 9fc496a914..23cc3c30bd 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 @@ -252,6 +253,18 @@ 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. + */ + fun subscribeToChanges(listener: SharedPreferences.OnSharedPreferenceChangeListener) { + defaultPrefs.registerOnSharedPreferenceChangeListener(listener) + } + fun unsubscribeToChanges(listener: SharedPreferences.OnSharedPreferenceChangeListener) { + defaultPrefs.unregisterOnSharedPreferenceChangeListener(listener) + } /** * Clear the preferences.