You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iceraven-browser/app/src/main/java/org/mozilla/fenix/settings/SharedPreferenceUpdater.kt

21 lines
703 B
Kotlin

package org.mozilla.fenix.settings
import androidx.core.content.edit
import androidx.preference.Preference
import org.mozilla.fenix.ext.settings
/**
* Updates the corresponding [android.content.SharedPreferences] when the boolean [Preference] is changed.
* The preference key is used as the shared preference key.
*/
open class SharedPreferenceUpdater : Preference.OnPreferenceChangeListener {
override fun onPreferenceChange(preference: Preference, newValue: Any?): Boolean {
val newBooleanValue = newValue as? Boolean ?: return false
preference.context.settings.preferences.edit {
putBoolean(preference.key, newBooleanValue)
}
return true
}
}