Skip to content

Commit

Permalink
新增 UGC 主分区内容
Browse files Browse the repository at this point in the history
  • Loading branch information
aaa1115910 committed Dec 4, 2024
1 parent 28264c6 commit 4f0203f
Show file tree
Hide file tree
Showing 52 changed files with 2,236 additions and 405 deletions.
2 changes: 2 additions & 0 deletions app/src/main/kotlin/dev/aaa1115910/bv/BVApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import dev.aaa1115910.biliapi.repositories.PgcRepository
import dev.aaa1115910.biliapi.repositories.RecommendVideoRepository
import dev.aaa1115910.biliapi.repositories.SearchRepository
import dev.aaa1115910.biliapi.repositories.SeasonRepository
import dev.aaa1115910.biliapi.repositories.UgcRepository
import dev.aaa1115910.biliapi.repositories.VideoDetailRepository
import dev.aaa1115910.biliapi.repositories.VideoPlayRepository
import dev.aaa1115910.bv.dao.AppDatabase
Expand Down Expand Up @@ -162,6 +163,7 @@ val appModule = module {
single { SeasonRepository(get()) }
single { dev.aaa1115910.biliapi.repositories.UserRepository(get(), get()) }
single { PgcRepository() }
single { UgcRepository(get()) }
viewModel { DynamicViewModel(get(), get()) }
viewModel { RecommendViewModel(get()) }
viewModel { PopularViewModel(get()) }
Expand Down
146 changes: 86 additions & 60 deletions app/src/main/kotlin/dev/aaa1115910/bv/component/Carousel.kt
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
)
}
57 changes: 30 additions & 27 deletions app/src/main/kotlin/dev/aaa1115910/bv/component/TopNav.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ import androidx.tv.material3.Tab
import androidx.tv.material3.TabRow
import androidx.tv.material3.TabRowScope
import androidx.tv.material3.Text
import dev.aaa1115910.biliapi.entity.pgc.PgcType
import dev.aaa1115910.biliapi.entity.ugc.UgcType
import dev.aaa1115910.bv.BVApp
import dev.aaa1115910.bv.util.getDisplayName

@Composable
fun TopNav(
modifier: Modifier = Modifier,
items: List<TopNavItem>,
isLargePadding:Boolean,
isLargePadding: Boolean,
onSelectedChanged: (TopNavItem) -> Unit = {},
onClick: (TopNavItem) -> Unit = {}
) {
Expand Down Expand Up @@ -114,38 +117,38 @@ enum class HomeTopNavItem(private val displayName: String) : TopNavItem {
}
}

enum class UgcTopNavItem(private val displayName: String) : TopNavItem {
Douga("动画"),
Game("游戏"),
Kichiku("鬼畜"),
Music("音乐"),
Dance("舞蹈"),
Cinephile("影视"),
Ent("娱乐"),
Knowledge("知识"),
Tech("科技"),
Information("资讯"),
Food("美食"),
Life("生活"),
Car("汽车"),
Fashion("时尚"),
Sports("体育"),
Animal("动物圈");
enum class UgcTopNavItem(private val ugcType: UgcType) : TopNavItem {
Douga(UgcType.Douga),
Game(UgcType.Game),
Kichiku(UgcType.Kichiku),
Music(UgcType.Music),
Dance(UgcType.Dance),
Cinephile(UgcType.Cinephile),
Ent(UgcType.Ent),
Knowledge(UgcType.Knowledge),
Tech(UgcType.Tech),
Information(UgcType.Information),
Food(UgcType.Food),
Life(UgcType.Life),
Car(UgcType.Car),
Fashion(UgcType.Fashion),
Sports(UgcType.Sports),
Animal(UgcType.Animal);

override fun getDisplayName(context: Context): String {
return displayName
return ugcType.getDisplayName(context)
}
}

enum class PgcTopNavItem(private val displayName: String) : TopNavItem {
Anime("番剧"),
GuoChuang("国创"),
Movie("电影"),
Documentary("纪录片"),
Tv("电视剧"),
Variety("综艺");
enum class PgcTopNavItem(private val pgcType: PgcType) : TopNavItem {
Anime(PgcType.Anime),
GuoChuang(PgcType.GuoChuang),
Movie(PgcType.Movie),
Documentary(PgcType.Documentary),
Tv(PgcType.Tv),
Variety(PgcType.Variety);

override fun getDisplayName(context: Context): String {
return displayName
return pgcType.getDisplayName(context)
}
}
77 changes: 0 additions & 77 deletions app/src/main/kotlin/dev/aaa1115910/bv/component/pgc/Carousel.kt

This file was deleted.

This file was deleted.

Loading

0 comments on commit 4f0203f

Please sign in to comment.