Skip to content

Commit

Permalink
update: enable danmaku switch
Browse files Browse the repository at this point in the history
  • Loading branch information
muedsa committed Nov 3, 2023
1 parent c5cfdfe commit 7e7c048
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -60,7 +60,6 @@ import com.muedsa.uitl.LogUtil

@OptIn(
ExperimentalTvMaterial3Api::class,
ExperimentalMaterial3Api::class,
ExperimentalLayoutApi::class
)
@Composable
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
43 changes: 43 additions & 0 deletions app/src/main/kotlin/com/muedsa/compose/tv/widget/SwitchKt.kt
Original file line number Diff line number Diff line change
@@ -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
)
}

0 comments on commit 7e7c048

Please sign in to comment.