Skip to content

Commit

Permalink
Adjust item order
Browse files Browse the repository at this point in the history
  • Loading branch information
CrazyBoyFeng committed Mar 17, 2022
1 parent ab60b45 commit fcae399
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))!!
Expand All @@ -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()
Expand Down Expand Up @@ -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() {
Expand All @@ -201,8 +195,7 @@ class ConfigFragment : PreferenceFragmentCompat() {
} else {
pauseCapacity.maxValue = 100
onShutdownCapacitySet()
onResumeCapacitySet()
onCooldownCapacitySet()
onMiddleCapacitySet()
onPauseCapacitySet()
}
}
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/xml/config_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
app:dialogMessage="@string/hint_capacity_shutdown"
app:key="@string/set_shutdown_capacity"
app:title="@string/shutdown_below" />
<NumberPickerPreference
app:key="@string/set_resume_capacity"
app:title="@string/charge_below" />
<NumberPickerPreference
app:dialogMessage="@string/hint_cooldown"
app:key="@string/set_cooldown_capacity"
app:title="@string/cooldown_above" />
<NumberPickerPreference
app:key="@string/set_resume_capacity"
app:title="@string/charge_below" />
<NumberPickerPreference
app:key="@string/set_pause_capacity"
app:title="@string/pause_above" />
Expand Down

0 comments on commit fcae399

Please sign in to comment.