From 6c0e20c68e40e9cc4b2a412e7f79a63d4a26119d Mon Sep 17 00:00:00 2001 From: Hardcore Sushi Date: Wed, 24 Jul 2024 17:31:36 +0200 Subject: [PATCH] Disable usfExpose when disabling usfBackground --- .../hardcore/droidfs/SettingsActivity.kt | 27 ++++++++++++------- .../droidfs/add_volume/SelectPathFragment.kt | 3 +-- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/sushi/hardcore/droidfs/SettingsActivity.kt b/app/src/main/java/sushi/hardcore/droidfs/SettingsActivity.kt index c10c3f4..79e6ece 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/SettingsActivity.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/SettingsActivity.kt @@ -177,25 +177,32 @@ class SettingsActivity : BaseActivity() { val switchExpose = findPreference("usf_expose")!! val switchSafWrite = findPreference("usf_saf_write")!! - fun updateView(usfOpen: Boolean? = null, usfBackground: Boolean? = null, usfExpose: Boolean? = null) { - val usfBackground = usfBackground ?: switchBackground.isChecked - switchKeepOpen.isEnabled = usfBackground - switchExpose.isEnabled = usfBackground - switchSafWrite.isEnabled = usfOpen ?: switchExternalOpen.isChecked || (usfBackground && usfExpose ?: switchExpose.isChecked) + fun onUsfBackgroundChanged(usfBackground: Boolean) { + fun updateSwitchPreference(switch: SwitchPreference) = with (switch) { + isChecked = isChecked && usfBackground + isEnabled = usfBackground + 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 -> - updateView(usfBackground = checked as Boolean) - switchKeepOpen.isChecked = switchKeepOpen.isChecked && checked + onUsfBackgroundChanged(checked as Boolean) true } switchExternalOpen.setOnPreferenceChangeListener { _, checked -> - updateView(usfOpen = checked as Boolean) + updateSafWrite(usfOpen = checked as Boolean) true } switchExpose.setOnPreferenceChangeListener { _, checked -> - updateView(usfExpose = checked as Boolean) + updateSafWrite(usfExpose = checked as Boolean) VolumeProvider.notifyRootsChanged(requireContext()) true } diff --git a/app/src/main/java/sushi/hardcore/droidfs/add_volume/SelectPathFragment.kt b/app/src/main/java/sushi/hardcore/droidfs/add_volume/SelectPathFragment.kt index 3c0a8ba..7810b96 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/add_volume/SelectPathFragment.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/add_volume/SelectPathFragment.kt @@ -258,9 +258,8 @@ class SelectPathFragment: Fragment() { .setPositiveButton(R.string.ok, null) .show() } else { - binding.editVolumeName.setText(path) inputViewModel.showEditText = true - updateUi(path) + binding.editVolumeName.setText(path) } }