Explorar o código

themes preimplementation

Milan Jurkulak %!s(int64=3) %!d(string=hai) anos
pai
achega
b39ab68648

+ 47 - 0
app/src/main/kotlin/org/mjdev/tvapp/base/ui/theme/ThemeHelper.kt

@@ -6,6 +6,8 @@
  *  w: https://mjdev.org
  */
 
+@file:Suppress("unused")
+
 package org.mjdev.tvapp.base.ui.theme
 
 import android.app.Activity
@@ -15,11 +17,17 @@ import androidx.compose.foundation.shape.RoundedCornerShape
 import androidx.compose.runtime.Composable
 import androidx.compose.runtime.ReadOnlyComposable
 import androidx.compose.runtime.SideEffect
+import androidx.compose.runtime.compositionLocalOf
 import androidx.compose.runtime.staticCompositionLocalOf
+import androidx.compose.ui.graphics.Color
 import androidx.compose.ui.graphics.Shape
 import androidx.compose.ui.graphics.toArgb
 import androidx.compose.ui.platform.LocalView
+import androidx.compose.ui.text.TextStyle
+import androidx.compose.ui.unit.Dp
+import androidx.compose.ui.unit.TextUnit
 import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.sp
 import androidx.core.view.ViewCompat
 import androidx.tv.material3.ColorScheme
 import androidx.tv.material3.ExperimentalTvMaterial3Api
@@ -71,6 +79,40 @@ val LocalCardShape = staticCompositionLocalOf<Shape> {
     RoundedCornerShape(8.dp)
 }
 
+val LocalThemeProvider = compositionLocalOf {
+    ThemeProvider()
+}
+
+// todo
+@Suppress("MemberVisibilityCanBePrivate")
+class ThemeProvider {
+
+    val detailTextPaddingHorizontal: Dp = 48.dp
+    val detailTextPaddingVertical: Dp = 32.dp
+    val detailsTextColor: Color = Color.White
+    val detailTextBackgroundColor: Color = Color.Black
+    val detailsTitleTextStyle: TextStyle
+        @Composable
+        get() = MaterialTheme.typography.headlineLarge
+    val detailsTextStyle: TextStyle
+        @Composable
+        get() = MaterialTheme.typography.headlineMedium
+
+    val headerTitleTextSize: TextUnit = 0.sp
+    val headerTextSize: TextUnit = 0.sp
+    val headerClockTextSize: TextUnit = 0.sp
+
+    val backgroundColorDefault = Color.DarkGray
+    val backgroundColorMenu = Color(0xff202020)
+
+    val textColorDefault = Color.White
+
+    val roundCornerSize: Dp = 16.dp
+
+    val backgroundShape: Shape = RoundedCornerShape(roundCornerSize)
+
+}
+
 @Suppress("unused")
 object ThemeHelper {
 
@@ -79,4 +121,9 @@ object ThemeHelper {
         @ReadOnlyComposable
         get() = LocalCardShape.current
 
+    val themeProvider
+        @Composable
+        @ReadOnlyComposable
+        get() = LocalThemeProvider.current
+
 }

+ 16 - 25
app/src/main/kotlin/org/mjdev/tvapp/ui/components/Details.kt

@@ -18,13 +18,11 @@ import androidx.compose.foundation.layout.padding
 import androidx.compose.runtime.Composable
 import androidx.compose.ui.Alignment
 import androidx.compose.ui.Modifier
-import androidx.compose.ui.graphics.Color
 import androidx.compose.ui.layout.ContentScale
-import androidx.compose.ui.unit.dp
-import androidx.tv.material3.MaterialTheme
 import org.mjdev.tvapp.base.annotations.TvPreview
 import org.mjdev.tvapp.base.ui.components.image.ImageAny
 import org.mjdev.tvapp.base.ui.components.text.TextAny
+import org.mjdev.tvapp.base.ui.theme.LocalThemeProvider
 import org.mjdev.tvapp.data.Movie
 
 @SuppressLint("ModifierParameter")
@@ -33,49 +31,42 @@ import org.mjdev.tvapp.data.Movie
 fun Details(
     movie: Movie? = null,
     modifier: Modifier = Modifier,
-    textColor: Color = Color.White.copy(alpha = 0.8f)
 ) {
-
+    val themeProvider = LocalThemeProvider.current
     Box(
         modifier = modifier.fillMaxSize(),
         contentAlignment = Alignment.BottomStart,
     ) {
-
         ImageAny(
             src = movie?.imageUrl,
             contentDescription = null,
             contentScale = ContentScale.Crop,
             modifier = Modifier.fillMaxSize()
         )
-
         Column(
             modifier = Modifier
                 .fillMaxWidth()
-                .background(Color.Black)
-                .padding(vertical = 32.dp, horizontal = 48.dp)
+                .background(themeProvider.detailTextBackgroundColor)
+                .padding(
+                    vertical = themeProvider.detailTextPaddingVertical,
+                    horizontal = themeProvider.detailTextPaddingHorizontal
+                )
         ) {
-
             TextAny(
-                text = movie?.title,
-                style = MaterialTheme.typography.headlineLarge,
-                color = textColor
+                text = movie?.title ?: "-",
+                style = themeProvider.detailsTitleTextStyle,
+                color = themeProvider.detailsTextColor
             )
-
             TextAny(
-                text = movie?.studio,
-                style = MaterialTheme.typography.headlineMedium,
-                color = textColor
+                text = movie?.studio ?: "-",
+                style = themeProvider.detailsTextStyle,
+                color = themeProvider.detailsTextColor
             )
-
             TextAny(
-                text = movie?.title,
-                style = MaterialTheme.typography.headlineMedium,
-                color = textColor
+                text = movie?.title ?: "-",
+                style = themeProvider.detailsTextStyle,
+                color = themeProvider.detailsTextColor
             )
-
         }
-
     }
-
-
 }

+ 1 - 11
app/src/main/kotlin/org/mjdev/tvapp/ui/theme/Theme.kt

@@ -18,14 +18,4 @@ fun TVAppTheme(
     useDarkTheme: Boolean = isSystemInDarkTheme(),
     dynamicColor: Boolean = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S,
     content: @Composable () -> Unit,
-) = ThemeHelper (useDarkTheme, dynamicColor, content)
-
-// todo
-
-//val backgroundColorDefault = Color.DarkGray
-//val backgroundColorMenu = Color(0xff202020)
-//
-//val textColorDefault = Color.White
-//
-//val roundCornerSize: Dp = 16.dp
-//val backgroundShape: Shape = RoundedCornerShape(roundCornerSize)
+) = ThemeHelper (useDarkTheme, dynamicColor, content)