mirror of
https://github.com/owenlejeune/TVTime.git
synced 2025-11-22 19:50:54 -05:00
some cleanup
This commit is contained in:
@@ -59,6 +59,9 @@ dependencies {
|
|||||||
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
|
||||||
|
implementation "androidx.window:window:1.0.0"
|
||||||
|
|
||||||
// compose
|
// compose
|
||||||
def compose = composeVersion
|
def compose = composeVersion
|
||||||
def compose_material3 = "1.0.0-alpha07"
|
def compose_material3 = "1.0.0-alpha07"
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import androidx.activity.ComponentActivity
|
|||||||
import androidx.activity.compose.setContent
|
import androidx.activity.compose.setContent
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.runtime.saveable.rememberSaveable
|
|
||||||
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
|
||||||
@@ -30,19 +29,8 @@ class MainActivity : ComponentActivity() {
|
|||||||
|
|
||||||
setContent {
|
setContent {
|
||||||
AppKeyboardFocusManager()
|
AppKeyboardFocusManager()
|
||||||
val displayUnderStatusBar = rememberSaveable { mutableStateOf(false) }
|
|
||||||
// WindowCompat.setDecorFitsSystemWindows(window, false)
|
|
||||||
// WindowCompat.setDecorFitsSystemWindows(window, !displayUnderStatusBar.value)
|
|
||||||
// val statusBarColor = if (displayUnderStatusBar.value) {
|
|
||||||
// Color.Transparent
|
|
||||||
// } else {
|
|
||||||
// MaterialTheme.colorScheme.background
|
|
||||||
// }
|
|
||||||
// val systemUiController = rememberSystemUiController()
|
|
||||||
// systemUiController.setStatusBarColor(statusBarColor, !isSystemInDarkTheme())
|
|
||||||
MyApp(
|
MyApp(
|
||||||
appNavController = rememberNavController(),
|
appNavController = rememberNavController()
|
||||||
displayUnderStatusBar = displayUnderStatusBar
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -50,12 +38,11 @@ class MainActivity : ComponentActivity() {
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun MyApp(
|
fun MyApp(
|
||||||
appNavController: NavHostController = rememberNavController(),
|
appNavController: NavHostController = rememberNavController()
|
||||||
displayUnderStatusBar: MutableState<Boolean> = mutableStateOf(false)
|
|
||||||
) {
|
) {
|
||||||
TVTimeTheme {
|
TVTimeTheme {
|
||||||
Box {
|
Box {
|
||||||
MainNavigationRoutes(navController = appNavController, displayUnderStatusBar = displayUnderStatusBar)
|
MainNavigationRoutes(navController = appNavController)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package com.owenlejeune.tvtime.extensions
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.ui.geometry.Size
|
||||||
|
import androidx.compose.ui.graphics.toComposeRect
|
||||||
|
import androidx.compose.ui.platform.LocalConfiguration
|
||||||
|
import androidx.compose.ui.platform.LocalDensity
|
||||||
|
import androidx.compose.ui.unit.DpSize
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.window.layout.WindowMetricsCalculator
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun Activity.rememberWindowSize(): Size {
|
||||||
|
val configuration = LocalConfiguration.current
|
||||||
|
|
||||||
|
val windowMetrics = remember(configuration) {
|
||||||
|
WindowMetricsCalculator.getOrCreate().computeCurrentWindowMetrics(this)
|
||||||
|
}
|
||||||
|
return windowMetrics.bounds.toComposeRect().size
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class WindowSizeClass { Compact, Medium, Expanded }
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun Activity.rememberWindowSizeClass(): WindowSizeClass {
|
||||||
|
val windowSize = rememberWindowSize()
|
||||||
|
|
||||||
|
val windowSizeDp = with(LocalDensity.current) {
|
||||||
|
windowSize.toDpSize()
|
||||||
|
}
|
||||||
|
|
||||||
|
return getWindowSizeClass(windowSizeDp)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getWindowSizeClass(windowDpSize: DpSize): WindowSizeClass = when {
|
||||||
|
windowDpSize.width < 0.dp -> throw IllegalArgumentException("Dp value cannot be negative")
|
||||||
|
windowDpSize.width < 600.dp -> WindowSizeClass.Compact
|
||||||
|
windowDpSize.width < 840.dp -> WindowSizeClass.Medium
|
||||||
|
else -> WindowSizeClass.Expanded
|
||||||
|
}
|
||||||
@@ -23,12 +23,10 @@ object NavConstants {
|
|||||||
@Composable
|
@Composable
|
||||||
fun MainNavigationRoutes(
|
fun MainNavigationRoutes(
|
||||||
navController: NavHostController,
|
navController: NavHostController,
|
||||||
displayUnderStatusBar: MutableState<Boolean> = mutableStateOf(false),
|
|
||||||
startDestination: String = MainNavItem.MainView.route
|
startDestination: String = MainNavItem.MainView.route
|
||||||
) {
|
) {
|
||||||
NavHost(navController = navController, startDestination = startDestination) {
|
NavHost(navController = navController, startDestination = startDestination) {
|
||||||
composable(MainNavItem.MainView.route) {
|
composable(MainNavItem.MainView.route) {
|
||||||
displayUnderStatusBar.value = false
|
|
||||||
MainAppView(appNavController = navController)
|
MainAppView(appNavController = navController)
|
||||||
}
|
}
|
||||||
composable(
|
composable(
|
||||||
@@ -38,7 +36,6 @@ fun MainNavigationRoutes(
|
|||||||
navArgument(NavConstants.TYPE_KEY) { type = NavType.EnumType(MediaViewType::class.java) }
|
navArgument(NavConstants.TYPE_KEY) { type = NavType.EnumType(MediaViewType::class.java) }
|
||||||
)
|
)
|
||||||
) { navBackStackEntry ->
|
) { navBackStackEntry ->
|
||||||
displayUnderStatusBar.value = true
|
|
||||||
val args = navBackStackEntry.arguments
|
val args = navBackStackEntry.arguments
|
||||||
val mediaType = args?.getSerializable(NavConstants.TYPE_KEY) as MediaViewType
|
val mediaType = args?.getSerializable(NavConstants.TYPE_KEY) as MediaViewType
|
||||||
if (mediaType != MediaViewType.PERSON) {
|
if (mediaType != MediaViewType.PERSON) {
|
||||||
|
|||||||
Reference in New Issue
Block a user