refactor: strong preference key constraint (#128)
Some checks failed
/ build-debug (push) Has been cancelled
Some checks failed
/ build-debug (push) Has been cancelled
Reviewed-on: #128 Co-authored-by: septs <github@septs.pw> Co-committed-by: septs <github@septs.pw>
This commit is contained in:
parent
087c760010
commit
9596b8632c
2 changed files with 24 additions and 21 deletions
|
@ -29,7 +29,7 @@ open class SettingsFragment: PreferenceFragmentCompat() {
|
|||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
setPreferencesFromResource(R.xml.pref_settings, rootKey)
|
||||
|
||||
developerPref = findPreference("pref_developer")!!
|
||||
developerPref = requirePreference("pref_developer")
|
||||
|
||||
// Show / hide developer preference based on whether it is enabled
|
||||
lifecycleScope.launch {
|
||||
|
@ -38,14 +38,14 @@ open class SettingsFragment: PreferenceFragmentCompat() {
|
|||
.collect()
|
||||
}
|
||||
|
||||
findPreference<Preference>("pref_info_app_version")?.apply {
|
||||
requirePreference<Preference>("pref_info_app_version").apply {
|
||||
summary = requireContext().selfAppVersion
|
||||
|
||||
// Enable developer options when this is clicked for 7 times
|
||||
setOnPreferenceClickListener(::onAppVersionClicked)
|
||||
}
|
||||
|
||||
findPreference<Preference>("pref_advanced_language")?.apply {
|
||||
requirePreference<Preference>("pref_advanced_language").apply {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) return@apply
|
||||
isVisible = true
|
||||
intent = Intent(Settings.ACTION_APP_LOCALE_SETTINGS).apply {
|
||||
|
@ -53,32 +53,35 @@ open class SettingsFragment: PreferenceFragmentCompat() {
|
|||
}
|
||||
}
|
||||
|
||||
findPreference<Preference>("pref_advanced_logs")?.apply {
|
||||
requirePreference<Preference>("pref_advanced_logs").apply {
|
||||
intent = Intent(requireContext(), LogsActivity::class.java)
|
||||
}
|
||||
|
||||
findPreference<CheckBoxPreference>("pref_notifications_download")
|
||||
?.bindBooleanFlow(preferenceRepository.notificationDownloadFlow)
|
||||
requirePreference<CheckBoxPreference>("pref_notifications_download")
|
||||
.bindBooleanFlow(preferenceRepository.notificationDownloadFlow)
|
||||
|
||||
findPreference<CheckBoxPreference>("pref_notifications_delete")
|
||||
?.bindBooleanFlow(preferenceRepository.notificationDeleteFlow)
|
||||
requirePreference<CheckBoxPreference>("pref_notifications_delete")
|
||||
.bindBooleanFlow(preferenceRepository.notificationDeleteFlow)
|
||||
|
||||
findPreference<CheckBoxPreference>("pref_notifications_switch")
|
||||
?.bindBooleanFlow(preferenceRepository.notificationSwitchFlow)
|
||||
requirePreference<CheckBoxPreference>("pref_notifications_switch")
|
||||
.bindBooleanFlow(preferenceRepository.notificationSwitchFlow)
|
||||
|
||||
findPreference<CheckBoxPreference>("pref_advanced_disable_safeguard_removable_esim")
|
||||
?.bindBooleanFlow(preferenceRepository.disableSafeguardFlow)
|
||||
requirePreference<CheckBoxPreference>("pref_advanced_disable_safeguard_removable_esim")
|
||||
.bindBooleanFlow(preferenceRepository.disableSafeguardFlow)
|
||||
|
||||
findPreference<CheckBoxPreference>("pref_advanced_verbose_logging")
|
||||
?.bindBooleanFlow(preferenceRepository.verboseLoggingFlow)
|
||||
requirePreference<CheckBoxPreference>("pref_advanced_verbose_logging")
|
||||
.bindBooleanFlow(preferenceRepository.verboseLoggingFlow)
|
||||
|
||||
findPreference<CheckBoxPreference>("pref_developer_unfiltered_profile_list")
|
||||
?.bindBooleanFlow(preferenceRepository.unfilteredProfileListFlow)
|
||||
requirePreference<CheckBoxPreference>("pref_developer_unfiltered_profile_list")
|
||||
.bindBooleanFlow(preferenceRepository.unfilteredProfileListFlow)
|
||||
|
||||
findPreference<CheckBoxPreference>("pref_ignore_tls_certificate")
|
||||
?.bindBooleanFlow(preferenceRepository.ignoreTLSCertificateFlow)
|
||||
requirePreference<CheckBoxPreference>("pref_developer_ignore_tls_certificate")
|
||||
.bindBooleanFlow(preferenceRepository.ignoreTLSCertificateFlow)
|
||||
}
|
||||
|
||||
protected fun <T : Preference> requirePreference(key: CharSequence) =
|
||||
findPreference<T>(key)!!
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
setupRootViewInsets(requireView().requireViewById(R.id.recycler_view))
|
||||
|
@ -133,8 +136,8 @@ open class SettingsFragment: PreferenceFragmentCompat() {
|
|||
}
|
||||
|
||||
protected fun mergePreferenceOverlay(overlayKey: String, targetKey: String) {
|
||||
val overlayCat = findPreference<PreferenceCategory>(overlayKey)!!
|
||||
val targetCat = findPreference<PreferenceCategory>(targetKey)!!
|
||||
val overlayCat = requirePreference<PreferenceCategory>(overlayKey)
|
||||
val targetCat = requirePreference<PreferenceCategory>(targetKey)
|
||||
|
||||
val prefs = buildList {
|
||||
for (i in 0..<overlayCat.preferenceCount) {
|
||||
|
|
|
@ -31,7 +31,7 @@ class UnprivilegedSettingsFragment : SettingsFragment() {
|
|||
addPreferencesFromResource(R.xml.pref_unprivileged_settings)
|
||||
mergePreferenceOverlay("pref_info_overlay", "pref_info")
|
||||
|
||||
findPreference<Preference>("pref_info_ara_m")?.apply {
|
||||
requirePreference<Preference>("pref_info_ara_m").apply {
|
||||
summary = firstSigner.encodeHex()
|
||||
setOnPreferenceClickListener {
|
||||
requireContext().getSystemService(ClipboardManager::class.java)!!
|
||||
|
|
Loading…
Reference in a new issue