Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/aaa1115910/bv into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ldm0206 committed Dec 29, 2024
2 parents 599351c + 1b47270 commit 9b5958b
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 139 deletions.
14 changes: 7 additions & 7 deletions app/src/main/kotlin/dev/aaa1115910/bv/screen/main/HomeContent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import androidx.compose.animation.slideOutHorizontally
import androidx.compose.animation.togetherWith
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.grid.rememberLazyGridState
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
Expand Down Expand Up @@ -54,9 +54,9 @@ fun HomeContent(
val scope = rememberCoroutineScope()
val logger = KotlinLogging.logger("HomeContent")

val recommendState = rememberLazyGridState()
val popularState = rememberLazyGridState()
val dynamicState = rememberLazyGridState()
val recommendState = rememberLazyListState()
val popularState = rememberLazyListState()
val dynamicState = rememberLazyListState()

var selectedTab by remember { mutableStateOf(HomeTopNavItem.Recommend) }
var focusOnContent by remember { mutableStateOf(false) }
Expand Down Expand Up @@ -188,9 +188,9 @@ fun HomeContent(
}
) { screen ->
when (screen) {
HomeTopNavItem.Recommend -> RecommendScreen(lazyGridState = recommendState)
HomeTopNavItem.Popular -> PopularScreen(lazyGridState = popularState)
HomeTopNavItem.Dynamics -> DynamicsScreen(lazyGridState = dynamicState)
HomeTopNavItem.Recommend -> RecommendScreen(lazyListState = recommendState)
HomeTopNavItem.Popular -> PopularScreen(lazyListState = popularState)
HomeTopNavItem.Dynamics -> DynamicsScreen(lazyListState = dynamicState)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ package dev.aaa1115910.bv.screen.main.home

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.GridItemSpan
import androidx.compose.foundation.lazy.grid.LazyGridState
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.itemsIndexed
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.derivedStateOf
Expand All @@ -20,19 +18,16 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.input.key.KeyEventType
import androidx.compose.ui.input.key.key
import androidx.compose.ui.input.key.onPreviewKeyEvent
import androidx.compose.ui.input.key.type
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.tv.material3.Text
import dev.aaa1115910.biliapi.entity.user.DynamicVideo
import dev.aaa1115910.bv.activities.video.VideoInfoActivity
import dev.aaa1115910.bv.component.LoadingTip
import dev.aaa1115910.bv.component.videocard.SmallVideoCard
import dev.aaa1115910.bv.entity.carddata.VideoCardData
import dev.aaa1115910.bv.entity.proxy.ProxyArea
import dev.aaa1115910.bv.screen.main.ugc.gridItems
import dev.aaa1115910.bv.viewmodel.home.DynamicViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand All @@ -41,7 +36,7 @@ import org.koin.androidx.compose.koinViewModel
@Composable
fun DynamicsScreen(
modifier: Modifier = Modifier,
lazyGridState: LazyGridState,
lazyListState: LazyListState,
dynamicViewModel: DynamicViewModel = koinViewModel()
) {
val context = LocalContext.current
Expand All @@ -51,6 +46,14 @@ fun DynamicsScreen(
derivedStateOf { currentFocusedIndex + 24 > dynamicViewModel.dynamicList.size }
}

val onClickVideo: (DynamicVideo) -> Unit = { dynamic ->
VideoInfoActivity.actionStart(
context = context,
aid = dynamic.aid,
proxyArea = ProxyArea.checkProxyArea(dynamic.title)
)
}

//不能直接使用 LaunchedEffect(currentFocusedIndex),会导致整个页面重组
LaunchedEffect(shouldLoadMore) {
if (shouldLoadMore) {
Expand All @@ -63,39 +66,36 @@ fun DynamicsScreen(
}

if (dynamicViewModel.isLogin) {
LazyVerticalGrid(
LazyColumn(
modifier = modifier,
state = lazyGridState,
columns = GridCells.Fixed(4),
contentPadding = PaddingValues(24.dp),
verticalArrangement = Arrangement.spacedBy(24.dp),
horizontalArrangement = Arrangement.spacedBy(24.dp)
state = lazyListState
) {
itemsIndexed(dynamicViewModel.dynamicList) { index, dynamic ->
SmallVideoCard(
data = VideoCardData(
avid = dynamic.aid,
title = dynamic.title,
cover = dynamic.cover,
play = dynamic.play,
danmaku = dynamic.danmaku,
upName = dynamic.author,
time = dynamic.duration * 1000L
),
onClick = {
VideoInfoActivity.actionStart(
context = context,
aid = dynamic.aid,
proxyArea = ProxyArea.checkProxyArea(dynamic.title)
)
},
onFocus = { currentFocusedIndex = index }
)
}
gridItems(
data = dynamicViewModel.dynamicList,
columnCount = 4,
modifier = Modifier
.width(880.dp)
.padding(horizontal = 24.dp, vertical = 12.dp),
horizontalArrangement = Arrangement.spacedBy(24.dp),
itemContent = { index, item ->
SmallVideoCard(
data = VideoCardData(
avid = item.aid,
title = item.title,
cover = item.cover,
play = item.play,
danmaku = item.danmaku,
upName = item.author,
time = item.duration * 1000L
),
onClick = { onClickVideo(item) },
onFocus = { currentFocusedIndex = index }
)
}
)

if (dynamicViewModel.loading)
item(
span = { GridItemSpan(4) }
) {
item {
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
Expand All @@ -105,9 +105,7 @@ fun DynamicsScreen(
}

if (!dynamicViewModel.hasMore)
item(
span = { GridItemSpan(4) }
) {
item {
Text(
text = "没有更多了捏",
color = Color.White
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ package dev.aaa1115910.bv.screen.main.home

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.GridItemSpan
import androidx.compose.foundation.lazy.grid.LazyGridState
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.itemsIndexed
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.derivedStateOf
Expand All @@ -19,17 +17,14 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.input.key.KeyEventType
import androidx.compose.ui.input.key.key
import androidx.compose.ui.input.key.onPreviewKeyEvent
import androidx.compose.ui.input.key.type
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import dev.aaa1115910.biliapi.entity.ugc.UgcItem
import dev.aaa1115910.bv.activities.video.VideoInfoActivity
import dev.aaa1115910.bv.component.LoadingTip
import dev.aaa1115910.bv.component.videocard.SmallVideoCard
import dev.aaa1115910.bv.entity.carddata.VideoCardData
import dev.aaa1115910.bv.screen.main.ugc.gridItems
import dev.aaa1115910.bv.viewmodel.home.PopularViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand All @@ -38,7 +33,7 @@ import org.koin.androidx.compose.koinViewModel
@Composable
fun PopularScreen(
modifier: Modifier = Modifier,
lazyGridState: LazyGridState,
lazyListState: LazyListState,
popularViewModel: PopularViewModel = koinViewModel()
) {
val context = LocalContext.current
Expand All @@ -48,6 +43,10 @@ fun PopularScreen(
derivedStateOf { currentFocusedIndex + 24 > popularViewModel.popularVideoList.size }
}

val onClickVideo: (UgcItem) -> Unit = { ugcItem ->
VideoInfoActivity.actionStart(context, ugcItem.aid)
}

LaunchedEffect(shouldLoadMore) {
if (shouldLoadMore) {
scope.launch(Dispatchers.IO) {
Expand All @@ -58,33 +57,36 @@ fun PopularScreen(
}
}

LazyVerticalGrid(
LazyColumn(
modifier = modifier,
state = lazyGridState,
columns = GridCells.Fixed(4),
contentPadding = PaddingValues(24.dp),
verticalArrangement = Arrangement.spacedBy(24.dp),
horizontalArrangement = Arrangement.spacedBy(24.dp)
state = lazyListState
) {
itemsIndexed(popularViewModel.popularVideoList) { index, video ->
SmallVideoCard(
data = VideoCardData(
avid = video.aid,
title = video.title,
cover = video.cover,
play = with(video.play) { if (this == -1) null else this },
danmaku = with(video.danmaku) { if (this == -1) null else this },
upName = video.author,
time = video.duration * 1000L
),
onClick = { VideoInfoActivity.actionStart(context, video.aid) },
onFocus = { currentFocusedIndex = index }
)
}
gridItems(
data = popularViewModel.popularVideoList,
columnCount = 4,
modifier = Modifier
.width(880.dp)
.padding(horizontal = 24.dp, vertical = 12.dp),
horizontalArrangement = Arrangement.spacedBy(24.dp),
itemContent = { index, item ->
SmallVideoCard(
data = VideoCardData(
avid = item.aid,
title = item.title,
cover = item.cover,
play = with(item.play) { if (this == -1) null else this },
danmaku = with(item.danmaku) { if (this == -1) null else this },
upName = item.author,
time = item.duration * 1000L
),
onClick = { onClickVideo(item) },
onFocus = { currentFocusedIndex = index }
)
}
)

if (popularViewModel.loading)
item(
span = { GridItemSpan(4) }
) {
item {
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
Expand Down
Loading

0 comments on commit 9b5958b

Please sign in to comment.