Use consts in PreferencesFragment

Instead of duplicated string literals.
This commit is contained in:
Markus Fisch
2026-06-01 22:36:20 +02:00
parent 1ff170a279
commit 2035c935dc
@@ -46,16 +46,16 @@ class PreferencesFragment : PreferenceFragmentCompat() {
prefs.update()
}
when (preference.key) {
"custom_locale",
"dynamic_colors" -> {
CUSTOM_LOCALE,
DYNAMIC_COLORS -> {
activity?.restartApp()
return
}
"beep_tone_name",
"beep_stream_name" -> beepConfirm()
BEEP_TONE_NAME,
BEEP_STREAM_NAME -> activity?.beepConfirm()
"send_scan_bluetooth" -> if (
SEND_SCAN_BLUETOOTH -> if (
prefs.sendScanBluetooth &&
activity?.hasBluetoothPermission() == false
) {
@@ -135,14 +135,14 @@ class PreferencesFragment : PreferenceFragmentCompat() {
if (prefs.sendScanBluetooth &&
activity?.hasBluetoothPermission() == true
) {
findPreference<ListPreference>("send_scan_bluetooth_host")?.let {
findPreference<ListPreference>(SEND_SCAN_BLUETOOTH_HOST)?.let {
setBluetoothHosts(it)
}
}
}
private fun wireClearNetworkPreferences() {
findPreference<Preference>("clear_network_suggestions")?.apply {
findPreference<Preference>(CLEAR_NETWORK_SUGGESTIONS)?.apply {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {
// From R+ we can query past network suggestions and
// make them editable.
@@ -225,7 +225,7 @@ class PreferencesFragment : PreferenceFragmentCompat() {
setTargetFragment(this@PreferencesFragment, 0)
show(fm, null)
}
} else if (preference.key == "send_scan_bluetooth_host") {
} else if (preference.key == SEND_SCAN_BLUETOOTH_HOST) {
val ac = activity ?: return
if (ac.hasBluetoothPermission()) {
setBluetoothHosts(preference as ListPreference)
@@ -290,8 +290,8 @@ class PreferencesFragment : PreferenceFragmentCompat() {
setIcon("show_toast_in_bulk_mode", R.drawable.ic_action_toast)
setIcon("vibrate", R.drawable.ic_action_vibrate)
setIcon("beep", R.drawable.ic_action_beep)
setIcon("beep_tone_name", R.drawable.ic_action_notification_sound)
setIcon("beep_stream_name", R.drawable.ic_action_notification_sound)
setIcon(BEEP_TONE_NAME, R.drawable.ic_action_notification_sound)
setIcon(BEEP_STREAM_NAME, R.drawable.ic_action_notification_sound)
setIcon("use_history", R.drawable.ic_action_history)
setIcon("ignore_duplicates_name", R.drawable.ic_action_remove)
setIcon(IGNORE_CODES, R.drawable.ic_action_remove)
@@ -300,8 +300,8 @@ class PreferencesFragment : PreferenceFragmentCompat() {
setIcon("send_scan_url", R.drawable.ic_action_link)
setIcon("send_scan_type", R.drawable.ic_action_link)
setIcon("send_scan_device_id", R.drawable.ic_label)
setIcon("send_scan_bluetooth", R.drawable.ic_action_bluetooth)
setIcon("send_scan_bluetooth_host", R.drawable.ic_action_bluetooth)
setIcon(SEND_SCAN_BLUETOOTH, R.drawable.ic_action_bluetooth)
setIcon(SEND_SCAN_BLUETOOTH_HOST, R.drawable.ic_action_bluetooth)
setIcon("open_immediately", R.drawable.ic_action_open)
setIcon("strip_tracking_params", R.drawable.ic_action_remove)
setIcon("show_meta_data", R.drawable.ic_action_info)
@@ -312,10 +312,10 @@ class PreferencesFragment : PreferenceFragmentCompat() {
setIcon("default_search_url", R.drawable.ic_action_search)
setIcon("open_with_url", R.drawable.ic_action_link)
setIcon(AUTOMATED_ACTIONS, R.drawable.ic_action_create)
setIcon("clear_network_suggestions", R.drawable.ic_action_wifi)
setIcon(CLEAR_NETWORK_SUGGESTIONS, R.drawable.ic_action_wifi)
setIcon("brighten_screen", R.drawable.ic_action_bright)
setIcon("custom_locale", R.drawable.ic_action_preferences)
setIcon("dynamic_colors", R.drawable.ic_action_preferences)
setIcon(CUSTOM_LOCALE, R.drawable.ic_action_preferences)
setIcon(DYNAMIC_COLORS, R.drawable.ic_action_preferences)
}
private fun setIcon(key: String, iconResId: Int) {
@@ -356,7 +356,14 @@ class PreferencesFragment : PreferenceFragmentCompat() {
companion object {
private const val PROFILE = "profile"
private const val AUTOMATED_ACTIONS = "automated_actions"
private const val BEEP_TONE_NAME = "beep_tone_name"
private const val BEEP_STREAM_NAME = "beep_stream_name"
private const val CLEAR_NETWORK_SUGGESTIONS = "clear_network_suggestions"
private const val CUSTOM_LOCALE = "custom_locale"
private const val DYNAMIC_COLORS = "dynamic_colors"
private const val IGNORE_CODES = "ignore_codes"
private const val SEND_SCAN_BLUETOOTH = "send_scan_bluetooth"
private const val SEND_SCAN_BLUETOOTH_HOST = "send_scan_bluetooth_host"
}
}