Android: Remove all uses of Any from SliderSetting

This makes casting unnecessary, preventing the kind of type error we
just had from occurring in the future.
This commit is contained in:
JosJuice 2023-09-02 10:05:42 +02:00
parent e6138d7683
commit 1c47c510cd
5 changed files with 32 additions and 43 deletions

View File

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

View File

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

View File

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

View File

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

View File

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