Skip to content

Commit

Permalink
feat: 文件夹
Browse files Browse the repository at this point in the history
  • Loading branch information
Greatwallcorner committed Jul 5, 2024
1 parent 0551e17 commit 342dfbf
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ interface VideoComponent {

fun loadMore()

fun clickFolder(vod:Vod)

fun chooseCate(cate: String)

fun clear()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import com.arkivanov.decompose.value.MutableValue
import com.arkivanov.decompose.value.update
import com.arkivanov.essenty.backhandler.BackHandlerOwner
import com.arkivanov.essenty.lifecycle.Lifecycle
import com.corner.catvod.enum.bean.Vod
import com.corner.catvodcore.bean.Filter
import com.corner.catvodcore.bean.Type
import com.corner.catvodcore.bean.getFirstOrEmpty
import com.corner.catvodcore.config.ApiConfig
import com.corner.catvodcore.viewmodel.GlobalModel
import com.corner.ui.decompose.VideoComponent
import com.corner.ui.scene.hideProgress
Expand Down Expand Up @@ -153,6 +155,22 @@ class DefaultVideoComponent(componentContext: ComponentContext) : VideoComponent
}
}

override fun clickFolder(vod: Vod) {
showProgress()
SiteViewModel.viewModelScope.launch {
val result = SiteViewModel.categoryContent(
ApiConfig.api.recent!!,
vod.vodId,
"1",
false,
hashMapOf()
)
model.update { it.copy(homeVodResult = result.list.toMutableSet()) }
}.invokeOnCompletion {
hideProgress()
}
}

override fun loadMore() {
if (model.value.currentClass == null || model.value.currentClass?.typeId == "home") return
if ((model.value.currentClass?.failTime ?: 0) >= 2) return
Expand All @@ -175,6 +193,11 @@ class DefaultVideoComponent(componentContext: ComponentContext) : VideoComponent
return@launch
}
val list = rst.list
// 有的源不支持分页 每次请求返回相同的数据
if(model.value.homeVodResult.map { it.vodId }.containsAll(list.map { it.vodId })){
model.value.currentClass?.failTime = model.value.currentClass?.failTime!! + 1
return@launch
}
model.value.homeVodResult.addAll(list)
model.update { it.copy(homeVodResult = model.value.homeVodResult) }
} finally {
Expand Down
30 changes: 21 additions & 9 deletions composeApp/src/commonMain/kotlin/com/corner/ui/video/Video.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,23 @@ fun VideoItem(modifier: Modifier, vod: Vod, showSite: Boolean, click: (Vod) -> U
elevation = CardDefaults.cardElevation(defaultElevation = 8.dp),
shape = RoundedCornerShape(8.dp)
) {
val picModifier = remember { Modifier.height(220.dp).width(200.dp) }
Box(modifier = modifier) {
AutoSizeImage(url = vod.vodPic ?: "",
modifier = Modifier.height(220.dp).width(200.dp),
contentDescription = vod.vodName,
contentScale = ContentScale.Crop,
placeholderPainter = { painterResource("/pic/empty.png") },
errorPainter = { painterResource("/pic/empty.png") })
if(vod.isFolder()){
Image(
modifier = modifier,
painter = painterResource("/pic/folder-back.png"),
contentDescription = "This is a folder ${vod.vodName}",
contentScale = ContentScale.Fit
)
}else{
AutoSizeImage(url = vod.vodPic ?: "",
modifier = picModifier,
contentDescription = vod.vodName,
contentScale = ContentScale.Crop,
placeholderPainter = { painterResource("/pic/empty.png") },
errorPainter = { painterResource("/pic/empty.png") })
}
Box(Modifier.align(Alignment.BottomCenter)) {
ToolTipText(
text = vod.vodName!!,
Expand Down Expand Up @@ -113,6 +123,10 @@ fun VideoScene(
val model = component.model.subscribeAsState()
val list = derivedStateOf { component.model.value.homeVodResult.toTypedArray() }

LaunchedEffect(list.value){
println("list 修改")
}

LaunchedEffect(state) {
snapshotFlow { state.layoutInfo }
.collect { layoutInfo ->
Expand Down Expand Up @@ -171,9 +185,7 @@ fun VideoScene(
itemsIndexed(list.value, key = { i, item -> item.vodId + item.vodName+i }) { _, item ->
VideoItem(Modifier.animateItemPlacement(), item, false) {
if (item.isFolder()) {
SiteViewModel.viewModelScope.launch {

}
component.clickFolder(it)
} else {
onClickItem(it)
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 342dfbf

Please sign in to comment.