-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
28264c6
commit 4f0203f
Showing
52 changed files
with
2,236 additions
and
405 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 86 additions & 60 deletions
146
app/src/main/kotlin/dev/aaa1115910/bv/component/Carousel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,110 @@ | ||
package dev.aaa1115910.bv.component | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.border | ||
import androidx.compose.foundation.focusable | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.animation.core.tween | ||
import androidx.compose.animation.fadeIn | ||
import androidx.compose.animation.fadeOut | ||
import androidx.compose.animation.togetherWith | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
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.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.focus.onFocusChanged | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.draw.clip | ||
import androidx.compose.ui.layout.ContentScale | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.unit.dp | ||
import androidx.tv.material3.Button | ||
import androidx.tv.material3.Carousel | ||
import androidx.tv.material3.ExperimentalTvMaterial3Api | ||
import androidx.tv.material3.Text | ||
import androidx.tv.material3.MaterialTheme | ||
import coil.compose.AsyncImage | ||
import dev.aaa1115910.biliapi.entity.CarouselData | ||
import dev.aaa1115910.bv.activities.video.SeasonInfoActivity | ||
import dev.aaa1115910.bv.activities.video.VideoInfoActivity | ||
import dev.aaa1115910.bv.entity.proxy.ProxyArea | ||
import dev.aaa1115910.bv.util.focusedBorder | ||
|
||
@OptIn(ExperimentalTvMaterial3Api::class) | ||
@Composable | ||
fun HomeCarousel( | ||
modifier: Modifier = Modifier | ||
fun PgcCarousel( | ||
modifier: Modifier = Modifier, | ||
data: List<CarouselData.CarouselItem> | ||
) { | ||
val backgrounds = listOf( | ||
Color.Red.copy(alpha = 0.3f), | ||
Color.Yellow.copy(alpha = 0.3f), | ||
Color.Green.copy(alpha = 0.3f) | ||
val context = LocalContext.current | ||
|
||
CarouselContent( | ||
modifier = modifier, | ||
data = data, | ||
onClick = { item -> | ||
SeasonInfoActivity.actionStart( | ||
context = context, | ||
epId = item.episodeId, | ||
seasonId = item.seasonId, | ||
proxyArea = ProxyArea.checkProxyArea(item.title) | ||
) | ||
} | ||
) | ||
} | ||
|
||
@OptIn(ExperimentalTvMaterial3Api::class) | ||
@Composable | ||
fun UgcCarousel( | ||
modifier: Modifier = Modifier, | ||
data: List<CarouselData.CarouselItem> | ||
) { | ||
val context = LocalContext.current | ||
|
||
CarouselContent( | ||
modifier = modifier, | ||
data = data, | ||
onClick = { item -> | ||
VideoInfoActivity.actionStart( | ||
context = context, | ||
aid = item.avid!! | ||
) | ||
} | ||
) | ||
} | ||
|
||
@OptIn(ExperimentalTvMaterial3Api::class) | ||
@Composable | ||
fun CarouselContent( | ||
modifier: Modifier = Modifier, | ||
data: List<CarouselData.CarouselItem>, | ||
onClick: (CarouselData.CarouselItem) -> Unit | ||
) { | ||
Carousel( | ||
itemCount = backgrounds.size, | ||
itemCount = data.size, | ||
modifier = modifier | ||
.height(300.dp) | ||
.fillMaxWidth(), | ||
.height(240.dp) | ||
.clip(MaterialTheme.shapes.large) | ||
.focusedBorder(), | ||
contentTransformEndToStart = | ||
fadeIn(tween(1000)).togetherWith(fadeOut(tween(1000))), | ||
contentTransformStartToEnd = | ||
fadeIn(tween(1000)).togetherWith(fadeOut(tween(1000))) | ||
) { itemIndex -> | ||
Box( | ||
modifier = Modifier | ||
.background(backgrounds[itemIndex]) | ||
.border(2.dp, Color.White.copy(alpha = 0.5f)) | ||
.fillMaxSize() | ||
) { | ||
CarouselCard() | ||
} | ||
CarouselCard( | ||
data = data[itemIndex], | ||
onClick = { onClick(data[itemIndex]) } | ||
) | ||
} | ||
} | ||
|
||
@Composable | ||
private fun CarouselCard() { | ||
Box( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.focusable() | ||
.padding(40.dp), | ||
contentAlignment = Alignment.CenterStart | ||
) { | ||
var isFocused by remember { mutableStateOf(false) } | ||
|
||
Box( | ||
modifier = Modifier | ||
.border( | ||
width = 2.dp, | ||
color = if (isFocused) Color.Red else Color.Transparent, | ||
shape = RoundedCornerShape(50) | ||
) | ||
) { | ||
Button( | ||
onClick = { }, | ||
modifier = Modifier | ||
.onFocusChanged { isFocused = it.isFocused } | ||
.padding(vertical = 2.dp, horizontal = 5.dp) | ||
) { | ||
Text(text = "Play") | ||
} | ||
} | ||
} | ||
fun CarouselCard( | ||
modifier: Modifier = Modifier, | ||
data: CarouselData.CarouselItem, | ||
onClick: () -> Unit = {} | ||
) { | ||
AsyncImage( | ||
modifier = modifier | ||
.fillMaxWidth() | ||
.clip(MaterialTheme.shapes.large) | ||
.clickable { onClick() }, | ||
model = data.cover, | ||
contentDescription = null, | ||
contentScale = ContentScale.Crop, | ||
alignment = Alignment.TopCenter | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 0 additions & 77 deletions
77
app/src/main/kotlin/dev/aaa1115910/bv/component/pgc/Carousel.kt
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
app/src/main/kotlin/dev/aaa1115910/bv/screen/main/PartitionScreen.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.