Merge pull request #2848 from vector-im/neilalexander/vectorpreferences

Add subscribeToChanges/unsubscribeToChanges to VectorPreferences
This commit is contained in:
Benoit Marty 2021-07-05 16:22:43 +02:00 committed by GitHub
commit 97cae9926b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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.