Skip to content

Commit

Permalink
Use a TextStyle instead of hardcoding a text size
Browse files Browse the repository at this point in the history
  • Loading branch information
MGaetan89 committed Aug 12, 2024
1 parent d66cce9 commit 2a32a0b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shadow
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.sp
import androidx.media3.common.Format
import ch.srgssr.pillarbox.demo.shared.ui.settings.MetricsOverlayOptions
import ch.srgssr.pillarbox.player.analytics.metrics.PlaybackMetrics
Expand Down Expand Up @@ -109,8 +107,7 @@ private fun OverlayText(
) {
BasicText(
modifier = modifier,
style = TextStyle.Default.copy(
fontSize = overlayOptions.textSize,
style = overlayOptions.textStyle.copy(
shadow = Shadow(
color = Color.Black,
blurRadius = 4f,
Expand All @@ -124,7 +121,7 @@ private fun OverlayText(
@Preview
@Composable
private fun OverlayTextPreview() {
val overlayOptions = MetricsOverlayOptions(textColor = Color.Yellow, textSize = 12.sp)
val overlayOptions = MetricsOverlayOptions()
OverlayText(text = "Text; 12 ac1.mp3 channels:4 colors:4", overlayOptions = overlayOptions)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
package ch.srgssr.pillarbox.demo.shared.ui.settings

import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.sp

/**
* App settings
Expand All @@ -23,13 +21,11 @@ class AppSettings(

/**
* Text size
*
* @property size the [TextUnit].
*/
enum class TextSize(val size: TextUnit) {
Small(12.sp),
Medium(14.sp),
Large(16.sp),
enum class TextSize {
Small,
Medium,
Large,
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
package ch.srgssr.pillarbox.demo.shared.ui.settings

import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.text.TextStyle

/**
* Metrics overlay options
*
* @property textColor The [Color] for the text overlay.
* @property textSize The [TextUnit] for the text overlay.
* @property textStyle The [TextStyle] for the text overlay.
*/

data class MetricsOverlayOptions(
val textColor: Color = Color.Yellow,
val textSize: TextUnit = TextUnit.Unspecified,
val textStyle: TextStyle = TextStyle.Default,
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.core.content.IntentCompat
import androidx.tv.material3.MaterialTheme
import ch.srgssr.pillarbox.demo.shared.data.DemoItem
import ch.srgssr.pillarbox.demo.shared.di.PlayerModule
import ch.srgssr.pillarbox.demo.shared.ui.settings.AppSettings
import ch.srgssr.pillarbox.demo.shared.ui.settings.AppSettingsRepository
import ch.srgssr.pillarbox.demo.shared.ui.settings.AppSettingsViewModel
import ch.srgssr.pillarbox.demo.shared.ui.settings.MetricsOverlayOptions
Expand Down Expand Up @@ -62,7 +64,11 @@ class PlayerActivity : ComponentActivity() {
metricsOverlayEnabled = appSettings.metricsOverlayEnabled,
metricsOverlayOptions = MetricsOverlayOptions(
textColor = appSettings.metricsOverlayTextColor.color,
textSize = appSettings.metricsOverlayTextSize.size,
textStyle = when (appSettings.metricsOverlayTextSize) {
AppSettings.TextSize.Small -> MaterialTheme.typography.bodySmall
AppSettings.TextSize.Medium -> MaterialTheme.typography.bodyMedium
AppSettings.TextSize.Large -> MaterialTheme.typography.bodyLarge
},
),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import androidx.media3.common.Player
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import ch.srgssr.pillarbox.demo.shared.ui.settings.AppSettings
import ch.srgssr.pillarbox.demo.shared.ui.settings.AppSettingsRepository
import ch.srgssr.pillarbox.demo.shared.ui.settings.AppSettingsViewModel
import ch.srgssr.pillarbox.demo.shared.ui.settings.MetricsOverlayOptions
Expand All @@ -45,7 +46,7 @@ import com.google.accompanist.navigation.material.rememberBottomSheetNavigator
* @param player The [Player] to observe.
* @param modifier The modifier to be applied to the layout.
* @param pictureInPicture The picture in picture state.
* @param pictureInPictureClick he picture in picture button action. If null no button.
* @param pictureInPictureClick The picture in picture button action. If `null` no button is displayed.
* @param displayPlaylist If it displays playlist ui or not.
*/
@OptIn(ExperimentalMaterialNavigationApi::class)
Expand Down Expand Up @@ -141,7 +142,11 @@ private fun PlayerContent(
overlayEnabled = appSettings.metricsOverlayEnabled,
overlayOptions = MetricsOverlayOptions(
textColor = appSettings.metricsOverlayTextColor.color,
textSize = appSettings.metricsOverlayTextSize.size
textStyle = when (appSettings.metricsOverlayTextSize) {
AppSettings.TextSize.Small -> MaterialTheme.typography.bodySmall
AppSettings.TextSize.Medium -> MaterialTheme.typography.bodyMedium
AppSettings.TextSize.Large -> MaterialTheme.typography.bodyLarge
},
),
) {
PlayerBottomToolbar(
Expand Down

0 comments on commit 2a32a0b

Please sign in to comment.