Skip to content

Commit

Permalink
fix: text colors for tv.
Browse files Browse the repository at this point in the history
fix: disable colorful background blur effect.
  • Loading branch information
oxyroid committed May 15, 2024
1 parent 75905ff commit d9ccf3b
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private fun Star(
) {
Box(
modifier = modifier
.blur(spec.blurRadius)
// .blur(spec.blurRadius)
.drawWithCache {
val width = size.width
val star = RoundedPolygon.star(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package com.m3u.features.favorite.components
import androidx.compose.foundation.combinedClickable
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.ListItem
import androidx.compose.material3.ListItemDefaults
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedCard
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.font.FontWeight
Expand Down Expand Up @@ -73,6 +75,7 @@ private fun SmartphoneFavoriteItemImpl(
OutlinedCard(
modifier = Modifier.semantics(mergeDescendants = true) { },
border = CardDefaults.outlinedCardBorder(zapping),
colors = CardDefaults.cardColors(Color.Transparent),
shape = AbsoluteSmoothCornerShape(spacing.medium, 65),
) {
ListItem(
Expand Down Expand Up @@ -108,6 +111,7 @@ private fun SmartphoneFavoriteItemImpl(
)
}
},
colors = ListItemDefaults.colors(Color.Transparent),
modifier = Modifier
.combinedClickable(
onClick = onClick,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.rounded.DriveFileMove
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.ListItem
import androidx.compose.material3.ListItemDefaults
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedCard
Expand All @@ -19,6 +20,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.BaselineShift
Expand Down Expand Up @@ -89,6 +91,7 @@ private fun SmartphonePlaylistItemImpl(
OutlinedCard(
shape = AbsoluteSmoothCornerShape(spacing.medium, 65),
border = CardDefaults.outlinedCardBorder(local),
colors = CardDefaults.cardColors(Color.Transparent),
modifier = modifier.semantics(mergeDescendants = true) { }
) {
ListItem(
Expand Down Expand Up @@ -170,6 +173,7 @@ private fun SmartphonePlaylistItemImpl(
}
}
},
colors = ListItemDefaults.colors(Color.Transparent),
modifier = Modifier.combinedClickable(
onClick = onClick,
onLongClick = onLongClick
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import androidx.compose.ui.platform.LocalContext
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.LifecycleResumeEffect
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.tv.material3.MaterialTheme
import com.google.accompanist.permissions.rememberPermissionState
import com.m3u.core.architecture.preferences.hiltPreferences
import com.m3u.core.util.basic.title
Expand All @@ -53,11 +52,14 @@ import com.m3u.data.service.MediaCommand
import com.m3u.features.playlist.internal.SmartphonePlaylistScreenImpl
import com.m3u.features.playlist.internal.TvPlaylistScreenImpl
import com.m3u.i18n.R.string
import com.m3u.material.ktx.asColorScheme
import com.m3u.material.ktx.checkPermissionOrRationale
import com.m3u.material.ktx.createScheme
import com.m3u.material.ktx.interceptVolumeEvent
import com.m3u.material.ktx.isTelevision
import com.m3u.material.ktx.thenIf
import com.m3u.material.model.LocalSpacing
import com.m3u.material.model.asTvScheme
import com.m3u.ui.Destination
import com.m3u.ui.EpisodesBottomSheet
import com.m3u.ui.Sort
Expand All @@ -68,6 +70,7 @@ import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import androidx.tv.material3.MaterialTheme as TvMaterialTheme

@Composable
internal fun PlaylistRoute(
Expand All @@ -80,7 +83,7 @@ internal fun PlaylistRoute(
val preferences = hiltPreferences()
val helper = LocalHelper.current
val coroutineScope = rememberCoroutineScope()
val colorScheme = MaterialTheme.colorScheme
val colorScheme = TvMaterialTheme.colorScheme

val tv = isTelevision()

Expand Down Expand Up @@ -314,23 +317,30 @@ private fun PlaylistScreen(
modifier = modifier
)
} else {
TvPlaylistScreenImpl(
title = title,
channels = channels,
query = query,
onQuery = onQuery,
onStream = onStream,
onRefresh = onRefresh,
sorts = sorts,
sort = sort,
onSort = onSort,
favorite = favourite,
hide = hide,
savePicture = savePicture,
createTvRecommend = createTvRecommend,
isVodOrSeriesPlaylist = isVodPlaylist || isSeriesPlaylist,
modifier = modifier
)
val preferences = hiltPreferences()
TvMaterialTheme(
colorScheme = remember(preferences.argb) {
createScheme(preferences.argb, true).asColorScheme().asTvScheme()
}
) {
TvPlaylistScreenImpl(
title = title,
channels = channels,
query = query,
onQuery = onQuery,
onStream = onStream,
onRefresh = onRefresh,
sorts = sorts,
sort = sort,
onSort = onSort,
favorite = favourite,
hide = hide,
savePicture = savePicture,
createTvRecommend = createTvRecommend,
isVodOrSeriesPlaylist = isVodPlaylist || isSeriesPlaylist,
modifier = modifier
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import androidx.activity.compose.BackHandler
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.foundation.background
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxHeight
Expand Down Expand Up @@ -40,11 +39,11 @@ import com.m3u.features.playlist.PlaylistViewModel
import com.m3u.features.playlist.components.ImmersiveBackground
import com.m3u.features.playlist.components.TvStreamGallery
import com.m3u.i18n.R
import com.m3u.material.components.Background
import com.m3u.material.components.Icon
import com.m3u.material.components.television.dialogFocusable
import com.m3u.material.ktx.Edge
import com.m3u.material.ktx.blurEdge
import com.m3u.material.ktx.thenIf
import com.m3u.material.model.LocalHazeState
import com.m3u.ui.Sort
import com.m3u.ui.TvSortFullScreenDialog
Expand Down Expand Up @@ -76,8 +75,6 @@ internal fun TvPlaylistScreenImpl(

val multiCategories = channels.size > 1
val noPictureMode = preferences.noPictureMode
val darkMode = if (preferences.followSystemTheme) isSystemInDarkTheme()
else preferences.darkMode
val useGridLayout = sort != Sort.UNSPECIFIED

val maxBrowserHeight by animateDpAsState(
Expand Down Expand Up @@ -121,23 +118,21 @@ internal fun TvPlaylistScreenImpl(
onClick = onStream,
onLongClick = { stream -> press = stream },
onFocus = { stream -> focus = stream },
modifier = Modifier.thenIf(darkMode) {
Modifier
.hazeChild(
LocalHazeState.current,
style = HazeStyle(blurRadius = 4.dp)
)
.blurEdge(
color = MaterialTheme.colorScheme.background,
edge = Edge.Top
)
}
modifier = Modifier
.hazeChild(
LocalHazeState.current,
style = HazeStyle(blurRadius = 4.dp)
)
.blurEdge(
color = MaterialTheme.colorScheme.background,
edge = Edge.Top
)
)
}
)
}

Box {
Background {
content()
MenuFullScreenDialog(
stream = press,
Expand Down
27 changes: 9 additions & 18 deletions material/src/main/java/com/m3u/material/components/Backgrounds.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.material3.LocalAbsoluteTonalElevation
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.contentColorFor
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Modifier
Expand All @@ -15,32 +14,24 @@ import androidx.compose.ui.unit.dp
import com.m3u.material.ktx.isTelevision

@Composable
// TODO: check drawBehind but not surface is necessary or not.
inline fun Background(
modifier: Modifier = Modifier,
color: Color = MaterialTheme.colorScheme.background,
contentColor: Color = MaterialTheme.colorScheme.contentColorFor(color),
color: Color = Color.Unspecified,
contentColor: Color = Color.Unspecified,
crossinline content: @Composable () -> Unit
) {
val actualColor = color.takeOrElse {
if (!isTelevision()) MaterialTheme.colorScheme.background
else androidx.tv.material3.MaterialTheme.colorScheme.background
}
val actualContentColor = contentColor.takeOrElse {
if (!isTelevision()) LocalContentColor.current
else androidx.tv.material3.LocalContentColor.current
if (!isTelevision()) MaterialTheme.colorScheme.onBackground
else androidx.tv.material3.MaterialTheme.colorScheme.onBackground
}
// val currentColor by animateColorAsState(
// targetValue = color,
// label = "color",
// animationSpec = spring(stiffness = Spring.StiffnessMediumLow)
// )
// val currentContentColor by animateColorAsState(
// targetValue = actualContentColor,
// label = "content-color",
// animationSpec = spring(stiffness = Spring.StiffnessMediumLow)
// )
Box(
modifier = Modifier
.drawBehind {
drawRect(color)
// if (currentColor.isSpecified) drawRect(currentColor)
drawRect(actualColor)
}
.then(modifier)
) {
Expand Down

0 comments on commit d9ccf3b

Please sign in to comment.