Initialize LivePref lazily
It avoids unnecessary observer registrations.
This commit is contained in:
parent
e3e4e86305
commit
5bc110479b
1 changed files with 8 additions and 3 deletions
|
|
@ -104,9 +104,14 @@ class AppPreferences(context: Context) {
|
|||
updateValue()
|
||||
}
|
||||
|
||||
init {
|
||||
updateValue() //Initial load
|
||||
prefs.registerOnSharedPreferenceChangeListener(prefChangeListener)
|
||||
private var initialized = false
|
||||
|
||||
override fun onActive() {
|
||||
if (!initialized) {
|
||||
initialized = true
|
||||
updateValue()
|
||||
prefs.registerOnSharedPreferenceChangeListener(prefChangeListener)
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateValue() {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue