settings: snap the preamp to its grid and drop a duplicate header

Review follow-ups.

- Remove the second "Playback" section header the rows were added
  under; the section already had one, so the screen rendered it twice.
- Snap the preamp to the 0.5 dB grid in the dialog. Material's slider
  snaps in pixel space and converts back, so the value it reports is near
  the configured grid but not on it: -1.0 dB arrives as -0.99999905, was
  displayed verbatim and was stored that way until the next drag. The
  step count is now derived from the range rather than hardcoded.
- Format the decibel value with the resource locale so translated
  layouts get their own decimal separator.
- The controls move to `ReplayGainControls.kt`, since the file now holds
  the grid as well as the labels, and the snap is covered by a test that
  reproduces the off-grid value without it.
This commit is contained in:
austinried
2026-10-16 13:07:11 +00:00
parent 229d6de4c6
commit 0b4e1d18bc
4 changed files with 58 additions and 29 deletions
@@ -3,13 +3,15 @@ package com.subtracks.ui.settings
import android.content.Context
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.subtracks.data.prefs.MAX_REPLAY_GAIN_PREAMP_DB
import com.subtracks.data.prefs.MIN_REPLAY_GAIN_PREAMP_DB
import com.subtracks.data.prefs.ReplayGainMode
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class ReplayGainLabelsTest {
class ReplayGainControlsTest {
private val resources = ApplicationProvider.getApplicationContext<Context>().resources
@Test
@@ -25,4 +27,20 @@ class ReplayGainLabelsTest {
assertEquals("-2.5 dB", replayGainPreampLabel(resources, -2.5f))
assertEquals("0.0 dB", replayGainPreampLabel(resources, 0f))
}
@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)
}
@Test
fun thePreampSnapsBackOntoTheHalfDecibelGrid() {
assertEquals(0f, snapReplayGainPreampDb(-0f), 0f)
assertEquals(-1f, snapReplayGainPreampDb(-0.99999905f), 0f)
assertEquals(-3f, snapReplayGainPreampDb(-3.000001f), 0f)
assertEquals(14.5f, snapReplayGainPreampDb(14.6f), 0f)
assertEquals(MAX_REPLAY_GAIN_PREAMP_DB, snapReplayGainPreampDb(14.9f), 0f)
assertEquals(MIN_REPLAY_GAIN_PREAMP_DB, snapReplayGainPreampDb(-14.9f), 0f)
}
}