inline fun <reified T> Preference.setOnPreferenceChangeListener( crossinline onPreferenceChangeListener: (Preference, T) -> Boolean, ) { setOnPreferenceChangeListener { preference: Preference, newValue: Any -> (newValue as? T)?.let { onPreferenceChangeListener(preference, it) } ?: false } }
Sets the callback to be invoked when this preference is changed by the user (but before the internal state has been updated). Allows the type of the preference to be specified. If the new value doesn't match the preference type the listener isn't called.