Skip to content

Commit

Permalink
optimize: 过滤器
Browse files Browse the repository at this point in the history
  • Loading branch information
Greatwallcorner committed Jul 23, 2024
1 parent fe2f730 commit f6a141a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package com.corner.catvodcore.bean
import kotlinx.serialization.Serializable

@Serializable
data class Value(val n:String?=null, var v:String?=null)
data class Value(val n:String?=null, var v:String?=null, var selected:Boolean = false)
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ interface VideoComponent {
result = 31 * result + homeLoaded.hashCode()
result = 31 * result + classList.hashCode()
// classList.forEach{ result = 31 * result + it.hashCode()}
result = 31 * result + currentFilters.hashCode()
result = 31 * result + filtersMap.hashCode()
result = 31 * result + (currentClass?.hashCode() ?: 0)
result = 31 * result + (currentClass?.hashCode() ?: 0)
result = 31 * result + page.hashCode()
result = 31 * result + isRunning.hashCode()
result = 31 * result + prompt.hashCode()
Expand Down
17 changes: 11 additions & 6 deletions composeApp/src/commonMain/kotlin/com/corner/ui/video/Video.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import com.corner.catvodcore.enum.ConfigType
import com.corner.catvodcore.enum.Menu
import com.corner.catvodcore.viewmodel.GlobalModel
import com.corner.database.Db
import com.corner.ui.decompose.VideoComponent
import com.corner.ui.decompose.component.DefaultVideoComponent
import com.corner.ui.scene.*
import com.corner.util.isScrollingUp
Expand Down Expand Up @@ -205,7 +204,7 @@ fun VideoScene(
}
}

FiltersDialog(Modifier.align(Alignment.BottomCenter), showFiltersDialog, model, component) {
FiltersDialog(Modifier.align(Alignment.BottomCenter), showFiltersDialog, component) {
showFiltersDialog = false
}
}
Expand All @@ -217,11 +216,11 @@ fun VideoScene(
private fun FiltersDialog(
modifier: Modifier,
showFiltersDialog: Boolean,
model: State<VideoComponent.Model>,
component: DefaultVideoComponent,
onClose: () -> Unit
) {
val scope = rememberCoroutineScope()
val model = component.model.subscribeAsState()
Dialog(
modifier
.fillMaxWidth(0.7f)
Expand All @@ -241,17 +240,23 @@ private fun FiltersDialog(
) {
items(model.value.currentFilters) { filter ->
val state = rememberLazyListState(0)
val f = rememberUpdatedState(filter)
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)
}
}) {
items(filter.value ?: listOf()) {
items(f.value.value ?: listOf()) {
RatioBtn(it.n ?: "", onClick = {
filter.init = it.v ?: ""
scope.launch {
f.value.init = it.v ?: ""
f.value.value?.filter { i -> i.n != it.n }?.map { t -> t.selected = false }
it.selected = true
component.model.update { it.copy(currentFilters = model.value.currentFilters) }
}
component.chooseCate(it.v ?: "")
}, selected = it.v == filter.init, loading = false)
}, selected = it.selected, loading = false)
}
}
}
Expand Down

0 comments on commit f6a141a

Please sign in to comment.