Disable usfExpose when disabling usfBackground

This commit is contained in:
Matéo Duparc 2024-07-24 17:31:36 +02:00
parent e9b67bd9c4
commit 6c0e20c68e
Signed by: hardcoresushi
GPG Key ID: AFE384344A45E13A
2 changed files with 18 additions and 12 deletions

View File

@ -177,25 +177,32 @@ class SettingsActivity : BaseActivity() {
val switchExpose = findPreference<SwitchPreference>("usf_expose")!! val switchExpose = findPreference<SwitchPreference>("usf_expose")!!
val switchSafWrite = findPreference<SwitchPreference>("usf_saf_write")!! val switchSafWrite = findPreference<SwitchPreference>("usf_saf_write")!!
fun updateView(usfOpen: Boolean? = null, usfBackground: Boolean? = null, usfExpose: Boolean? = null) { fun onUsfBackgroundChanged(usfBackground: Boolean) {
val usfBackground = usfBackground ?: switchBackground.isChecked fun updateSwitchPreference(switch: SwitchPreference) = with (switch) {
switchKeepOpen.isEnabled = usfBackground isChecked = isChecked && usfBackground
switchExpose.isEnabled = usfBackground isEnabled = usfBackground
switchSafWrite.isEnabled = usfOpen ?: switchExternalOpen.isChecked || (usfBackground && usfExpose ?: switchExpose.isChecked) onPreferenceChangeListener?.onPreferenceChange(switch, isChecked)
}
updateSwitchPreference(switchKeepOpen)
updateSwitchPreference(switchExpose)
} }
onUsfBackgroundChanged(switchBackground.isChecked)
fun updateSafWrite(usfOpen: Boolean? = null, usfExpose: Boolean? = null) {
switchSafWrite.isEnabled = usfOpen ?: switchExternalOpen.isChecked || usfExpose ?: switchExpose.isChecked
}
updateSafWrite()
updateView()
switchBackground.setOnPreferenceChangeListener { _, checked -> switchBackground.setOnPreferenceChangeListener { _, checked ->
updateView(usfBackground = checked as Boolean) onUsfBackgroundChanged(checked as Boolean)
switchKeepOpen.isChecked = switchKeepOpen.isChecked && checked
true true
} }
switchExternalOpen.setOnPreferenceChangeListener { _, checked -> switchExternalOpen.setOnPreferenceChangeListener { _, checked ->
updateView(usfOpen = checked as Boolean) updateSafWrite(usfOpen = checked as Boolean)
true true
} }
switchExpose.setOnPreferenceChangeListener { _, checked -> switchExpose.setOnPreferenceChangeListener { _, checked ->
updateView(usfExpose = checked as Boolean) updateSafWrite(usfExpose = checked as Boolean)
VolumeProvider.notifyRootsChanged(requireContext()) VolumeProvider.notifyRootsChanged(requireContext())
true true
} }

View File

@ -258,9 +258,8 @@ class SelectPathFragment: Fragment() {
.setPositiveButton(R.string.ok, null) .setPositiveButton(R.string.ok, null)
.show() .show()
} else { } else {
binding.editVolumeName.setText(path)
inputViewModel.showEditText = true inputViewModel.showEditText = true
updateUi(path) binding.editVolumeName.setText(path)
} }
} }