From ab4f4c62ee6efd505e5d54121c7646ff07f9345a Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sun, 10 Dec 2023 10:49:16 +0100 Subject: [PATCH] Android: Fix crash when trying to edit gate size setting The gate size is 79.37125 by default, and the step size is 0.5. Android throws an exception if we try to show the slider with the value set to something that isn't divisible by the step size. To avoid this problem, round the value. --- .../features/settings/model/view/FloatSliderSetting.kt | 5 +---- .../dolphinemu/features/settings/ui/SettingsAdapter.kt | 3 ++- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/FloatSliderSetting.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/FloatSliderSetting.kt index 34d0b0eb00..8a193afc6a 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/FloatSliderSetting.kt +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/FloatSliderSetting.kt @@ -56,9 +56,6 @@ open class FloatSliderSetting : SliderSetting { get() = floatSetting.float open fun setSelectedValue(settings: Settings, selection: Float) { - floatSetting.setFloat( - settings, - BigDecimal((selection).toDouble()).round(MathContext(3)).toFloat() - ) + floatSetting.setFloat(settings, selection) } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.kt index 0d2b8786b0..bcf68e67ec 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.kt +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.kt @@ -41,6 +41,7 @@ import java.io.File import java.io.IOException import java.io.RandomAccessFile import java.util.* +import kotlin.math.roundToInt class SettingsAdapter( private val fragmentView: SettingsFragmentView, @@ -259,7 +260,7 @@ class SettingsAdapter( slider.stepSize = item.stepSize.toFloat() } } - slider.value = seekbarProgress + slider.value = (seekbarProgress / slider.stepSize).roundToInt() * slider.stepSize slider.addOnChangeListener(this) dialog = MaterialAlertDialogBuilder(fragmentView.fragmentActivity)