From 7e7c0485b2e24541a17e654516b7b50f3b7d16d2 Mon Sep 17 00:00:00 2001 From: MUEDSA <7676275+muedsa@users.noreply.github.com> Date: Fri, 3 Nov 2023 18:07:34 +0800 Subject: [PATCH] update: enable danmaku switch --- .../ui/features/detail/AnimeDetailScreen.kt | 21 +++++++-- .../home/recommend/RecommendScreen.kt | 2 +- .../com/muedsa/compose/tv/widget/SwitchKt.kt | 43 +++++++++++++++++++ 3 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 app/src/main/kotlin/com/muedsa/compose/tv/widget/SwitchKt.kt diff --git a/app/src/main/kotlin/com/muedsa/agetv/ui/features/detail/AnimeDetailScreen.kt b/app/src/main/kotlin/com/muedsa/agetv/ui/features/detail/AnimeDetailScreen.kt index ab3dbee..a525761 100644 --- a/app/src/main/kotlin/com/muedsa/agetv/ui/features/detail/AnimeDetailScreen.kt +++ b/app/src/main/kotlin/com/muedsa/agetv/ui/features/detail/AnimeDetailScreen.kt @@ -18,7 +18,6 @@ import androidx.compose.material.icons.filled.Comment import androidx.compose.material.icons.filled.Favorite import androidx.compose.material.icons.filled.Star import androidx.compose.material.icons.filled.Whatshot -import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue @@ -51,6 +50,7 @@ import com.muedsa.compose.tv.widget.EmptyDataScreen import com.muedsa.compose.tv.widget.ErrorMessageBoxState import com.muedsa.compose.tv.widget.ErrorScreen import com.muedsa.compose.tv.widget.ExposedDropdownMenuButton +import com.muedsa.compose.tv.widget.FocusScaleSwitch import com.muedsa.compose.tv.widget.LoadingScreen import com.muedsa.compose.tv.widget.ScreenBackground import com.muedsa.compose.tv.widget.ScreenBackgroundType @@ -60,7 +60,6 @@ import com.muedsa.uitl.LogUtil @OptIn( ExperimentalTvMaterial3Api::class, - ExperimentalMaterial3Api::class, ExperimentalLayoutApi::class ) @Composable @@ -122,6 +121,8 @@ fun AnimeDetailScreen( var selectedPlaySource by remember { mutableStateOf(info.playLists.keys.first()) } var selectedPlaySourceList by remember { mutableStateOf(info.playLists[selectedPlaySource]!!) } + var enabledDanmaku by remember { mutableStateOf(true) } + LaunchedEffect(key1 = animeDetailLD) { if (selectedPlaySource != info.playLists.keys.first()) { selectedPlaySource = info.playLists.keys.first() @@ -249,9 +250,23 @@ fun AnimeDetailScreen( } ) + if (danAnimeInfo.type == LazyType.SUCCESS && danAnimeInfo.data != null) { + Spacer(modifier = Modifier.width(25.dp)) + Text( + text = "弹幕", + color = MaterialTheme.colorScheme.onBackground, + style = MaterialTheme.typography.titleMedium + ) + Spacer(modifier = Modifier.width(8.dp)) + FocusScaleSwitch( + checked = enabledDanmaku, + onCheckedChange = { enabledDanmaku = it } + ) + } + // 弹弹Play数据 if (danSearchAnimeListLD.type == LazyType.SUCCESS && !danSearchAnimeListLD.data.isNullOrEmpty()) { - Spacer(modifier = Modifier.width(15.dp)) + Spacer(modifier = Modifier.width(25.dp)) Text( text = "匹配弹弹Play", color = MaterialTheme.colorScheme.onBackground, diff --git a/app/src/main/kotlin/com/muedsa/agetv/ui/features/home/recommend/RecommendScreen.kt b/app/src/main/kotlin/com/muedsa/agetv/ui/features/home/recommend/RecommendScreen.kt index abfdf6a..66fa22b 100644 --- a/app/src/main/kotlin/com/muedsa/agetv/ui/features/home/recommend/RecommendScreen.kt +++ b/app/src/main/kotlin/com/muedsa/agetv/ui/features/home/recommend/RecommendScreen.kt @@ -88,7 +88,7 @@ fun RecommendScreen( itemsIndexed( items = recommendList, key = { _, item -> item.aid } - ) { index, item -> + ) { _, item -> ImageContentCard( modifier = Modifier.padding(end = ImageCardRowCardPadding), url = item.picSmall, diff --git a/app/src/main/kotlin/com/muedsa/compose/tv/widget/SwitchKt.kt b/app/src/main/kotlin/com/muedsa/compose/tv/widget/SwitchKt.kt new file mode 100644 index 0000000..4af343f --- /dev/null +++ b/app/src/main/kotlin/com/muedsa/compose/tv/widget/SwitchKt.kt @@ -0,0 +1,43 @@ +package com.muedsa.compose.tv.widget + +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.scale +import androidx.compose.ui.focus.onFocusChanged +import androidx.tv.material3.ExperimentalTvMaterial3Api +import androidx.tv.material3.Switch +import androidx.tv.material3.SwitchColors +import androidx.tv.material3.SwitchDefaults + +@OptIn(ExperimentalTvMaterial3Api::class) +@Composable +fun FocusScaleSwitch( + checked: Boolean, + onCheckedChange: ((Boolean) -> Unit)?, + modifier: Modifier = Modifier, + thumbContent: (@Composable () -> Unit)? = null, + enabled: Boolean = true, + colors: SwitchColors = SwitchDefaults.colors(), + interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, + scaleFactor: Float = 1.3f +) { + var hasFocus by remember { mutableStateOf(false) } + Switch( + checked = checked, + onCheckedChange = onCheckedChange, + modifier = modifier + .onFocusChanged { + hasFocus = it.hasFocus + } + .scale(if (hasFocus) scaleFactor else 1f), + thumbContent = thumbContent, + enabled = enabled, + colors = colors, + interactionSource = interactionSource + ) +} \ No newline at end of file