修复发现某些点击项错误响应的问题
This commit is contained in:
@@ -53,6 +53,7 @@ import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import io.legado.app.R
|
||||
import io.legado.app.data.entities.BookSourcePart
|
||||
import io.legado.app.help.source.getExploreInfoMap
|
||||
import io.legado.app.ui.widget.components.explore.ExploreKindUiUseCase
|
||||
import io.legado.app.ui.book.search.SearchActivity
|
||||
import io.legado.app.ui.book.search.SearchScope
|
||||
@@ -77,8 +78,10 @@ import io.legado.app.ui.widget.components.menuItem.RoundDropdownMenu
|
||||
import io.legado.app.ui.widget.components.menuItem.RoundDropdownMenuItem
|
||||
import io.legado.app.ui.widget.components.text.AppText
|
||||
import io.legado.app.utils.startActivity
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.collect
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.koin.androidx.compose.koinViewModel
|
||||
import org.koin.compose.koinInject
|
||||
import top.yukonga.miuix.kmp.theme.MiuixTheme
|
||||
@@ -104,13 +107,17 @@ fun ExploreScreen(
|
||||
viewModel.effects.collect { effect ->
|
||||
when (effect) {
|
||||
is ExploreEffect.ExecuteKindAction -> {
|
||||
exploreKindUseCase.executeAction(
|
||||
action = effect.kind.action,
|
||||
title = effect.kind.title,
|
||||
sourceUrl = effect.sourceUrl,
|
||||
activity = activity,
|
||||
onRefreshKinds = { viewModel.refreshExploreKinds(effect.sourceUrl) }
|
||||
)
|
||||
withContext(Dispatchers.IO) {
|
||||
val infoMap = getExploreInfoMap(effect.sourceUrl)
|
||||
exploreKindUseCase.executeAction(
|
||||
action = effect.kind.action,
|
||||
title = effect.kind.title,
|
||||
sourceUrl = effect.sourceUrl,
|
||||
infoMap = infoMap,
|
||||
activity = activity,
|
||||
onRefreshKinds = { viewModel.refreshExploreKinds(effect.sourceUrl) }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -201,13 +208,7 @@ fun ExploreScreen(
|
||||
) {
|
||||
items(
|
||||
items = uiState.listItems,
|
||||
key = { it.key },
|
||||
contentType = {
|
||||
when (it) {
|
||||
is ExploreListItem.Header -> "source-header"
|
||||
is ExploreListItem.KindRow -> "kind-row"
|
||||
}
|
||||
}
|
||||
key = { it.key }
|
||||
) { listItem ->
|
||||
when (listItem) {
|
||||
is ExploreListItem.Header -> {
|
||||
|
||||
@@ -21,8 +21,6 @@ import kotlinx.collections.immutable.persistentSetOf
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
import kotlinx.collections.immutable.toImmutableMap
|
||||
import kotlinx.coroutines.Dispatchers.IO
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.FlowPreview
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
@@ -30,10 +28,6 @@ import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asSharedFlow
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.debounce
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.flatMapLatest
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
@@ -53,8 +47,7 @@ class ExploreViewModel(
|
||||
private val _effects = MutableSharedFlow<ExploreEffect>(extraBufferCapacity = 8)
|
||||
val effects = _effects.asSharedFlow()
|
||||
|
||||
private val searchKeyFlow = MutableStateFlow("")
|
||||
private val groupFlow = MutableStateFlow("")
|
||||
private var exploreJob: Job? = null
|
||||
private var kindsJob: Job? = null
|
||||
|
||||
init {
|
||||
@@ -73,13 +66,13 @@ class ExploreViewModel(
|
||||
}
|
||||
|
||||
fun search(key: String) {
|
||||
searchKeyFlow.value = key
|
||||
_uiState.update { it.copy(searchKey = key, expandedId = null) }
|
||||
observeExplore()
|
||||
}
|
||||
|
||||
fun setGroup(group: String) {
|
||||
groupFlow.value = group
|
||||
_uiState.update { it.copy(selectedGroup = group, expandedId = null) }
|
||||
observeExplore()
|
||||
}
|
||||
|
||||
fun toggleSearchVisible(visible: Boolean) {
|
||||
@@ -89,20 +82,14 @@ class ExploreViewModel(
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class)
|
||||
private fun observeExplore() {
|
||||
viewModelScope.launch {
|
||||
combine(
|
||||
searchKeyFlow
|
||||
.debounce(250)
|
||||
.distinctUntilChanged(),
|
||||
groupFlow
|
||||
) { query, selectedGroup ->
|
||||
query to selectedGroup
|
||||
}
|
||||
.flatMapLatest { (query, selectedGroup) ->
|
||||
exploreRepository.getExploreSources(query, selectedGroup)
|
||||
}
|
||||
exploreJob?.cancel()
|
||||
exploreJob = viewModelScope.launch {
|
||||
val state = _uiState.value
|
||||
val query = state.searchKey
|
||||
val selectedGroup = state.selectedGroup
|
||||
|
||||
exploreRepository.getExploreSources(query, selectedGroup)
|
||||
.flowOn(IO)
|
||||
.collectLatest { items ->
|
||||
_uiState.update { it.copy(items = items.toImmutableList()) }
|
||||
|
||||
@@ -73,7 +73,7 @@ fun ExploreKindItem(
|
||||
modifier = modifier,
|
||||
border = if (enableBorder) {
|
||||
BorderStroke(borderWidth, borderColor)
|
||||
} else BorderStroke(1.dp, LegadoTheme.colorScheme.outline)
|
||||
} else BorderStroke(1.dp, LegadoTheme.colorScheme.outlineVariant)
|
||||
) {
|
||||
KindText(
|
||||
text = displayText,
|
||||
|
||||
Reference in New Issue
Block a user