From 8bcca2767d11144a53a865a5fcc61cdcb2260e12 Mon Sep 17 00:00:00 2001 From: austinried <4966622+austinried@users.noreply.github.com> Date: Fri, 16 Oct 2026 09:17:14 +0000 Subject: [PATCH] settings: clamp the preamp and make the dialog test assert Review follow-ups. - The snap clamped nothing, so an out-of-range stored value would show a decibel label the slider cannot reach: clamps now live in the snap rather than duplicated in the step. - The screenshot test only rendered the dialog without asserting it opened, so deleting the row's click would have left it passing while the capture showed the plain list. It now requires the dialog's Reset. - "Adjust level on top of the ReplayGain" was not grammatical, and the mode prompt claimed the server normalises when it only supplies the tags. - Drop a test assertion that restated the production formula. --- .../com/subtracks/ui/settings/ReplayGainControls.kt | 8 ++++---- app/src/main/res/values/strings.xml | 4 ++-- app/src/test/kotlin/com/subtracks/ui/AppScreenshotTest.kt | 1 + .../com/subtracks/ui/settings/ReplayGainControlsTest.kt | 7 ++++++- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/src/main/kotlin/com/subtracks/ui/settings/ReplayGainControls.kt b/app/src/main/kotlin/com/subtracks/ui/settings/ReplayGainControls.kt index fe43209d..393caa0f 100644 --- a/app/src/main/kotlin/com/subtracks/ui/settings/ReplayGainControls.kt +++ b/app/src/main/kotlin/com/subtracks/ui/settings/ReplayGainControls.kt @@ -15,14 +15,14 @@ internal val REPLAY_GAIN_PREAMP_STEPS = // Compose Material 3's Slider snaps in pixel space and converts back, so the value it reports is // near, but not on, the grid it was configured with (for example -0.99999905 for -1.0). Snap before // showing or storing it. -internal fun snapReplayGainPreampDb(value: Float): Float = (value / REPLAY_GAIN_PREAMP_STEP_DB).roundToInt() * REPLAY_GAIN_PREAMP_STEP_DB +internal fun snapReplayGainPreampDb(value: Float): Float = + ((value / REPLAY_GAIN_PREAMP_STEP_DB).roundToInt() * REPLAY_GAIN_PREAMP_STEP_DB) + .coerceIn(MIN_REPLAY_GAIN_PREAMP_DB, MAX_REPLAY_GAIN_PREAMP_DB) internal fun stepReplayGainPreampDb( value: Float, steps: Int, -): Float = - snapReplayGainPreampDb(value + steps * REPLAY_GAIN_PREAMP_STEP_DB) - .coerceIn(MIN_REPLAY_GAIN_PREAMP_DB, MAX_REPLAY_GAIN_PREAMP_DB) +): Float = snapReplayGainPreampDb(value + steps * REPLAY_GAIN_PREAMP_STEP_DB) internal fun replayGainModeLabel( resources: Resources, diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index be037408..469a461e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -79,11 +79,11 @@ Track gain Lower preamp Raise preamp - Adjust level on top of the ReplayGain + Extra level on top of ReplayGain Reset Preamp %1$s dB - Normalise loudness with the server\'s ReplayGain + Normalise loudness using the ReplayGain tags from the server ReplayGain Network Stream quality: Mobile diff --git a/app/src/test/kotlin/com/subtracks/ui/AppScreenshotTest.kt b/app/src/test/kotlin/com/subtracks/ui/AppScreenshotTest.kt index a6c6961e..3f0fce0e 100644 --- a/app/src/test/kotlin/com/subtracks/ui/AppScreenshotTest.kt +++ b/app/src/test/kotlin/com/subtracks/ui/AppScreenshotTest.kt @@ -355,6 +355,7 @@ class AppScreenshotTest { composeRule.onNode(hasScrollAction()).performScrollToNode(hasText("Preamp")) composeRule.onAllNodesWithText("Preamp")[0].performClick() composeRule.waitForIdle() + composeRule.onAllNodesWithText("Reset").assertCountEquals(1) composeRule.onRoot().captureRoboImage("src/test/screenshots/replay_gain_preamp.png") } diff --git a/app/src/test/kotlin/com/subtracks/ui/settings/ReplayGainControlsTest.kt b/app/src/test/kotlin/com/subtracks/ui/settings/ReplayGainControlsTest.kt index 5b08e816..b58e2250 100644 --- a/app/src/test/kotlin/com/subtracks/ui/settings/ReplayGainControlsTest.kt +++ b/app/src/test/kotlin/com/subtracks/ui/settings/ReplayGainControlsTest.kt @@ -30,7 +30,6 @@ class ReplayGainControlsTest { @Test fun theSliderHasOneStepPerHalfDecibel() { - assertEquals(60, ((MAX_REPLAY_GAIN_PREAMP_DB - MIN_REPLAY_GAIN_PREAMP_DB) / REPLAY_GAIN_PREAMP_STEP_DB).toInt()) assertEquals(59, REPLAY_GAIN_PREAMP_STEPS) } @@ -51,4 +50,10 @@ class ReplayGainControlsTest { assertEquals(MAX_REPLAY_GAIN_PREAMP_DB, snapReplayGainPreampDb(14.9f), 0f) assertEquals(MIN_REPLAY_GAIN_PREAMP_DB, snapReplayGainPreampDb(-14.9f), 0f) } + + @Test + fun thePreampIsClampedToItsRange() { + assertEquals(MAX_REPLAY_GAIN_PREAMP_DB, snapReplayGainPreampDb(20f), 0f) + assertEquals(MIN_REPLAY_GAIN_PREAMP_DB, snapReplayGainPreampDb(-20f), 0f) + } }