From ba3943c4d4edff98407b88b1cca934b98ff78d03 Mon Sep 17 00:00:00 2001 From: oxy Date: Sat, 23 Sep 2023 16:38:03 +0800 Subject: [PATCH] feat: preference tooltips. --- androidApp/build.gradle.kts | 2 - .../main/java/com/m3u/androidApp/ui/App.kt | 121 +++++++++--------- core/build.gradle.kts | 2 - data/build.gradle.kts | 2 - features/console/build.gradle.kts | 2 - features/crash/build.gradle.kts | 2 - features/favorite/build.gradle.kts | 2 - features/feed/build.gradle.kts | 2 - features/live/build.gradle.kts | 2 - features/main/build.gradle.kts | 2 - features/scheme/build.gradle.kts | 2 - features/setting/build.gradle.kts | 2 - ui/build.gradle.kts | 2 - ui/src/main/java/com/m3u/ui/LocalProvider.kt | 38 +++++- ui/src/main/java/com/m3u/ui/model/Theme.kt | 6 +- 15 files changed, 94 insertions(+), 95 deletions(-) diff --git a/androidApp/build.gradle.kts b/androidApp/build.gradle.kts index 8f3360f90..5228d3456 100644 --- a/androidApp/build.gradle.kts +++ b/androidApp/build.gradle.kts @@ -1,5 +1,3 @@ -@file:Suppress("UnstableApiUsage") - plugins { alias(libs.plugins.com.android.application) alias(libs.plugins.org.jetbrains.kotlin.android) diff --git a/androidApp/src/main/java/com/m3u/androidApp/ui/App.kt b/androidApp/src/main/java/com/m3u/androidApp/ui/App.kt index 2ae56f9e7..89773dae2 100644 --- a/androidApp/src/main/java/com/m3u/androidApp/ui/App.kt +++ b/androidApp/src/main/java/com/m3u/androidApp/ui/App.kt @@ -32,7 +32,6 @@ import com.m3u.androidApp.navigation.safeDestinationTo import com.m3u.data.database.entity.Post import com.m3u.ui.M3ULocalProvider import com.m3u.ui.components.AppTopBar -import com.m3u.ui.components.Background import com.m3u.ui.components.IconButton import com.m3u.ui.model.ABlackTheme import com.m3u.ui.model.AppAction @@ -93,7 +92,9 @@ fun App( val isSystemBarVisible = currentDestination notDestinationTo Destination.Live::class.java && currentDestination notDestinationTo Destination.LivePlayList::class.java - val isBackPressedVisible = currentDestination.safeDestinationTo(true) + val isBackPressedVisible = with(currentDestination) { + safeDestinationTo(true) + } val cinemaMode = state.cinemaMode val theme = when { @@ -138,69 +139,67 @@ fun App( onDispose {} } - Background { - AppTopBar( - text = text, - visible = isSystemBarVisible, - scrollable = currentDestination notDestinationTo Destination.Root::class.java, - actions = { - val actions by viewModel.actions.collectAsStateWithLifecycle() - actions.forEach { action -> - IconButton( - icon = action.icon, - contentDescription = action.contentDescription, - onClick = action.onClick - ) - } - }, - onBackPressed = if (isBackPressedVisible) null else appState::onBackClick - ) { padding -> - Column( - modifier = Modifier - .fillMaxSize() - .padding(padding), - verticalArrangement = Arrangement.Bottom, - horizontalAlignment = Alignment.CenterHorizontally - ) { - M3UNavHost( - navController = appState.navController, - currentPage = appState.currentPage, - onCurrentPage = { appState.currentPage = it }, - destinations = topLevelDestinations, - navigateToDestination = appState::navigateToDestination, - modifier = Modifier - .fillMaxWidth() - .weight(1f) + AppTopBar( + text = text, + visible = isSystemBarVisible, + scrollable = currentDestination notDestinationTo Destination.Root::class.java, + actions = { + val actions by viewModel.actions.collectAsStateWithLifecycle() + actions.forEach { action -> + IconButton( + icon = action.icon, + contentDescription = action.contentDescription, + onClick = action.onClick ) - AnimatedVisibility(isSystemBarVisible) { - Column { - OptimizeBanner( - post = posts.firstOrNull(), - onPost = onPost, - modifier = Modifier.fillMaxWidth() - ) - BottomNavigationSheet( - destinations = topLevelDestinations, - index = appState.currentPage, - navigateToTopLevelDestination = { - appState.navigateToTopLevelDestination(it) - }, - modifier = Modifier.fillMaxWidth() - ) - } + } + }, + onBackPressed = if (isBackPressedVisible) null else appState::onBackClick + ) { padding -> + Column( + modifier = Modifier + .fillMaxSize() + .padding(padding), + verticalArrangement = Arrangement.Bottom, + horizontalAlignment = Alignment.CenterHorizontally + ) { + M3UNavHost( + navController = appState.navController, + currentPage = appState.currentPage, + onCurrentPage = { appState.currentPage = it }, + destinations = topLevelDestinations, + navigateToDestination = appState::navigateToDestination, + modifier = Modifier + .fillMaxWidth() + .weight(1f) + ) + AnimatedVisibility(isSystemBarVisible) { + Column { + OptimizeBanner( + post = posts.firstOrNull(), + onPost = onPost, + modifier = Modifier.fillMaxWidth() + ) + BottomNavigationSheet( + destinations = topLevelDestinations, + index = appState.currentPage, + navigateToTopLevelDestination = { + appState.navigateToTopLevelDestination(it) + }, + modifier = Modifier.fillMaxWidth() + ) } } } - PostDialog( - status = postDialogStatus, - onDismiss = { onPost(null) }, - onNext = { viewModel.onEvent(RootEvent.OnNext) }, - onPrevious = { viewModel.onEvent(RootEvent.OnPrevious) }, - onRead = { viewModel.onEvent(RootEvent.OnRead) } - ) - BackHandler(postDialogStatus != PostDialogStatus.Idle) { - postDialogStatus = PostDialogStatus.Idle - } + } + PostDialog( + status = postDialogStatus, + onDismiss = { onPost(null) }, + onNext = { viewModel.onEvent(RootEvent.OnNext) }, + onPrevious = { viewModel.onEvent(RootEvent.OnPrevious) }, + onRead = { viewModel.onEvent(RootEvent.OnRead) } + ) + BackHandler(postDialogStatus != PostDialogStatus.Idle) { + postDialogStatus = PostDialogStatus.Idle } } } diff --git a/core/build.gradle.kts b/core/build.gradle.kts index ac971b565..583d9e180 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -1,5 +1,3 @@ -@file:Suppress("UnstableApiUsage") - plugins { alias(libs.plugins.com.android.library) alias(libs.plugins.org.jetbrains.kotlin.android) diff --git a/data/build.gradle.kts b/data/build.gradle.kts index 985c227ca..6e8bbdbbd 100644 --- a/data/build.gradle.kts +++ b/data/build.gradle.kts @@ -1,5 +1,3 @@ -@file:Suppress("UnstableApiUsage") - plugins { alias(libs.plugins.com.android.library) alias(libs.plugins.org.jetbrains.kotlin.android) diff --git a/features/console/build.gradle.kts b/features/console/build.gradle.kts index ae400153a..48aeb6d7d 100644 --- a/features/console/build.gradle.kts +++ b/features/console/build.gradle.kts @@ -1,5 +1,3 @@ -@file:Suppress("UnstableApiUsage") - plugins { alias(libs.plugins.com.android.library) alias(libs.plugins.org.jetbrains.kotlin.android) diff --git a/features/crash/build.gradle.kts b/features/crash/build.gradle.kts index 50a97febd..82d27085c 100644 --- a/features/crash/build.gradle.kts +++ b/features/crash/build.gradle.kts @@ -1,5 +1,3 @@ -@file:Suppress("UnstableApiUsage") - plugins { alias(libs.plugins.com.android.library) alias(libs.plugins.org.jetbrains.kotlin.android) diff --git a/features/favorite/build.gradle.kts b/features/favorite/build.gradle.kts index d74a6af9c..081ebc5a5 100644 --- a/features/favorite/build.gradle.kts +++ b/features/favorite/build.gradle.kts @@ -1,5 +1,3 @@ -@file:Suppress("UnstableApiUsage") - plugins { alias(libs.plugins.com.android.library) alias(libs.plugins.org.jetbrains.kotlin.android) diff --git a/features/feed/build.gradle.kts b/features/feed/build.gradle.kts index 369693009..7f123ecb8 100644 --- a/features/feed/build.gradle.kts +++ b/features/feed/build.gradle.kts @@ -1,5 +1,3 @@ -@file:Suppress("UnstableApiUsage") - plugins { alias(libs.plugins.com.android.library) alias(libs.plugins.org.jetbrains.kotlin.android) diff --git a/features/live/build.gradle.kts b/features/live/build.gradle.kts index df29e0f21..fe7a4381a 100644 --- a/features/live/build.gradle.kts +++ b/features/live/build.gradle.kts @@ -1,5 +1,3 @@ -@file:Suppress("UnstableApiUsage") - plugins { alias(libs.plugins.com.android.library) alias(libs.plugins.org.jetbrains.kotlin.android) diff --git a/features/main/build.gradle.kts b/features/main/build.gradle.kts index d2d330d5b..002d14e04 100644 --- a/features/main/build.gradle.kts +++ b/features/main/build.gradle.kts @@ -1,5 +1,3 @@ -@file:Suppress("UnstableApiUsage") - plugins { alias(libs.plugins.com.android.library) alias(libs.plugins.org.jetbrains.kotlin.android) diff --git a/features/scheme/build.gradle.kts b/features/scheme/build.gradle.kts index dac3c01b6..169a5063c 100644 --- a/features/scheme/build.gradle.kts +++ b/features/scheme/build.gradle.kts @@ -1,5 +1,3 @@ -@file:Suppress("UnstableApiUsage") - plugins { alias(libs.plugins.com.android.library) alias(libs.plugins.org.jetbrains.kotlin.android) diff --git a/features/setting/build.gradle.kts b/features/setting/build.gradle.kts index 323f76186..2a89c25d0 100644 --- a/features/setting/build.gradle.kts +++ b/features/setting/build.gradle.kts @@ -1,5 +1,3 @@ -@file:Suppress("UnstableApiUsage") - plugins { alias(libs.plugins.com.android.library) alias(libs.plugins.org.jetbrains.kotlin.android) diff --git a/ui/build.gradle.kts b/ui/build.gradle.kts index fc1eb46d0..00dff3cbe 100644 --- a/ui/build.gradle.kts +++ b/ui/build.gradle.kts @@ -1,5 +1,3 @@ -@file:Suppress("UnstableApiUsage") - plugins { alias(libs.plugins.com.android.library) alias(libs.plugins.org.jetbrains.kotlin.android) diff --git a/ui/src/main/java/com/m3u/ui/LocalProvider.kt b/ui/src/main/java/com/m3u/ui/LocalProvider.kt index ee7f76b78..3ae39fc08 100644 --- a/ui/src/main/java/com/m3u/ui/LocalProvider.kt +++ b/ui/src/main/java/com/m3u/ui/LocalProvider.kt @@ -4,6 +4,7 @@ import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.material.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider +import com.m3u.ui.components.Background import com.m3u.ui.model.DayTheme import com.m3u.ui.model.EmptyHelper import com.m3u.ui.model.Helper @@ -12,21 +13,44 @@ import com.m3u.ui.model.LocalTheme import com.m3u.ui.model.NightTheme import com.m3u.ui.model.Theme import com.m3u.ui.model.Typography +import androidx.compose.material3.MaterialTheme as Material3Theme @Composable fun M3ULocalProvider( - theme: Theme = if (isSystemInDarkTheme()) NightTheme - else DayTheme, + theme: Theme = if (isSystemInDarkTheme()) NightTheme else DayTheme, helper: Helper = EmptyHelper, content: @Composable () -> Unit ) { - CompositionLocalProvider( - LocalTheme provides theme, - LocalHelper provides helper + Material3Theme( + colorScheme = Material3Theme.colorScheme.copy( + surface = theme.surface, + onSurface = theme.onSurface, + background = theme.background, + onBackground = theme.onBackground, + primary = theme.tint, + onPrimary = theme.onTint, + ) ) { MaterialTheme( typography = Typography, - content = content - ) + colors = MaterialTheme.colors.copy( + surface = theme.surface, + onSurface = theme.onSurface, + background = theme.background, + onBackground = theme.onBackground, + primary = theme.tint, + onPrimary = theme.onTint, + ) + ) { + CompositionLocalProvider( + LocalTheme provides theme, + LocalHelper provides helper + ) { + Background { + content() + } + } + } + } } \ No newline at end of file diff --git a/ui/src/main/java/com/m3u/ui/model/Theme.kt b/ui/src/main/java/com/m3u/ui/model/Theme.kt index a0d2c9cd7..f5d333ac9 100644 --- a/ui/src/main/java/com/m3u/ui/model/Theme.kt +++ b/ui/src/main/java/com/m3u/ui/model/Theme.kt @@ -1,6 +1,6 @@ package com.m3u.ui.model -import androidx.compose.runtime.staticCompositionLocalOf +import androidx.compose.runtime.compositionLocalOf import androidx.compose.ui.graphics.Color data class Theme( @@ -31,7 +31,7 @@ data class Theme( val divider: Color ) -val LocalTheme = staticCompositionLocalOf { DayTheme } +val LocalTheme = compositionLocalOf { DayTheme } val DayTheme = Theme( name = "Day", @@ -94,7 +94,7 @@ val ABlackTheme = Theme( isDark = true, isDarkText = false, tint = Color.White, - surface = Color.Transparent, + surface = Color(0xff000000), onSurface = Color(0xFFeeeeee), topBar = Color(0xff1C1B1F), onTopBar = Color(0xFFE6E1E5),