Skip to content

Commit

Permalink
build: compose 1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
oxyroid committed May 15, 2024
1 parent 6f4b8cc commit 45f0394
Show file tree
Hide file tree
Showing 24 changed files with 339 additions and 317 deletions.
6 changes: 3 additions & 3 deletions androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ dependencies {

debugImplementation(libs.com.squareup.leakcanary.leakcanary.android)

androidTestImplementation(libs.androidx.compose.ui.ui.test.junit4)

implementation(libs.androidx.compose.material3.material3.adaptive)
implementation(libs.androidx.compose.material3.adaptive)
implementation(libs.androidx.compose.material3.adaptive.layout)
implementation(libs.androidx.compose.material3.adaptive.navigation)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.navigationBarsIgnoringVisibility
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.ModalBottomSheetDefaults
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
Expand Down Expand Up @@ -63,13 +62,9 @@ internal fun RemoteControlSheet(
if (visible) {
ModalBottomSheet(
sheetState = sheetState,
windowInsets = WindowInsets(0),
onDismissRequest = {
if (!searchingOrConnecting) onDismissRequest()
},
properties = ModalBottomSheetDefaults.properties(
shouldDismissOnBackPress = false
)
}
) {
Column(
modifier.padding(WindowInsets.navigationBarsIgnoringVisibility.asPaddingValues())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.ArrowBackIosNew
import androidx.compose.material.icons.rounded.Delete
import androidx.compose.material.ripple.rememberRipple
import com.m3u.material.components.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.ripple
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.m3u.material.components.Icon

@Composable
internal fun VirtualNumberKeyboard(
Expand Down Expand Up @@ -111,7 +111,7 @@ internal fun VirtualNumberKeyboard(
)
}
},
indication = rememberRipple(color = MaterialTheme.colorScheme.primary),
indication = ripple(color = MaterialTheme.colorScheme.primary),
interactionSource = remember { MutableInteractionSource() }
),
horizontalAlignment = Alignment.CenterHorizontally,
Expand Down Expand Up @@ -139,7 +139,7 @@ internal fun VirtualNumberKeyboard(
onCode("")
}
},
indication = rememberRipple(color = MaterialTheme.colorScheme.primary),
indication = ripple(color = MaterialTheme.colorScheme.primary),
interactionSource = remember { MutableInteractionSource() }
),
horizontalAlignment = Alignment.CenterHorizontally,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.compose.LifecycleResumeEffect
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.google.accompanist.permissions.rememberPermissionState
Expand All @@ -52,7 +53,6 @@ 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
Expand Down Expand Up @@ -91,7 +91,9 @@ internal fun PlaylistRoute(
val playlistUrl by viewModel.playlistUrl.collectAsStateWithLifecycle()
val playlist by viewModel.playlist.collectAsStateWithLifecycle()

val channels by viewModel.channels.collectAsStateWithLifecycle()
val channels by viewModel.channels.collectAsStateWithLifecycle(
minActiveState = Lifecycle.State.RESUMED
)

val episodes by viewModel.episodes.collectAsStateWithLifecycle()
val pinnedCategories by viewModel.pinnedCategories.collectAsStateWithLifecycle()
Expand Down Expand Up @@ -320,7 +322,7 @@ private fun PlaylistScreen(
val preferences = hiltPreferences()
TvMaterialTheme(
colorScheme = remember(preferences.argb) {
createScheme(preferences.argb, true).asColorScheme().asTvScheme()
createScheme(preferences.argb, true).asTvScheme()
}
) {
TvPlaylistScreenImpl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ package com.m3u.features.playlist.components

import androidx.activity.compose.BackHandler
import androidx.compose.animation.AnimatedContent
import androidx.compose.foundation.background
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.interaction.MutableInteractionSource
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.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
Expand All @@ -19,15 +23,16 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Menu
import androidx.compose.material.icons.rounded.PushPin
import androidx.compose.material.icons.rounded.VisibilityOff
import androidx.compose.material.ripple.rememberRipple
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.ripple
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand All @@ -36,76 +41,138 @@ import androidx.compose.runtime.setValue
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.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.dp
import com.m3u.material.components.IconButton
import com.m3u.material.ktx.thenIf
import com.m3u.material.model.LocalHazeState
import com.m3u.material.model.LocalSpacing
import dev.chrisbanes.haze.HazeDefaults
import dev.chrisbanes.haze.haze

@Composable
internal fun PlaylistTabRow(
selectedCategory: String,
categories: List<String>,
isExpanded: Boolean,
bottomContentPadding: PaddingValues,
onCategoryChanged: (String) -> Unit,
pinnedCategories: List<String>,
onPinOrUnpinCategory: (String) -> Unit,
onHideCategory: (String) -> Unit,
onExpanded: () -> Unit,
modifier: Modifier = Modifier
) {
val spacing = LocalSpacing.current
val hapticFeedback = LocalHapticFeedback.current
val state = rememberLazyListState()

Box(modifier) {
if (categories.size > 1) {
var focusCategory: String? by rememberSaveable { mutableStateOf(null) }
var focusCategory: String? by rememberSaveable { mutableStateOf(null) }
val header = @Composable {
AnimatedContent(
targetState = focusCategory,
label = "playlist-tab-row-action-buttons",
modifier = Modifier.background(MaterialTheme.colorScheme.surface)
) { name ->
Box(
modifier = Modifier.thenIf(isExpanded) {
Modifier.fillMaxWidth()
}
) {
if (name != null) {
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.End
) {
IconButton(
icon = Icons.Rounded.PushPin,
contentDescription = "pin",
onClick = {
name.let(onPinOrUnpinCategory)
focusCategory = null
}
)
IconButton(
icon = Icons.Rounded.VisibilityOff,
contentDescription = "hide",
onClick = {
name.let(onHideCategory)
focusCategory = null
}
)
}
} else {
IconButton(
icon = Icons.Rounded.Menu,
contentDescription = "",
onClick = onExpanded
)
}
}
}
}
LaunchedEffect(Unit) {
val index = categories.indexOf(selectedCategory)
if (index != -1) {
state.scrollToItem(index)
}
}
if (isExpanded) {
LazyColumn(
state = state,
horizontalAlignment = Alignment.Start,
verticalArrangement = Arrangement.spacedBy(spacing.extraSmall),
contentPadding = bottomContentPadding,
modifier = Modifier
.fillMaxSize()
.background(MaterialTheme.colorScheme.surface)
.haze(
LocalHazeState.current,
HazeDefaults.style(MaterialTheme.colorScheme.surface)
)
) {
stickyHeader {
header()
HorizontalDivider()
}
items(categories) { category ->
PlaylistTabRowItem(
name = category,
selected = category == selectedCategory,
pinned = category in pinnedCategories,
focused = category == focusCategory,
hasOtherFocused = focusCategory != null && focusCategory != category,
onClick = {
if (focusCategory == null) {
onCategoryChanged(category)
}
},
onLongClick = {
focusCategory = category
onCategoryChanged(category)
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
},
modifier = Modifier.fillMaxWidth()
)
}
}
} else {
Column {
LazyRow(
state = state,
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(spacing.extraSmall),
modifier = Modifier.fillMaxWidth()
modifier = Modifier
.background(MaterialTheme.colorScheme.surface)
.fillMaxWidth()
) {
stickyHeader {
AnimatedContent(
targetState = focusCategory,
label = "playlist-tab-row-action-buttons"
) { name ->
if (name != null) {
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.End
) {
IconButton(
icon = Icons.Rounded.PushPin,
contentDescription = "pin",
onClick = {
name.let(onPinOrUnpinCategory)
focusCategory = null
}
)
IconButton(
icon = Icons.Rounded.VisibilityOff,
contentDescription = "hide",
onClick = {
name.let(onHideCategory)
focusCategory = null
}
)
}
} else {
IconButton(
icon = Icons.Rounded.Menu,
contentDescription = "",
onClick = { /*TODO*/ }
)
}
}
}
stickyHeader { header() }
items(categories) { category ->
PlaylistTabRowItem(
name = category,
Expand All @@ -128,9 +195,9 @@ internal fun PlaylistTabRow(
}
HorizontalDivider()
}
BackHandler(focusCategory != null) {
focusCategory = null
}
}
BackHandler(focusCategory != null) {
focusCategory = null
}
}
}
Expand Down Expand Up @@ -159,14 +226,14 @@ private fun PlaylistTabRowItem(
}
)
) {
val indication = if (hasOtherFocused) null else rememberRipple()
val indication = if (hasOtherFocused) null else ripple()
val shape = RoundedCornerShape(topStart = 12.dp, topEnd = 12.dp)
Card(
colors = CardDefaults.cardColors(
containerColor = if (focused) LocalContentColor.current
else Color.Transparent,
else MaterialTheme.colorScheme.surface,
contentColor = if (focused) MaterialTheme.colorScheme.surfaceVariant
else LocalContentColor.current
else MaterialTheme.colorScheme.onSurface
),
shape = shape,
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ internal fun SmartphoneStreamGallery(
contentPadding = PaddingValues(spacing.medium) + contentPadding,
modifier = modifier.fillMaxSize()
) {
items(streams?.itemCount ?: 0) { index ->
items(
count = streams?.itemCount ?: 0,
key = { it }
) { index ->
val stream = streams?.get(index)
if (stream != null) {
SmartphoneStreamItem(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ internal fun SmartphoneStreamItem(
OutlinedCard(
modifier = Modifier.semantics(mergeDescendants = true) { },
border = CardDefaults.outlinedCardBorder(zapping),
colors = CardDefaults.cardColors(Color.Transparent),
colors = CardDefaults.cardColors(MaterialTheme.colorScheme.surfaceContainer),
shape = AbsoluteSmoothCornerShape(spacing.medium, 65)
) {
when {
Expand Down
Loading

0 comments on commit 45f0394

Please sign in to comment.