Add subscribeToChanges/unsubscribeToChanges to VectorPreferences

This commit is contained in:
Neil Alexander 2021-02-19 13:36:39 +00:00 committed by GitHub
parent 9614d55612
commit e53801957c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -240,6 +240,20 @@ class VectorPreferences @Inject constructor(private val context: Context) {
private val defaultPrefs = DefaultSharedPreferences.getInstance(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. * Clear the preferences.
*/ */