Merge pull request #12151 from JosJuice/android-controller-float

Android: Fix controller float sliders crashing
This commit is contained in:
JosJuice 2023-09-03 17:38:42 +02:00 committed by GitHub
commit 57b1bd2b1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 34 additions and 41 deletions

View File

@ -10,7 +10,11 @@ import java.math.BigDecimal
import java.math.MathContext import java.math.MathContext
open class FloatSliderSetting : SliderSetting { open class FloatSliderSetting : SliderSetting {
var floatSetting: AbstractFloatSetting protected val floatSetting: AbstractFloatSetting
val min: Float
val max: Float
val stepSize: Float
override val setting: AbstractSetting override val setting: AbstractSetting
get() = floatSetting get() = floatSetting
@ -25,8 +29,11 @@ open class FloatSliderSetting : SliderSetting {
units: String?, units: String?,
stepSize: Float, stepSize: Float,
showDecimal: Boolean showDecimal: Boolean
) : super(context, titleId, descriptionId, min, max, units, stepSize, showDecimal) { ) : super(context, titleId, descriptionId, units, showDecimal) {
floatSetting = setting floatSetting = setting
this.min = min
this.max = max
this.stepSize = stepSize
} }
constructor( constructor(
@ -36,12 +43,16 @@ open class FloatSliderSetting : SliderSetting {
min: Float, min: Float,
max: Float, max: Float,
units: String?, units: String?,
stepSize: Float,
showDecimal: Boolean showDecimal: Boolean
) : super(name, description, min, max, units, showDecimal) { ) : super(name, description, units, showDecimal) {
floatSetting = setting floatSetting = setting
this.min = min
this.max = max
this.stepSize = stepSize
} }
override val selectedValue: Float open val selectedValue: Float
get() = floatSetting.float get() = floatSetting.float
open fun setSelectedValue(settings: Settings?, selection: Float) { open fun setSelectedValue(settings: Settings?, selection: Float) {

View File

@ -12,15 +12,16 @@ class IntSliderSetting(
private val intSetting: AbstractIntSetting, private val intSetting: AbstractIntSetting,
titleId: Int, titleId: Int,
descriptionId: Int, descriptionId: Int,
min: Int, val min: Int,
max: Int, val max: Int,
units: String?, units: String?,
stepSize: Int val stepSize: Int
) : SliderSetting(context, titleId, descriptionId, min, max, units, stepSize, false) { ) : SliderSetting(context, titleId, descriptionId, units, false) {
override val setting: AbstractSetting override val setting: AbstractSetting
get() = intSetting get() = intSetting
override val selectedValue: Int val selectedValue: Int
get() = intSetting.int get() = intSetting.int
fun setSelectedValue(settings: Settings?, selection: Int) { fun setSelectedValue(settings: Settings?, selection: Int) {

View File

@ -7,47 +7,27 @@ import android.content.Context
sealed class SliderSetting : SettingsItem { sealed class SliderSetting : SettingsItem {
override val type: Int = TYPE_SLIDER override val type: Int = TYPE_SLIDER
var min: Any val units: String?
private set val showDecimal: Boolean
var max: Any
private set
var units: String?
private set
var stepSize: Any = 0
private set
var showDecimal: Boolean = false
private set
constructor( constructor(
context: Context, context: Context,
nameId: Int, nameId: Int,
descriptionId: Int, descriptionId: Int,
min: Any,
max: Any,
units: String?, units: String?,
stepSize: Any,
showDecimal: Boolean showDecimal: Boolean
) : super(context, nameId, descriptionId) { ) : super(context, nameId, descriptionId) {
this.min = min
this.max = max
this.units = units this.units = units
this.stepSize = stepSize
this.showDecimal = showDecimal this.showDecimal = showDecimal
} }
constructor( constructor(
name: CharSequence, name: CharSequence,
description: CharSequence?, description: CharSequence?,
min: Any,
max: Any,
units: String?, units: String?,
showDecimal: Boolean showDecimal: Boolean
) : super(name, description) { ) : super(name, description) {
this.min = min
this.max = max
this.units = units this.units = units
this.showDecimal = showDecimal this.showDecimal = showDecimal
} }
abstract val selectedValue: Any
} }

View File

@ -249,14 +249,14 @@ class SettingsAdapter(
val slider = binding.slider val slider = binding.slider
when (item) { when (item) {
is FloatSliderSetting -> { is FloatSliderSetting -> {
slider.valueFrom = item.min as Float slider.valueFrom = item.min
slider.valueTo = item.max as Float slider.valueTo = item.max
slider.stepSize = item.stepSize as Float slider.stepSize = item.stepSize
} }
is IntSliderSetting -> { is IntSliderSetting -> {
slider.valueFrom = (item.min as Int).toFloat() slider.valueFrom = item.min.toFloat()
slider.valueTo = (item.max as Int).toFloat() slider.valueTo = item.max.toFloat()
slider.stepSize = (item.stepSize as Int).toFloat() slider.stepSize = item.stepSize.toFloat()
} }
} }
slider.value = seekbarProgress slider.value = seekbarProgress

View File

@ -2356,6 +2356,7 @@ class SettingsFragmentPresenter(
ceil(setting.getDoubleMin()).toFloat(), ceil(setting.getDoubleMin()).toFloat(),
floor(setting.getDoubleMax()).toFloat(), floor(setting.getDoubleMax()).toFloat(),
setting.getUiSuffix(), setting.getUiSuffix(),
1.0f,
false false
) )
) )

View File

@ -7,6 +7,7 @@ import android.text.TextUtils
import android.view.View import android.view.View
import org.dolphinemu.dolphinemu.R import org.dolphinemu.dolphinemu.R
import org.dolphinemu.dolphinemu.databinding.ListItemSettingBinding import org.dolphinemu.dolphinemu.databinding.ListItemSettingBinding
import org.dolphinemu.dolphinemu.features.settings.model.view.FloatSliderSetting
import org.dolphinemu.dolphinemu.features.settings.model.view.IntSliderSetting import org.dolphinemu.dolphinemu.features.settings.model.view.IntSliderSetting
import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem
import org.dolphinemu.dolphinemu.features.settings.model.view.SliderSetting import org.dolphinemu.dolphinemu.features.settings.model.view.SliderSetting
@ -29,10 +30,9 @@ class SliderViewHolder(
if (!TextUtils.isEmpty(item.description)) { if (!TextUtils.isEmpty(item.description)) {
binding.textSettingDescription.text = item.description binding.textSettingDescription.text = item.description
} else { } else {
val selectedValue: Float = if (item is IntSliderSetting) { val selectedValue: Float = when (item) {
(setting.selectedValue as Int).toFloat() is FloatSliderSetting -> item.selectedValue
} else { is IntSliderSetting -> item.selectedValue.toFloat()
setting.selectedValue as Float
} }
if (setting.showDecimal) { if (setting.showDecimal) {