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

@@ -4,7 +4,7 @@ plugins {
id 'kotlin-android' id 'kotlin-android'
} }
def composeVersion = "1.1.0-rc03" def composeVersion = "1.2.0-beta03"
android { android {
compileSdkVersion 32 compileSdkVersion 32
@@ -54,21 +54,22 @@ android {
dependencies { dependencies {
// ktx // ktx
def ktx_core = "1.7.0" def ktx_core = "1.8.0"
def ktx_paging = "3.1.1" def ktx_paging = "3.1.1"
implementation "androidx.core:core-ktx:$ktx_core" implementation "androidx.core:core-ktx:$ktx_core"
implementation "androidx.paging:paging-common-ktx:$ktx_paging" implementation "androidx.paging:paging-common-ktx:$ktx_paging"
// android x // android x
implementation "androidx.window:window:1.0.0" def androidx = "1.0.0"
implementation "androidx.window:window:$androidx"
// compose // compose
def compose = composeVersion def compose = composeVersion
def compose_material3 = "1.0.0-alpha07" def compose_material3 = "1.0.0-alpha13"
def compose_accompanist = "0.22.1-rc" def compose_accompanist = "0.24.10-beta"
def compose_navigation = "2.4.1" def compose_navigation = "2.4.2"
def compose_paging = "1.0.0-alpha14" def compose_paging = "1.0.0-alpha15"
def compose_constraint_layout = "1.0.0" def compose_constraint_layout = "1.0.1"
def compose_activity = "1.4.0" def compose_activity = "1.4.0"
implementation "androidx.compose.ui:ui:$compose" implementation "androidx.compose.ui:ui:$compose"
implementation "androidx.compose.material3:material3:$compose_material3" implementation "androidx.compose.material3:material3:$compose_material3"
@@ -85,6 +86,10 @@ dependencies {
implementation "androidx.paging:paging-compose:$compose_paging" implementation "androidx.paging:paging-compose:$compose_paging"
implementation "androidx.constraintlayout:constraintlayout-compose:$compose_constraint_layout" implementation "androidx.constraintlayout:constraintlayout-compose:$compose_constraint_layout"
// material you
def monet_compat = "0.4.1"
implementation "com.github.KieronQuinn:MonetCompat:$monet_compat"
// lifecycle // lifecycle
def lifecycle_runtime = "2.4.1" def lifecycle_runtime = "2.4.1"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_runtime" implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_runtime"
@@ -92,7 +97,7 @@ dependencies {
// retrofit // retrofit
def retrofit = "2.9.0" def retrofit = "2.9.0"
def stetho = "1.6.0" def stetho = "1.6.0"
def gson = "2.8.7" def gson = "2.9.0"
implementation "com.squareup.retrofit2:retrofit:$retrofit" implementation "com.squareup.retrofit2:retrofit:$retrofit"
implementation "com.squareup.retrofit2:converter-gson:$retrofit" implementation "com.squareup.retrofit2:converter-gson:$retrofit"
implementation "com.google.code.gson:gson:$gson" implementation "com.google.code.gson:gson:$gson"
@@ -108,7 +113,7 @@ dependencies {
implementation "io.coil-kt:coil-compose:$coil" implementation "io.coil-kt:coil-compose:$coil"
//Coroutines //Coroutines
def coroutines = "1.6.0" def coroutines = "1.6.1"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines"
// youtube player // youtube player

View File

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

View File

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

View File

@@ -6,8 +6,8 @@ import androidx.compose.foundation.Image
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.GridCells import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.LazyVerticalGrid import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Card import androidx.compose.material.Card
import androidx.compose.material3.MaterialTheme 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.ContentScale
import androidx.compose.ui.layout.onGloballyPositioned import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.IntSize import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
@@ -50,7 +49,7 @@ fun PosterGrid(
fetchMedia(mediaList) fetchMedia(mediaList)
LazyVerticalGrid( LazyVerticalGrid(
cells = GridCells.Adaptive(minSize = POSTER_WIDTH), columns = GridCells.Adaptive(minSize = POSTER_WIDTH),
contentPadding = PaddingValues(8.dp), contentPadding = PaddingValues(8.dp),
horizontalArrangement = Arrangement.SpaceBetween horizontalArrangement = Arrangement.SpaceBetween
) { ) {
@@ -74,7 +73,7 @@ fun PeoplePosterGrid(
fetchPeople(peopleList) fetchPeople(peopleList)
LazyVerticalGrid( LazyVerticalGrid(
cells = GridCells.Adaptive(minSize = POSTER_WIDTH), columns = GridCells.Adaptive(minSize = POSTER_WIDTH),
contentPadding = PaddingValues(8.dp), contentPadding = PaddingValues(8.dp),
horizontalArrangement = Arrangement.SpaceBetween 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 appBarTitle = rememberSaveable { mutableStateOf(BottomNavItem.getByRoute(currentRoute)?.name ?: BottomNavItem.Items[0].name) }
val decayAnimationSpec = rememberSplineBasedDecay<Float>() val decayAnimationSpec = rememberSplineBasedDecay<Float>()
val topAppBarScrollState = rememberTopAppBarScrollState()
val scrollBehavior = remember(decayAnimationSpec) { val scrollBehavior = remember(decayAnimationSpec) {
TopAppBarDefaults.exitUntilCollapsedScrollBehavior(decayAnimationSpec) TopAppBarDefaults.exitUntilCollapsedScrollBehavior(decayAnimationSpec, topAppBarScrollState)
} }
val focusRequester = remember { FocusRequester() } 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 package com.owenlejeune.tvtime.ui.theme
//import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
//import androidx.compose.material.Shapes import androidx.compose.material.Shapes
//import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
//
//val Shapes = Shapes( val Shapes = Shapes(
// small = RoundedCornerShape(4.dp), small = RoundedCornerShape(4.dp),
// medium = RoundedCornerShape(4.dp), medium = RoundedCornerShape(4.dp),
// large = RoundedCornerShape(0.dp) large = RoundedCornerShape(0.dp)
//) )

View File

@@ -1,11 +1,12 @@
package com.owenlejeune.tvtime.ui.theme package com.owenlejeune.tvtime.ui.theme
import android.os.Build
import androidx.compose.foundation.isSystemInDarkTheme 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.runtime.Composable
import androidx.compose.ui.platform.LocalContext import com.kieronquinn.monetcompat.core.MonetCompat
import com.google.accompanist.systemuicontroller.rememberSystemUiController
private val DarkColorPalette = darkColorScheme( private val DarkColorPalette = darkColorScheme(
primary = A1_200, primary = A1_200,
@@ -65,30 +66,68 @@ private val LightColorPalette = lightColorScheme(
inverseOnSurface = N1_50 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 @Composable
fun TVTimeTheme( fun TVTimeTheme(
isDarkTheme: Boolean = isSystemInDarkTheme(), isDarkTheme: Boolean = isSystemInDarkTheme(),
isDynamicColor: Boolean = true, monetCompat: MonetCompat,
content: @Composable () -> Unit content: @Composable () -> Unit
) { ) {
val dynamicColor = isDynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S val colors = if(isDarkTheme) {
val colorScheme = when { monetCompat.darkMonetCompatScheme()
dynamicColor && isDarkTheme -> { } else {
dynamicDarkColorScheme(LocalContext.current) monetCompat.lightMonetCompatScheme()
}
dynamicColor && !isDarkTheme -> {
dynamicLightColorScheme(LocalContext.current)
}
isDarkTheme -> DarkColorPalette
else -> LightColorPalette
} }
val systemUiController = rememberSystemUiController() androidx.compose.material3.MaterialTheme(
systemUiController.setSystemBarsColor(colorScheme.background, !isDarkTheme) colorScheme = colors,
typography = Typography
) {
MaterialTheme( MaterialTheme(
colorScheme = colorScheme, colors = Colors(
typography = Typography, 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 content = content
) )
}
} }

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<style name="Theme.TVTime" parent="android:Theme.Material.Light.NoActionBar"> <style name="Theme.TVTime" parent="Theme.AppCompat.NoActionBar">
</style> </style>
</resources> </resources>

View File

@@ -1,6 +1,6 @@
buildscript { buildscript {
def gradle = "7.1.2" def gradle = "7.1.2"
def kotlin = "1.6.10" def kotlin = "1.6.21"
repositories { repositories {
google() google()
mavenCentral() mavenCentral()