Skip to content

Commit

Permalink
fix: code clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
oxyroid committed Jan 27, 2024
1 parent 8d7f33e commit 70dc47c
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 27 deletions.
14 changes: 10 additions & 4 deletions androidApp/src/main/java/com/m3u/androidApp/ui/AppRootGraph.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.tv.material3.Border
Expand Down Expand Up @@ -189,7 +191,7 @@ internal fun AppRootGraph(
contentColor = currentContentColor
),
interactionSource = source,
shape = CardDefaults.shape(CircleShape,),
shape = CardDefaults.shape(CircleShape),
border = CardDefaults.border(focusedBorder = Border.None),
scale = CardDefaults.scale(
scale = if (selected) 1.1f else 1f,
Expand Down Expand Up @@ -228,8 +230,8 @@ internal fun AppRootGraph(
.weight(1f)
) { topBarWithContent(WindowInsets.systemBars.exclude(WindowInsets.navigationBars)) }
NavigationBar(
containerColor = currentContainerColor,
contentColor = currentContentColor,
containerColor = MaterialTheme.colorScheme.background,
contentColor = MaterialTheme.colorScheme.onBackground,
modifier = Modifier.fillMaxWidth()
) {
items {
Expand Down Expand Up @@ -306,6 +308,7 @@ private inline fun NavigationItemLayout(
label: @Composable () -> Unit
) -> Unit
) {
val hapticFeedback = LocalHapticFeedback.current
val tv = isTelevision()
val usefob = fob?.rootDestination == rootDestination
val selected = usefob || rootDestination == currentRootDestination
Expand Down Expand Up @@ -352,7 +355,10 @@ private inline fun NavigationItemLayout(
val actualOnClick: () -> Unit = if (usefob) {
{ fob?.onClick?.invoke() }
} else {
{ navigateToRoot(rootDestination) }
{
navigateToRoot(rootDestination)
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
}
}
block(selected, actualOnClick, icon, label)
}
2 changes: 1 addition & 1 deletion core/src/main/java/com/m3u/core/wrapper/Event.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.m3u.core.wrapper
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.Stable

@Stable
@Immutable
sealed class Event<out T> private constructor(
private val data: T? = null
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ class FavouriteViewModel @Inject constructor(

val zapping = combine(
zappingMode,
playerManager.streamId,
playerManager.url,
streamRepository.observeAll()
) { zappingMode, streamId, streams ->
) { zappingMode, url, streams ->
if (!zappingMode) null
else streams.find { it.id == streamId }
else streams.find { it.url == url }
}
.stateIn(
scope = viewModelScope,
Expand Down Expand Up @@ -124,7 +124,7 @@ class FavouriteViewModel @Inject constructor(
context,
Contracts.PLAYER_ACTIVITY
)
putExtra(Contracts.PLAYER_SHORTCUT_STREAM_ID, stream.id)
putExtra(Contracts.PLAYER_SHORTCUT_STREAM_URL, stream.url)
}
)
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,22 @@ fun ForyouRoute(
EventHandler(resume) {
helper.deep = 0
helper.title = title.title()
helper.actions = persistentListOf(
Action(
icon = icon,
contentDescription = "link",
onClick = { isConnectSheetVisible = true }
),
Action(
icon = Icons.Rounded.Add,
contentDescription = "add",
onClick = navigateToSettingPlaylistManagement
)
)
}

LaunchedEffect(icon) {
LaunchedEffect(resume, icon) {
if (resume.isHandled) return@LaunchedEffect
helper.actions = persistentListOf(
Action(
icon = icon,
Expand Down
4 changes: 0 additions & 4 deletions i18n/src/main/res/values-zh-rCN/feat_setting.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
<string name="feat_setting_sync_mode_skip_favourite">绕过收藏夹</string>
<string name="feat_setting_sync_mode">同步策略</string>

<string name="feat_setting_common_ui_mode">默认布局</string>
<string name="feat_setting_common_ui_mode_description">使用手机设备布局模式</string>
<string name="feat_setting_common_ui_mode_disabled_description">手机设备不可调整</string>

<string name="feat_setting_script_management">脚本管理</string>
<string name="feat_setting_playlist_management">订阅管理</string>
<string name="feat_setting_connect_timeout">最大超时时间</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.isSpecified
import androidx.compose.ui.graphics.takeOrElse
import androidx.compose.ui.unit.dp
import com.m3u.material.ktx.ifUnspecified
import com.m3u.material.ktx.isTelevision

@Composable
Expand All @@ -25,7 +25,7 @@ inline fun Background(
contentColor: Color = MaterialTheme.colorScheme.onBackground,
crossinline content: @Composable () -> Unit
) {
val actualContentColor = contentColor.ifUnspecified {
val actualContentColor = contentColor.takeOrElse {
if (!isTelevision()) LocalContentColor.current
else androidx.tv.material3.LocalContentColor.current
}
Expand Down
14 changes: 7 additions & 7 deletions material/src/main/java/com/m3u/material/components/Dialogs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.takeOrElse
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.semantics
Expand All @@ -28,7 +29,6 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties
import com.m3u.material.ktx.ifUnspecified
import com.m3u.material.model.LocalSpacing

@Composable
Expand All @@ -54,8 +54,8 @@ fun DialogTextField(
text = text,
onValueChange = onTextChange,
backgroundColor = if (readOnly) Color.Transparent
else backgroundColor.ifUnspecified { theme.surface },
contentColor = contentColor.ifUnspecified { theme.onSurface },
else backgroundColor.takeOrElse { theme.surface },
contentColor = contentColor.takeOrElse { theme.onSurface },
readOnly = readOnly,
fontWeight = FontWeight.ExtraBold,
fontSize = 20.sp,
Expand All @@ -65,7 +65,7 @@ fun DialogTextField(
if (onIconClick != null && icon != null) {
IconButton(
icon = icon,
tint = iconTint.ifUnspecified { MaterialTheme.colorScheme.onBackground },
tint = iconTint.takeOrElse { MaterialTheme.colorScheme.onBackground },
onClick = onIconClick,
contentDescription = null
)
Expand All @@ -86,9 +86,9 @@ fun DialogItem(
Surface(
shape = RoundedCornerShape(spacing.medium),
tonalElevation = 0.dp,
color = color.ifUnspecified { theme.surface },
contentColor = contentColor.ifUnspecified { theme.onSurface },
modifier = Modifier.semantics(mergeDescendants = true) { }
color = color.takeOrElse { theme.surface },
contentColor = contentColor.takeOrElse { theme.onSurface },
modifier = Modifier.semantics(mergeDescendants = true) { }
) {
Row(
horizontalArrangement = Arrangement.Start,
Expand Down
6 changes: 4 additions & 2 deletions material/src/main/java/com/m3u/material/ktx/Effects.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.takeOrElse
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.takeOrElse
import com.m3u.material.model.LocalDuration
import com.m3u.material.model.LocalSpacing

Expand All @@ -32,8 +34,8 @@ fun Modifier.interactionBorder(
shape: Shape = RectangleShape
): Modifier = interaction(type, source) { visible ->
val duration = LocalDuration.current
val actualColor = color.ifUnspecified { InteractionDefaults.BorderColor }
val actualDp = width.ifUnspecified { InteractionDefaults.BorderWidth }
val actualColor = color.takeOrElse { InteractionDefaults.BorderColor }
val actualDp = width.takeOrElse { InteractionDefaults.BorderWidth }
val currentColor by animateColorAsState(
targetValue = if (visible) actualColor else Color.Transparent,
animationSpec = tween(duration.medium),
Expand Down
3 changes: 1 addition & 2 deletions ui/src/main/java/com/m3u/ui/EventHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ import kotlinx.coroutines.CoroutineScope
@NonRestartableComposable
fun <T> EventHandler(
event: Event<T>,
vararg keys: Any?,
handler: suspend CoroutineScope.(T) -> Unit
) {
val currentHandler by rememberUpdatedState(handler)
LaunchedEffect(event, keys) {
LaunchedEffect(event) {
event.handle {
currentHandler(this, it)
}
Expand Down

0 comments on commit 70dc47c

Please sign in to comment.