Skip to content

Commit

Permalink
feat: preference tooltips.
Browse files Browse the repository at this point in the history
  • Loading branch information
oxyroid committed Sep 23, 2023
1 parent cbe2730 commit ba3943c
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 95 deletions.
2 changes: 0 additions & 2 deletions androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:Suppress("UnstableApiUsage")

plugins {
alias(libs.plugins.com.android.application)
alias(libs.plugins.org.jetbrains.kotlin.android)
Expand Down
121 changes: 60 additions & 61 deletions androidApp/src/main/java/com/m3u/androidApp/ui/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -93,7 +92,9 @@ fun App(
val isSystemBarVisible =
currentDestination notDestinationTo Destination.Live::class.java &&
currentDestination notDestinationTo Destination.LivePlayList::class.java
val isBackPressedVisible = currentDestination.safeDestinationTo<Destination.Root>(true)
val isBackPressedVisible = with(currentDestination) {
safeDestinationTo<Destination.Root>(true)
}

val cinemaMode = state.cinemaMode
val theme = when {
Expand Down Expand Up @@ -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
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:Suppress("UnstableApiUsage")

plugins {
alias(libs.plugins.com.android.library)
alias(libs.plugins.org.jetbrains.kotlin.android)
Expand Down
2 changes: 0 additions & 2 deletions data/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:Suppress("UnstableApiUsage")

plugins {
alias(libs.plugins.com.android.library)
alias(libs.plugins.org.jetbrains.kotlin.android)
Expand Down
2 changes: 0 additions & 2 deletions features/console/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:Suppress("UnstableApiUsage")

plugins {
alias(libs.plugins.com.android.library)
alias(libs.plugins.org.jetbrains.kotlin.android)
Expand Down
2 changes: 0 additions & 2 deletions features/crash/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:Suppress("UnstableApiUsage")

plugins {
alias(libs.plugins.com.android.library)
alias(libs.plugins.org.jetbrains.kotlin.android)
Expand Down
2 changes: 0 additions & 2 deletions features/favorite/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:Suppress("UnstableApiUsage")

plugins {
alias(libs.plugins.com.android.library)
alias(libs.plugins.org.jetbrains.kotlin.android)
Expand Down
2 changes: 0 additions & 2 deletions features/feed/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:Suppress("UnstableApiUsage")

plugins {
alias(libs.plugins.com.android.library)
alias(libs.plugins.org.jetbrains.kotlin.android)
Expand Down
2 changes: 0 additions & 2 deletions features/live/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:Suppress("UnstableApiUsage")

plugins {
alias(libs.plugins.com.android.library)
alias(libs.plugins.org.jetbrains.kotlin.android)
Expand Down
2 changes: 0 additions & 2 deletions features/main/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:Suppress("UnstableApiUsage")

plugins {
alias(libs.plugins.com.android.library)
alias(libs.plugins.org.jetbrains.kotlin.android)
Expand Down
2 changes: 0 additions & 2 deletions features/scheme/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:Suppress("UnstableApiUsage")

plugins {
alias(libs.plugins.com.android.library)
alias(libs.plugins.org.jetbrains.kotlin.android)
Expand Down
2 changes: 0 additions & 2 deletions features/setting/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:Suppress("UnstableApiUsage")

plugins {
alias(libs.plugins.com.android.library)
alias(libs.plugins.org.jetbrains.kotlin.android)
Expand Down
2 changes: 0 additions & 2 deletions ui/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:Suppress("UnstableApiUsage")

plugins {
alias(libs.plugins.com.android.library)
alias(libs.plugins.org.jetbrains.kotlin.android)
Expand Down
38 changes: 31 additions & 7 deletions ui/src/main/java/com/m3u/ui/LocalProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
}
}
}

}
}
6 changes: 3 additions & 3 deletions ui/src/main/java/com/m3u/ui/model/Theme.kt
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -31,7 +31,7 @@ data class Theme(
val divider: Color
)

val LocalTheme = staticCompositionLocalOf { DayTheme }
val LocalTheme = compositionLocalOf { DayTheme }

val DayTheme = Theme(
name = "Day",
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit ba3943c

Please sign in to comment.