diff --git a/app/src/main/kotlin/crazyboyfeng/accSettings/fragment/ConfigFragment.kt b/app/src/main/kotlin/crazyboyfeng/accSettings/fragment/ConfigFragment.kt index c4ab60f..e9366c6 100644 --- a/app/src/main/kotlin/crazyboyfeng/accSettings/fragment/ConfigFragment.kt +++ b/app/src/main/kotlin/crazyboyfeng/accSettings/fragment/ConfigFragment.kt @@ -38,8 +38,8 @@ class ConfigFragment : PreferenceFragmentCompat() { setPreferencesFromResource(R.xml.config_preferences, rootKey) shutdownCapacity = findPreference(getString(R.string.set_shutdown_capacity))!! - resumeCapacity = findPreference(getString(R.string.set_resume_capacity))!! cooldownCapacity = findPreference(getString(R.string.set_cooldown_capacity))!! + resumeCapacity = findPreference(getString(R.string.set_resume_capacity))!! pauseCapacity = findPreference(getString(R.string.set_pause_capacity))!! capacityMask = findPreference(getString(R.string.set_capacity_mask))!! supportInVoltage = findPreference(getString(R.string.support_in_voltage))!! @@ -57,8 +57,8 @@ class ConfigFragment : PreferenceFragmentCompat() { configDataStore.onConfigChangeListener = ConfigDataStore.OnConfigChangeListener { when (it) { shutdownCapacity.key -> onShutdownCapacitySet() - resumeCapacity.key -> onResumeCapacitySet() - cooldownCapacity.key -> onCooldownCapacitySet() + cooldownCapacity.key -> onMiddleCapacitySet() + resumeCapacity.key -> onMiddleCapacitySet() pauseCapacity.key -> onPauseCapacitySet() supportInVoltage.key -> onSupportInVoltageSet() cooldownTemp.key -> onCooldownTempSet() @@ -161,22 +161,16 @@ class ConfigFragment : PreferenceFragmentCompat() { resumeCapacity.minValue = value + 1 } - private fun onResumeCapacitySet() { - if (capacitiesInVoltage()) { - return - } - val value = resumeCapacity.value - shutdownCapacity.maxValue = value - 1 - cooldownCapacity.minValue = value + 1 - } - - private fun onCooldownCapacitySet() { + private fun onMiddleCapacitySet() { if (capacitiesInVoltage()) { return } - val value = cooldownCapacity.value - resumeCapacity.maxValue = value - 1 - pauseCapacity.minValue = value + 1 + val cooldownCapacityValue = cooldownCapacity.value + val resumeCapacityValue = resumeCapacity.value + shutdownCapacity.maxValue = + (if (cooldownCapacityValue < resumeCapacityValue) cooldownCapacityValue else resumeCapacityValue) - 1 + pauseCapacity.minValue = + (if (cooldownCapacityValue > resumeCapacityValue) cooldownCapacityValue else resumeCapacityValue) + 1 } private fun onPauseCapacitySet() { @@ -201,8 +195,7 @@ class ConfigFragment : PreferenceFragmentCompat() { } else { pauseCapacity.maxValue = 100 onShutdownCapacitySet() - onResumeCapacitySet() - onCooldownCapacitySet() + onMiddleCapacitySet() onPauseCapacitySet() } } diff --git a/app/src/main/res/xml/config_preferences.xml b/app/src/main/res/xml/config_preferences.xml index cecb858..670e0a8 100644 --- a/app/src/main/res/xml/config_preferences.xml +++ b/app/src/main/res/xml/config_preferences.xml @@ -9,13 +9,13 @@ app:dialogMessage="@string/hint_capacity_shutdown" app:key="@string/set_shutdown_capacity" app:title="@string/shutdown_below" /> - +