update dependencies and implement monet colors

This commit is contained in:
Owen LeJeune
2022-06-14 14:55:28 -04:00
parent a5a5996fb3
commit eddbf65720
10 changed files with 252 additions and 63 deletions

View File

@@ -8,8 +8,10 @@ import androidx.compose.runtime.*
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.lifecycleScope
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import com.kieronquinn.monetcompat.app.MonetCompatActivity
import com.owenlejeune.tvtime.ui.navigation.MainNavigationRoutes
import com.owenlejeune.tvtime.ui.theme.TVTimeTheme
import com.owenlejeune.tvtime.utils.KeyboardManager
@@ -18,7 +20,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
class MainActivity : ComponentActivity() {
class MainActivity : MonetCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@@ -27,11 +29,16 @@ class MainActivity : ComponentActivity() {
SessionManager.initialize()
}
setContent {
AppKeyboardFocusManager()
MyApp(
appNavController = rememberNavController()
)
lifecycleScope.launchWhenCreated {
monet.awaitMonetReady()
setContent {
AppKeyboardFocusManager()
TVTimeTheme(monetCompat = monet) {
MyApp(
appNavController = rememberNavController()
)
}
}
}
}
}
@@ -40,10 +47,8 @@ class MainActivity : ComponentActivity() {
fun MyApp(
appNavController: NavHostController = rememberNavController()
) {
TVTimeTheme {
Box {
MainNavigationRoutes(navController = appNavController)
}
Box {
MainNavigationRoutes(navController = appNavController)
}
}

View File

@@ -2,9 +2,9 @@ package com.owenlejeune.tvtime.extensions
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.lazy.LazyGridScope
import androidx.compose.foundation.lazy.LazyItemScope
import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.foundation.lazy.grid.LazyGridItemScope
import androidx.compose.foundation.lazy.grid.LazyGridScope
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.paging.compose.LazyPagingItems
@@ -12,7 +12,7 @@ import androidx.paging.compose.LazyPagingItems
@OptIn(ExperimentalFoundationApi::class)
fun <T: Any> LazyGridScope.lazyPagingItems(
lazyPagingItems: LazyPagingItems<T>,
itemContent: @Composable LazyItemScope.(value: T?) -> Unit
itemContent: @Composable LazyGridItemScope.(value: T?) -> Unit
) {
items(lazyPagingItems.itemCount) { index ->
itemContent(lazyPagingItems[index])

View File

@@ -6,8 +6,8 @@ import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.GridCells
import androidx.compose.foundation.lazy.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Card
import androidx.compose.material3.MaterialTheme
@@ -19,7 +19,6 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp
@@ -50,7 +49,7 @@ fun PosterGrid(
fetchMedia(mediaList)
LazyVerticalGrid(
cells = GridCells.Adaptive(minSize = POSTER_WIDTH),
columns = GridCells.Adaptive(minSize = POSTER_WIDTH),
contentPadding = PaddingValues(8.dp),
horizontalArrangement = Arrangement.SpaceBetween
) {
@@ -74,7 +73,7 @@ fun PeoplePosterGrid(
fetchPeople(peopleList)
LazyVerticalGrid(
cells = GridCells.Adaptive(minSize = POSTER_WIDTH),
columns = GridCells.Adaptive(minSize = POSTER_WIDTH),
contentPadding = PaddingValues(8.dp),
horizontalArrangement = Arrangement.SpaceBetween
) {

View File

@@ -40,8 +40,9 @@ fun MainAppView(appNavController: NavHostController, preferences: AppPreferences
val appBarTitle = rememberSaveable { mutableStateOf(BottomNavItem.getByRoute(currentRoute)?.name ?: BottomNavItem.Items[0].name) }
val decayAnimationSpec = rememberSplineBasedDecay<Float>()
val topAppBarScrollState = rememberTopAppBarScrollState()
val scrollBehavior = remember(decayAnimationSpec) {
TopAppBarDefaults.exitUntilCollapsedScrollBehavior(decayAnimationSpec)
TopAppBarDefaults.exitUntilCollapsedScrollBehavior(decayAnimationSpec, topAppBarScrollState)
}
val focusRequester = remember { FocusRequester() }

View File

@@ -0,0 +1,140 @@
package com.owenlejeune.tvtime.ui.theme
import androidx.annotation.IntRange
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import com.kieronquinn.monetcompat.core.MonetCompat
import com.kieronquinn.monetcompat.extensions.toArgb
private fun MonetCompat.getMonetNeutralColor(
@IntRange(from = 1, to = 2) type: Int,
@IntRange(from = 50, to = 900) shade: Int
): Color {
val monetColor = when (type) {
1 -> this.getMonetColors().neutral1[shade]
else -> this.getMonetColors().neutral2[shade]
}?.toArgb() ?: throw Exception("Neutral$type shade $shade doesn't exist")
return Color(monetColor)
}
private fun MonetCompat.getMonetAccentColor(
@IntRange(from = 1, to = 3) type: Int,
@IntRange(from = 50, to = 900) shade: Int
): Color {
val monetColor = when (type) {
1 -> this.getMonetColors().accent1[shade]
2 -> this.getMonetColors().accent2[shade]
else -> this.getMonetColors().accent3[shade]
}?.toArgb() ?: throw Exception("Accent$type shade $shade doesn't exist")
return Color(monetColor)
}
/**
* Any values that are not set will be chosen to best represent default values given by [dynamicLightColorScheme][androidx.compose.material3.dynamicLightColorScheme]
* on Android 12+ devices
*/
@Composable
fun MonetCompat.lightMonetCompatScheme(
primary: Color = getMonetAccentColor(1, 700),
onPrimary: Color = getMonetNeutralColor(1, 50),
primaryContainer: Color = getMonetAccentColor(2, 100),
onPrimaryContainer: Color = getMonetAccentColor(1, 900),
inversePrimary: Color = getMonetAccentColor(1, 200),
secondary: Color = getMonetAccentColor(2, 700),
onSecondary: Color = getMonetNeutralColor(1, 50),
secondaryContainer: Color = getMonetAccentColor(2, 100),
onSecondaryContainer: Color = getMonetAccentColor(2, 900),
tertiary: Color = getMonetAccentColor(3, 600),
onTertiary: Color = getMonetNeutralColor(1, 50),
tertiaryContainer: Color = getMonetAccentColor(3, 100),
onTertiaryContainer: Color = getMonetAccentColor(3, 900),
background: Color = getMonetNeutralColor(1, 50),
onBackground: Color = getMonetNeutralColor(1, 900),
surface: Color = getMonetNeutralColor(1, 50),
onSurface: Color = getMonetNeutralColor(1, 900),
surfaceVariant: Color = getMonetNeutralColor(2, 100),
onSurfaceVariant: Color = getMonetNeutralColor(2, 700),
inverseSurface: Color = getMonetNeutralColor(1, 800),
inverseOnSurface: Color = getMonetNeutralColor(2, 50),
outline: Color = getMonetAccentColor(2, 500),
): androidx.compose.material3.ColorScheme =
lightColorScheme(
primary = primary,
onPrimary = onPrimary,
primaryContainer = primaryContainer,
onPrimaryContainer = onPrimaryContainer,
inversePrimary = inversePrimary,
secondary = secondary,
onSecondary = onSecondary,
secondaryContainer = secondaryContainer,
onSecondaryContainer = onSecondaryContainer,
tertiary = tertiary,
onTertiary = onTertiary,
tertiaryContainer = tertiaryContainer,
onTertiaryContainer = onTertiaryContainer,
background = background,
onBackground = onBackground,
surface = surface,
onSurface = onSurface,
surfaceVariant = surfaceVariant,
onSurfaceVariant = onSurfaceVariant,
inverseSurface = inverseSurface,
inverseOnSurface = inverseOnSurface,
outline = outline,
)
/**
* Any values that are not set will be chosen to best represent default values given by [dynamicDarkColorScheme][androidx.compose.material3.dynamicDarkColorScheme]
* on Android 12+ devices
*/
@Composable
fun MonetCompat.darkMonetCompatScheme(
primary: Color = getMonetAccentColor(1, 200),
onPrimary: Color = getMonetAccentColor(1, 800),
primaryContainer: Color = getMonetAccentColor(1, 600),
onPrimaryContainer: Color = getMonetAccentColor(2, 100),
inversePrimary: Color = getMonetAccentColor(1, 600),
secondary: Color = getMonetAccentColor(2, 200),
onSecondary: Color = getMonetAccentColor(2, 800),
secondaryContainer: Color = getMonetAccentColor(2, 700),
onSecondaryContainer: Color = getMonetAccentColor(2, 100),
tertiary: Color = getMonetAccentColor(3, 200),
onTertiary: Color = getMonetAccentColor(3, 700),
tertiaryContainer: Color = getMonetAccentColor(3, 700),
onTertiaryContainer: Color = getMonetAccentColor(3, 100),
background: Color = getMonetNeutralColor(1, 900),
onBackground: Color = getMonetNeutralColor(1, 100),
surface: Color = getMonetNeutralColor(1, 900),
onSurface: Color = getMonetNeutralColor(1, 100),
surfaceVariant: Color = getMonetNeutralColor(2, 700),
onSurfaceVariant: Color = getMonetNeutralColor(2, 200),
inverseSurface: Color = getMonetNeutralColor(1, 100),
inverseOnSurface: Color = getMonetNeutralColor(1, 800),
outline: Color = getMonetNeutralColor(2, 500),
): androidx.compose.material3.ColorScheme =
darkColorScheme(
primary = primary,
onPrimary = onPrimary,
primaryContainer = primaryContainer,
onPrimaryContainer = onPrimaryContainer,
inversePrimary = inversePrimary,
secondary = secondary,
onSecondary = onSecondary,
secondaryContainer = secondaryContainer,
onSecondaryContainer = onSecondaryContainer,
tertiary = tertiary,
onTertiary = onTertiary,
tertiaryContainer = tertiaryContainer,
onTertiaryContainer = onTertiaryContainer,
background = background,
onBackground = onBackground,
surface = surface,
onSurface = onSurface,
surfaceVariant = surfaceVariant,
onSurfaceVariant = onSurfaceVariant,
inverseSurface = inverseSurface,
inverseOnSurface = inverseOnSurface,
outline = outline,
)

View File

@@ -1,11 +1,11 @@
package com.owenlejeune.tvtime.ui.theme
//import androidx.compose.foundation.shape.RoundedCornerShape
//import androidx.compose.material.Shapes
//import androidx.compose.ui.unit.dp
//
//val Shapes = Shapes(
// small = RoundedCornerShape(4.dp),
// medium = RoundedCornerShape(4.dp),
// large = RoundedCornerShape(0.dp)
//)
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Shapes
import androidx.compose.ui.unit.dp
val Shapes = Shapes(
small = RoundedCornerShape(4.dp),
medium = RoundedCornerShape(4.dp),
large = RoundedCornerShape(0.dp)
)

View File

@@ -1,11 +1,12 @@
package com.owenlejeune.tvtime.ui.theme
import android.os.Build
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.*
import androidx.compose.material.Colors
import androidx.compose.material.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import com.kieronquinn.monetcompat.core.MonetCompat
private val DarkColorPalette = darkColorScheme(
primary = A1_200,
@@ -65,30 +66,68 @@ private val LightColorPalette = lightColorScheme(
inverseOnSurface = N1_50
)
//@Composable
//fun TVTimeTheme(
// isDarkTheme: Boolean = isSystemInDarkTheme(),
// isDynamicColor: Boolean = true,
// content: @Composable () -> Unit
//) {
// val dynamicColor = isDynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
// val colorScheme = when {
// dynamicColor && isDarkTheme -> {
// dynamicDarkColorScheme(LocalContext.current)
// }
// dynamicColor && !isDarkTheme -> {
// dynamicLightColorScheme(LocalContext.current)
// }
// isDarkTheme -> DarkColorPalette
// else -> LightColorPalette
// }
//
// val systemUiController = rememberSystemUiController()
// systemUiController.setSystemBarsColor(colorScheme.background, !isDarkTheme)
//
// MaterialTheme(
// colorScheme = colorScheme,
// typography = Typography,
// content = content
// )
//}
@Composable
fun TVTimeTheme(
isDarkTheme: Boolean = isSystemInDarkTheme(),
isDynamicColor: Boolean = true,
monetCompat: MonetCompat,
content: @Composable () -> Unit
) {
val dynamicColor = isDynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
val colorScheme = when {
dynamicColor && isDarkTheme -> {
dynamicDarkColorScheme(LocalContext.current)
}
dynamicColor && !isDarkTheme -> {
dynamicLightColorScheme(LocalContext.current)
}
isDarkTheme -> DarkColorPalette
else -> LightColorPalette
val colors = if(isDarkTheme) {
monetCompat.darkMonetCompatScheme()
} else {
monetCompat.lightMonetCompatScheme()
}
val systemUiController = rememberSystemUiController()
systemUiController.setSystemBarsColor(colorScheme.background, !isDarkTheme)
MaterialTheme(
colorScheme = colorScheme,
typography = Typography,
content = content
)
androidx.compose.material3.MaterialTheme(
colorScheme = colors,
typography = Typography
) {
MaterialTheme(
colors = Colors(
primary = colors.primary,
primaryVariant = colors.inversePrimary,
secondary = colors.secondary,
onSecondary = colors.onSecondary,
secondaryVariant = colors.secondaryContainer,
background = colors.background,
onBackground = colors.onBackground,
surface = colors.surface,
error = colors.error,
onPrimary = colors.onPrimary,
onSurface = colors.onSurface,
onError = colors.onError,
isLight = !isDarkTheme
),
shapes = Shapes,
content = content
)
}
}