Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.devil.phoenixproject.data.preferences.SettingsPreferencesManager
import com.devil.phoenixproject.data.repository.ActiveProfileContext
import com.devil.phoenixproject.domain.model.ScalingBasis
import com.devil.phoenixproject.domain.model.UserPreferences
import com.devil.phoenixproject.domain.model.WeightTextScale
import com.devil.phoenixproject.domain.model.WeightUnit
import com.devil.phoenixproject.domain.model.WorkoutPreferences
import com.devil.phoenixproject.testutil.FakePreferencesManager
Expand Down Expand Up @@ -107,6 +108,32 @@ class SettingsManagerTest {
}
}

@Test
fun `weight text scale is global and survives profile preference overlay`() = runTest {
val managerScope = CoroutineScope(coroutineContext + SupervisorJob())
try {
val manager = SettingsManager(fakePreferencesManager, fakeProfileRepository, managerScope)

manager.setWeightTextScale(WeightTextScale.EXTRA_LARGE)
advanceUntilIdle()
assertEquals(WeightTextScale.EXTRA_LARGE, manager.userPreferences.value.weightTextScale)
assertEquals(WeightTextScale.EXTRA_LARGE, fakePreferencesManager.preferencesFlow.value.weightTextScale)

// A profile preference write re-runs overlayProfile; the global weight text
// size must ride through untouched (SD6: the field is not in overlayProfile).
val ready = readyProfile()
fakeProfileRepository.updateCore(
ready.profile.id,
ready.preferences.core.value.copy(weightUnit = WeightUnit.KG),
)
advanceUntilIdle()
assertEquals(WeightTextScale.EXTRA_LARGE, manager.userPreferences.value.weightTextScale)
assertEquals(WeightUnit.KG, manager.userPreferences.value.weightUnit, "overlay still applies")
} finally {
managerScope.cancel()
}
}

@Test
fun `routine exercise percent defaults are off and eighty percent`() = runTest {
val managerScope = CoroutineScope(coroutineContext + SupervisorJob())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.devil.phoenixproject.presentation.util

import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.test.junit4.createComposeRule
import com.devil.phoenixproject.domain.model.WeightTextScale
import org.junit.Assert.assertEquals
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import org.robolectric.annotation.GraphicsMode

/**
* Issue #1367 T12: `LocalWeightTextScale` defaults to STANDARD outside the app shell
* (previews and tests render unchanged base typography) and honors a provided value.
* Asserted through a real composition because `CompositionLocal.current` is @Composable.
*/
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [34], qualifiers = "w411dp-h891dp")
@GraphicsMode(GraphicsMode.Mode.NATIVE)
class LocalWeightTextScaleDefaultTest {

@get:Rule
val compose = createComposeRule()

@Test
fun defaultsToStandardOutsideProvider() {
var seen: WeightTextScale? = null
compose.setContent { seen = LocalWeightTextScale.current }
assertEquals(WeightTextScale.STANDARD, seen)
}

@Test
fun providerOverrideIsVisibleToTheShell() {
var seen: WeightTextScale? = null
compose.setContent {
CompositionLocalProvider(LocalWeightTextScale provides WeightTextScale.EXTRA_LARGE) {
seen = LocalWeightTextScale.current
}
}
assertEquals(WeightTextScale.EXTRA_LARGE, seen)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package com.devil.phoenixproject.presentation.util

import android.util.DisplayMetrics
import android.util.TypedValue
import com.devil.phoenixproject.domain.model.WeightTextScale
import kotlin.math.abs
import kotlin.test.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config

/**
* Issue #1367 T11 / SD1: prove the physical ceiling through the ACTUAL platform density
* converter (`TypedValue.applyDimension`), not through sp arithmetic.
*
* The contract: the style helper multiplies fontSize by M = E/O (E = min(A*O, 2)), so the
* rendered physical size is `base * E`, capped at [WEIGHT_TEXT_MAX_EFFECTIVE_SCALE] x base.
* The ceiling is asserted against the OS-1.0 physical base (`baseSp * density`) for both
* linear scaledDensity and Android's nonlinear large-font conversion
* (scaledDensity < density * fontScale), and a negative control proves the test would
* catch the uncapped `* A` regression the signoff warned about.
*/
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [34])
class WeightTextScaleAndroidConversionTest {

private fun spToPx(sp: Float, density: Float, scaledDensity: Float): Float {
val metrics = DisplayMetrics().apply {
this.density = density
this.scaledDensity = scaledDensity
}
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, metrics)
}

/** Android 14+ nonlinear font scaling: physical scale grows sub-linearly past ~1.0. */
private fun nonlinearScaledDensity(density: Float, fontScale: Float): Float =
if (fontScale > 1f) density * (1f + (fontScale - 1f) * 0.8f) else density * fontScale

@Test
fun physicalRenderedSizeNeverExceedsTwoXBaseThroughThePlatformConverter() {
val baseSp = 28f
val density = 1f
for (scale in WeightTextScale.entries) {
for (os in listOf(0.85f, 1f, 1.5f, 2f, 2.5f, 3f)) {
val profiles = listOf(
"linear" to density * os,
"nonlinear" to nonlinearScaledDensity(density, os),
)
for ((profile, scaledDensity) in profiles) {
val multiplier = weightTextMultiplier(scale.preferenceFactor, os)
val targetSp = baseSp * multiplier
val renderedPx = spToPx(targetSp, density, scaledDensity)
val ceilingPx = WEIGHT_TEXT_MAX_EFFECTIVE_SCALE * baseSp * density
assertTrue(
renderedPx <= ceilingPx + 0.001f,
"rendered ${renderedPx}px exceeds ceiling ${ceilingPx}px for $scale at OS $os ($profile)",
)
}
}
}
}

@Test
fun uncappedAppFactorWouldViolateTheCeiling_provingTheTestDiscriminates() {
// Negative control: the pre-signoff defect (style *= A, no rendered cap) renders
// base*A*O = 4x base at A=2/O=2 — this test MUST be able to fail.
val baseSp = 28f
val density = 1f
val os = 2f
val uncappedTargetSp = baseSp * WeightTextScale.EXTRA_LARGE.preferenceFactor
val renderedPx = spToPx(uncappedTargetSp, density, density * os)
val ceilingPx = WEIGHT_TEXT_MAX_EFFECTIVE_SCALE * baseSp * density
assertTrue(
renderedPx > ceilingPx + 0.001f,
"negative control: uncapped rendering unexpectedly within ceiling",
)
}

@Test
fun cappedTargetDerivedThroughTheConverterRoundTripsAndStaysBounded() {
// SD1: derive the capped target and the inverse conversion through the platform
// converter (px / scaledDensity), never assume sp division by fontScale.
val baseSp = 22f
val density = 1f
for (os in listOf(1f, 1.5f, 2f, 2.5f)) {
val scaledDensity = nonlinearScaledDensity(density, os)
for (scale in WeightTextScale.entries) {
val targetSp = baseSp * weightTextMultiplier(scale.preferenceFactor, os)
val targetPx = spToPx(targetSp, density, scaledDensity)
val recoveredSp = targetPx / scaledDensity
assertTrue(abs(recoveredSp - targetSp) < 0.001f, "inverse conversion drifted")
assertTrue(
recoveredSp * os <= baseSp * WEIGHT_TEXT_MAX_EFFECTIVE_SCALE + 0.001f ||
scaledDensity < density * os,
"capped target exceeds the linear-model ceiling at OS $os for $scale",
)
}
}
}
}
8 changes: 8 additions & 0 deletions shared/src/commonMain/composeResources/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,14 @@
<string name="intervals_reason_no_remote_match">Keine passende Aktivität gefunden</string>
<string name="intervals_reason_multiple_remote_matches">Mehr als eine passende Aktivität gefunden</string>
<string name="intervals_reason_suppressed_by_pause">Pausiert</string>
<!-- Issue #1367: Gewichtsschriftgröße -->
<string name="settings_weight_text_size">Gewichtsschriftgröße</string>
<string name="settings_weight_text_size_help_1">Vergrößert Gewichtswerte in Set-Vorbereitung, Routinenübersicht, Pause, Übungseinrichtung und Trainingsanzeigen. Just Lift bleibt in dieser ersten Version unverändert. Wird nur auf diesem Gerät gespeichert.</string>
<string name="settings_weight_text_size_help_2">Kombiniert sich mit der Schriftgröße deines Geräts, bis zu 2× der Standard-Basisschriftgröße. Die Optionen können bei größeren Geräteschriftgrößen gleich aussehen. Diese Grenze gilt auch für Standard, wenn die Geräteschriftgröße sie überschreitet.</string>
<string name="settings_weight_text_size_standard">Standard</string>
<string name="settings_weight_text_size_large">Groß</string>
<string name="settings_weight_text_size_extra_large">Sehr groß</string>
<string name="cd_weight_text_size">Gewichtsschriftgröße</string>
<!-- Issue #1358: custom-exercise photos (Phase 1) -->
<string name="media_photos_count">Fotos · %1$d von %2$d</string>
<string name="media_add_photos">Fotos hinzufügen</string>
Expand Down
8 changes: 8 additions & 0 deletions shared/src/commonMain/composeResources/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,14 @@
<string name="intervals_reason_no_remote_match">No se encontró una actividad coincidente</string>
<string name="intervals_reason_multiple_remote_matches">Se encontró más de una actividad coincidente</string>
<string name="intervals_reason_suppressed_by_pause">En pausa</string>
<!-- Issue #1367: Tamaño del texto del peso -->
<string name="settings_weight_text_size">Tamaño del texto del peso</string>
<string name="settings_weight_text_size_help_1">Amplía los valores de peso en Preparación de serie, Resumen de rutina, descanso, configuración de ejercicios y lecturas del entrenamiento. Just Lift no cambia en esta primera versión. Se guarda solo en este dispositivo.</string>
<string name="settings_weight_text_size_help_2">Se combina con el tamaño de texto del dispositivo, hasta 2× el tamaño base estándar. Las opciones pueden verse iguales con tamaños de texto del dispositivo más grandes. Este límite también se aplica a Estándar cuando el tamaño de texto del dispositivo lo supera.</string>
<string name="settings_weight_text_size_standard">Estándar</string>
<string name="settings_weight_text_size_large">Grande</string>
<string name="settings_weight_text_size_extra_large">Muy grande</string>
<string name="cd_weight_text_size">Tamaño del texto del peso</string>
<!-- Issue #1358: custom-exercise photos (Phase 1) -->
<string name="media_photos_count">Fotos · %1$d de %2$d</string>
<string name="media_add_photos">Añadir fotos</string>
Expand Down
8 changes: 8 additions & 0 deletions shared/src/commonMain/composeResources/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,14 @@
<string name="intervals_reason_no_remote_match">Aucune activité correspondante trouvée</string>
<string name="intervals_reason_multiple_remote_matches">Plusieurs activités correspondantes trouvées</string>
<string name="intervals_reason_suppressed_by_pause">En pause</string>
<!-- Issue #1367: Taille du texte des poids -->
<string name="settings_weight_text_size">Taille du texte des poids</string>
<string name="settings_weight_text_size_help_1">Agrandit les valeurs de poids dans Préparation de série, Aperçu de la routine, la pause, la configuration des exercices et les affichages d'entraînement. Just Lift reste inchangé dans cette première version. Enregistré sur cet appareil uniquement.</string>
<string name="settings_weight_text_size_help_2">Se combine avec la taille du texte de votre appareil, jusqu'à 2× la taille de base standard. Les options peuvent sembler identiques avec des tailles de texte plus grandes. Cette limite s'applique aussi à Standard lorsque la taille du texte de l'appareil la dépasse.</string>
<string name="settings_weight_text_size_standard">Standard</string>
<string name="settings_weight_text_size_large">Grand</string>
<string name="settings_weight_text_size_extra_large">Très grand</string>
<string name="cd_weight_text_size">Taille du texte des poids</string>
<!-- Issue #1358: custom-exercise photos (Phase 1) -->
<string name="media_photos_count">Photos · %1$d sur %2$d</string>
<string name="media_add_photos">Ajouter des photos</string>
Expand Down
8 changes: 8 additions & 0 deletions shared/src/commonMain/composeResources/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,14 @@
<string name="intervals_reason_no_remote_match">Nessuna attività corrispondente trovata</string>
<string name="intervals_reason_multiple_remote_matches">Trovata più di un'attività corrispondente</string>
<string name="intervals_reason_suppressed_by_pause">In pausa</string>
<!-- Issue #1367: Dimensione del testo del peso -->
<string name="settings_weight_text_size">Dimensione del testo del peso</string>
<string name="settings_weight_text_size_help_1">Ingrandisce i valori del peso in Preparazione serie, Panoramica routine, recupero, configurazione degli esercizi e letture dell'allenamento. Just Lift resta invariato in questa prima versione. Salvato solo su questo dispositivo.</string>
<string name="settings_weight_text_size_help_2">Si combina con la dimensione del testo del dispositivo, fino a 2× la dimensione base standard. Le opzioni possono apparire uguali con dimensioni del testo maggiori. Questo limite si applica anche a Standard quando la dimensione del testo del dispositivo lo supera.</string>
<string name="settings_weight_text_size_standard">Standard</string>
<string name="settings_weight_text_size_large">Grande</string>
<string name="settings_weight_text_size_extra_large">Molto grande</string>
<string name="cd_weight_text_size">Dimensione del testo del peso</string>
<!-- Issue #1358: custom-exercise photos (Phase 1) -->
<string name="media_photos_count">Foto · %1$d di %2$d</string>
<string name="media_add_photos">Aggiungi foto</string>
Expand Down
8 changes: 8 additions & 0 deletions shared/src/commonMain/composeResources/values-nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,14 @@
<string name="intervals_reason_no_remote_match">Geen overeenkomende activiteit gevonden</string>
<string name="intervals_reason_multiple_remote_matches">Meer dan één overeenkomende activiteit gevonden</string>
<string name="intervals_reason_suppressed_by_pause">Gepauzeerd</string>
<!-- Issue #1367: Grootte van gewichtstekst -->
<string name="settings_weight_text_size">Grootte van gewichtstekst</string>
<string name="settings_weight_text_size_help_1">Vergroot gewichtswaarden in Set-klaarzetten, Routineoverzicht, rust, oefening instellen en trainingsweergaven. Just Lift blijft in deze eerste versie ongewijzigd. Alleen op dit apparaat opgeslagen.</string>
<string name="settings_weight_text_size_help_2">Combineert met de tekstgrootte van je apparaat, tot 2× de standaard basisgrootte. Opties kunnen er hetzelfde uitzien bij grotere apparaattekstgroottes. Deze limiet geldt ook voor Standaard wanneer de apparaattekstgrootte deze overschrijdt.</string>
<string name="settings_weight_text_size_standard">Standaard</string>
<string name="settings_weight_text_size_large">Groot</string>
<string name="settings_weight_text_size_extra_large">Extra groot</string>
<string name="cd_weight_text_size">Grootte van gewichtstekst</string>
<!-- Issue #1358: custom-exercise photos (Phase 1) -->
<string name="media_photos_count">Foto's · %1$d van %2$d</string>
<string name="media_add_photos">Foto's toevoegen</string>
Expand Down
8 changes: 8 additions & 0 deletions shared/src/commonMain/composeResources/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,14 @@
<string name="intervals_reason_no_remote_match">No matching activity found</string>
<string name="intervals_reason_multiple_remote_matches">More than one matching activity found</string>
<string name="intervals_reason_suppressed_by_pause">Paused</string>
<!-- Issue #1367: Weight text size preference. Help copy is signoff-verbatim (SD8). -->
<string name="settings_weight_text_size">Weight text size</string>
<string name="settings_weight_text_size_help_1">Enlarges weight values in Set Ready, Routine Overview, rest, exercise setup and workout readouts. Just Lift is unchanged in this first version. Saved on this device only.</string>
<string name="settings_weight_text_size_help_2">Combines with your device text size, up to 2× the standard base size. Options may look the same at larger device text sizes. This limit also applies to Standard when your device text size exceeds it.</string>
<string name="settings_weight_text_size_standard">Standard</string>
<string name="settings_weight_text_size_large">Large</string>
<string name="settings_weight_text_size_extra_large">Extra large</string>
<string name="cd_weight_text_size">Weight text size</string>
<!-- Issue #1358: custom-exercise photos (Phase 1) -->
<string name="media_photos_count">Photos · %1$d of %2$d</string>
<string name="media_add_photos">Add photos</string>
Expand Down
Loading
Loading