Skip to content

Commit

Permalink
fix: remove background content scope receiver.
Browse files Browse the repository at this point in the history
  • Loading branch information
oxyroid committed Jan 13, 2024
1 parent 7d7655e commit 3aea8e8
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 88 deletions.
20 changes: 11 additions & 9 deletions androidApp/src/main/java/com/m3u/androidApp/ui/AppRootGraph.kt
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,17 @@ internal fun AppRootGraph(
modifier = Modifier.fillMaxSize()
) { padding ->
Background {
content(padding)
AppSnackHost(
message = message,
modifier = Modifier
.fillMaxWidth()
.padding(spacing.small)
.align(Alignment.BottomCenter)
.padding(padding)
)
Box {
content(padding)
AppSnackHost(
message = message,
modifier = Modifier
.fillMaxWidth()
.padding(spacing.small)
.align(Alignment.BottomCenter)
.padding(padding)
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.m3u.features.console

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
Expand Down Expand Up @@ -73,52 +74,54 @@ private fun ConsoleScreen(
contentColor = Color.White,
modifier = modifier
) {
val commands = remember(output) { output.lines().asReversed() }
val state = rememberLazyListState()
LazyColumn(
state = state,
reverseLayout = true,
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Bottom,
horizontalAlignment = Alignment.Start,
contentPadding = contentPadding + PaddingValues(LocalSpacing.current.medium)
) {
items(commands) { command ->
CompositionLocalProvider(
LocalTextSelectionColors provides TextSelectionColors(
backgroundColor = Color(0xff265c8e),
handleColor = Color(0xff78c4dd)
)
) {
SelectionContainer {
MonoText(
text = MonoStyle.get(command).actual(command),
style = MaterialTheme.typography.bodyMedium,
color = MonoStyle.get(command).color,
modifier = Modifier.fillMaxWidth()
Box {
val commands = remember(output) { output.lines().asReversed() }
val state = rememberLazyListState()
LazyColumn(
state = state,
reverseLayout = true,
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Bottom,
horizontalAlignment = Alignment.Start,
contentPadding = contentPadding + PaddingValues(LocalSpacing.current.medium)
) {
items(commands) { command ->
CompositionLocalProvider(
LocalTextSelectionColors provides TextSelectionColors(
backgroundColor = Color(0xff265c8e),
handleColor = Color(0xff78c4dd)
)
) {
SelectionContainer {
MonoText(
text = MonoStyle.get(command).actual(command),
style = MaterialTheme.typography.bodyMedium,
color = MonoStyle.get(command).color,
modifier = Modifier.fillMaxWidth()
)
}
}
}
}
}
TextField(
text = input,
enabled = focus,
onValueChange = onInput,
singleLine = true,
placeholder = "command here...",
modifier = Modifier
.fillMaxWidth()
.align(Alignment.BottomCenter)
.padding(
start = LocalSpacing.current.medium,
end = LocalSpacing.current.medium,
bottom = LocalSpacing.current.medium,
),
keyboardActions = KeyboardActions { onExecute() }
)
LaunchedEffect(commands) {
state.animateScrollToItem(0)
TextField(
text = input,
enabled = focus,
onValueChange = onInput,
singleLine = true,
placeholder = "command here...",
modifier = Modifier
.fillMaxWidth()
.align(Alignment.BottomCenter)
.padding(
start = LocalSpacing.current.medium,
end = LocalSpacing.current.medium,
bottom = LocalSpacing.current.medium,
),
keyboardActions = KeyboardActions { onExecute() }
)
LaunchedEffect(commands) {
state.animateScrollToItem(0)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.m3u.features.crash.screen.detail

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.padding
Expand Down Expand Up @@ -34,35 +35,37 @@ internal fun DetailScreen(
}
val state by viewModel.state.collectAsStateWithLifecycle()
Background {
LazyColumn(
contentPadding = PaddingValues(spacing.medium),
modifier = modifier
) {
item {
MonoText(
text = state.text,
color = LocalContentColor.current
)
}
}
Column(
verticalArrangement = Arrangement.spacedBy(spacing.small),
modifier = Modifier
.align(Alignment.BottomEnd)
.padding(spacing.medium)
) {
ExtendedFloatingActionButton(
text = { Text("SAVE") },
icon = {
Icon(
imageVector = Icons.Rounded.FileDownload,
contentDescription = null
Box {
LazyColumn(
contentPadding = PaddingValues(spacing.medium),
modifier = modifier
) {
item {
MonoText(
text = state.text,
color = LocalContentColor.current
)
},
onClick = {
viewModel.onEvent(DetailEvent.Save)
}
)
}
Column(
verticalArrangement = Arrangement.spacedBy(spacing.small),
modifier = Modifier
.align(Alignment.BottomEnd)
.padding(spacing.medium)
) {
ExtendedFloatingActionButton(
text = { Text("SAVE") },
icon = {
Icon(
imageVector = Icons.Rounded.FileDownload,
contentDescription = null
)
},
onClick = {
viewModel.onEvent(DetailEvent.Save)
}
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flatMapMerge
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -76,7 +76,7 @@ class ForyouViewModel @Inject constructor(

@OptIn(ExperimentalCoroutinesApi::class)
internal val recommend: StateFlow<Recommend> = unseensDuration
.flatMapMerge { streamRepository.observeAllUnseenFavourites(it) }
.flatMapLatest { streamRepository.observeAllUnseenFavourites(it) }
.map { prev -> Recommend(prev.map { Recommend.UnseenSpec(it) }) }
.stateIn(
scope = viewModelScope,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.flatMapMerge
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
Expand Down Expand Up @@ -227,7 +227,7 @@ class PlaylistViewModel @Inject constructor(

@OptIn(ExperimentalCoroutinesApi::class)
internal val unsorted: StateFlow<List<Stream>> = combine(
playlistUrl.flatMapMerge { url ->
playlistUrl.flatMapLatest { url ->
playlistRepository.observeWithStreams(url)
},
query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import androidx.compose.material.icons.rounded.Image
import androidx.compose.material.icons.rounded.Refresh
import androidx.compose.material.icons.rounded.Search
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand Down Expand Up @@ -58,6 +57,7 @@ import com.m3u.features.playlist.Channel
import com.m3u.features.playlist.R
import com.m3u.features.playlist.components.TvStreamItem
import com.m3u.i18n.R.string
import com.m3u.material.components.Background
import com.m3u.material.components.IconButton
import com.m3u.material.ktx.Edge
import com.m3u.material.ktx.blurEdge
Expand Down Expand Up @@ -199,9 +199,7 @@ internal fun TvPlaylistScreenImpl(
ImmersiveList(
modifier = modifier.fillMaxWidth(),
background = { id, hasFocus ->
CompositionLocalProvider(
LocalContentColor provides MaterialTheme.colorScheme.onBackground
) {
Background {
AnimatedVisibility(hasFocus) {
AnimatedContent(id) { id ->
Box(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.spring
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.material3.LocalAbsoluteTonalElevation
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
Expand All @@ -24,7 +23,7 @@ inline fun Background(
modifier: Modifier = Modifier,
color: Color = MaterialTheme.colorScheme.background,
contentColor: Color = MaterialTheme.colorScheme.onBackground,
crossinline content: @Composable BoxScope.() -> Unit
crossinline content: @Composable () -> Unit
) {
val actualContentColor = contentColor.ifUnspecified {
if (!isTelevision()) LocalContentColor.current
Expand Down

0 comments on commit 3aea8e8

Please sign in to comment.