Skip to content

Commit

Permalink
feat: 文件夹支持路径跳转
Browse files Browse the repository at this point in the history
  • Loading branch information
Greatwallcorner committed Dec 7, 2024
1 parent 8258241 commit 26fd3db
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class DefaultVideoComponent(componentContext: ComponentContext) : VideoComponent
showProgress()
SiteViewModel.viewModelScope.launch {
val result = loadCate(vod.vodId)
model.update { it.copy(homeVodResult = result.list.toMutableSet(), dirPaths = mutableListOf<String>().apply { addAll(it.dirPaths); addAll(vod.vodId.split("/")) }) }
model.update { it.copy(homeVodResult = result.list.toMutableSet(), dirPaths = mutableListOf<String>().apply { addAll(vod.vodId.split("/")) }) }
}.invokeOnCompletion {
hideProgress()
}
Expand Down
112 changes: 77 additions & 35 deletions composeApp/src/commonMain/kotlin/com/corner/ui/video/Video.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import com.corner.util.isScrollingUp
import com.seiko.imageloader.ui.AutoSizeImage
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import javax.swing.Box

@Composable
fun VideoItem(modifier: Modifier, vod: Vod, showSite: Boolean, click: (Vod) -> Unit) {
Expand All @@ -74,7 +75,8 @@ fun VideoItem(modifier: Modifier, vod: Vod, showSite: Boolean, click: (Vod) -> U
contentScale = ContentScale.Fit
)
} else {
AutoSizeImage(url = vod.vodPic ?: "",
AutoSizeImage(
url = vod.vodPic ?: "",
modifier = picModifier,
contentDescription = vod.vodName,
contentScale = ContentScale.Crop,
Expand Down Expand Up @@ -207,37 +209,72 @@ fun WindowScope.VideoScene(
FiltersDialog(Modifier.align(Alignment.BottomCenter), showFiltersDialog, component) {
showFiltersDialog = false
}

DirPath(component = component)
}
}
}

//@OptIn(ExperimentalAnimationApi::class)
@Composable
fun DirPath(showDialog: Boolean = false, component: DefaultVideoComponent){
val state = component.model.subscribeAsState()
val show = derivedStateOf {
state.value.dirPaths.size > 1
}
AnimatedVisibility(show.value,){
Surface(modifier = Modifier.height(80.dp).fillMaxHeight(0.3f)
.shadow(8.dp, shape = RoundedCornerShape(10.dp)),
shape = RoundedCornerShape(10.dp)
) {
LazyRow {
items(state.value.dirPaths){
HoverableText(text = it){
SiteViewModel.viewModelScope.launch {
component.clickFolder(Vod(vodId = state.value.dirPaths.subList(0, state.value.dirPaths.indexOf(it)).joinToString("/")))
val show = derivedStateOf {
model.value.dirPaths.size > 1
}
AnimatedVisibility(show.value) {
Box(Modifier.fillMaxSize()) {
Surface(
modifier = Modifier.wrapContentHeight()
.wrapContentWidth()
.align(Alignment.BottomStart)
.shadow(8.dp, shape = RoundedCornerShape(10.dp))
.padding(1.dp),
shape = RoundedCornerShape(10.dp)
) {
LazyRow {
items(model.value.dirPaths) {
HoverableText(text = it) {
SiteViewModel.viewModelScope.launch {
component.clickFolder(
Vod(
vodId = model.value.dirPaths.subList(
0,
model.value.dirPaths.indexOf(it) + 1
).joinToString("/")
)
)
}
}
Text(text = "/")
}
}
}
}
}

// DirPath(component = component)
}
}
}

//@OptIn(ExperimentalAnimationApi::class)
//@Composable
//fun DirPath(showDialog: Boolean = false, component: DefaultVideoComponent){
// val state = component.model.subscribeAsState()
// val show = derivedStateOf {
// state.value.dirPaths.size > 1
// }
// AnimatedVisibility(show.value){
// Box(modifier = Modifier.height(80.dp)
// .fillMaxHeight(0.3f)
// .align(Alignment.BottomStart)
// .shadow(8.dp, shape = RoundedCornerShape(10.dp)),
// shape = RoundedCornerShape(10.dp)
// ) {
// LazyRow {
// items(state.value.dirPaths){
// HoverableText(text = it){
// SiteViewModel.viewModelScope.launch {
// component.clickFolder(Vod(vodId = state.value.dirPaths.subList(0, state.value.dirPaths.indexOf(it)).joinToString("/")))
// }
// }
// }
// }
// }
// }
//}

@OptIn(ExperimentalComposeUiApi::class)
@Composable
private fun FiltersDialog(
Expand Down Expand Up @@ -268,7 +305,8 @@ private fun FiltersDialog(
items(model.value.currentFilters) { filter ->
val state = rememberLazyListState(0)
val f = rememberUpdatedState(filter)
LazyRow(state = state, horizontalArrangement = Arrangement.spacedBy(5.dp),
LazyRow(
state = state, horizontalArrangement = Arrangement.spacedBy(5.dp),
modifier = Modifier.onPointerEvent(PointerEventType.Scroll) {
scope.launch {
state.scrollBy(it.changes.first().scrollDelta.y * state.layoutInfo.visibleItemsInfo.first().size)
Expand Down Expand Up @@ -327,7 +365,8 @@ fun FloatButton(
.padding(10.dp)
) {
Box(Modifier.align(Alignment.BottomEnd)) {
AnimatedContent(state.isScrollingUp(),
AnimatedContent(
state.isScrollingUp(),
contentAlignment = Alignment.BottomEnd,
transitionSpec = { fadeIn() togetherWith fadeOut() }
) {
Expand Down Expand Up @@ -414,13 +453,14 @@ fun VideoTopBar(
}
},
center = {
Box(modifier = Modifier
.fillMaxWidth(0.3f)
.fillMaxHeight(0.6f)
.background(Color.Gray.copy(alpha = 0.3f), shape = RoundedCornerShape(percent = 50))
.clickable {
onClickSearch()
}) {
Box(
modifier = Modifier
.fillMaxWidth(0.3f)
.fillMaxHeight(0.6f)
.background(Color.Gray.copy(alpha = 0.3f), shape = RoundedCornerShape(percent = 50))
.clickable {
onClickSearch()
}) {
AnimatedContent(
targetState = model.value.prompt,
contentAlignment = Alignment.Center,
Expand Down Expand Up @@ -507,7 +547,8 @@ fun ClassRow(component: DefaultVideoComponent, onCLick: (Type) -> Unit) {
it.copy(
currentClass = type,
classList = model.value.classList,
currentFilters = component.getFilters(type)
currentFilters = component.getFilters(type),
dirPaths = mutableListOf()
)
}
SiteViewModel.cancelAll()
Expand Down Expand Up @@ -574,7 +615,8 @@ fun ChooseHomeDialog(
state = lazyListState
) {
items(items = ApiConfig.api.sites.toList()) { item ->
OutlinedButton(modifier = Modifier.width(180.dp),
OutlinedButton(
modifier = Modifier.width(180.dp),
onClick = {
SiteViewModel.viewModelScope.launch {
ApiConfig.setHome(item)
Expand Down

0 comments on commit 26fd3db

Please sign in to comment.