mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-08-09 16:38:10 +00:00
fix(search): discover state reuse logic in SearchRepository
This commit is contained in:
parent
9bb4c341df
commit
da7053f426
1 changed files with 26 additions and 1 deletions
|
|
@ -127,6 +127,11 @@ object SearchRepository {
|
|||
}
|
||||
|
||||
val sources = buildDiscoverSources(activeAddons)
|
||||
val current = _discoverUiState.value
|
||||
if (sources == discoverSources && current.canReuseDiscoverState(sources)) {
|
||||
return
|
||||
}
|
||||
|
||||
discoverSources = sources
|
||||
if (sources.isEmpty()) {
|
||||
activeDiscoverJob?.cancel()
|
||||
|
|
@ -136,7 +141,6 @@ object SearchRepository {
|
|||
return
|
||||
}
|
||||
|
||||
val current = _discoverUiState.value
|
||||
val typeOptions = sources.map { it.type }.distinct()
|
||||
val selectedType = current.selectedType
|
||||
?.takeIf { type -> typeOptions.contains(type) }
|
||||
|
|
@ -404,6 +408,27 @@ private fun DiscoverCatalogOption.resolveGenreSelection(requestedGenre: String?)
|
|||
else -> null
|
||||
}
|
||||
|
||||
private fun DiscoverUiState.canReuseDiscoverState(
|
||||
sources: List<DiscoverCatalogOption>,
|
||||
): Boolean {
|
||||
val currentType = selectedType ?: return false
|
||||
if (!typeOptions.contains(currentType) || !sources.any { it.type == currentType }) {
|
||||
return false
|
||||
}
|
||||
|
||||
val currentCatalog = sources.firstOrNull { it.key == selectedCatalogKey } ?: return false
|
||||
if (currentCatalog.type != currentType) {
|
||||
return false
|
||||
}
|
||||
|
||||
val resolvedGenre = currentCatalog.resolveGenreSelection(selectedGenre)
|
||||
if (selectedGenre != resolvedGenre) {
|
||||
return false
|
||||
}
|
||||
|
||||
return isLoading || items.isNotEmpty() || emptyStateReason != null || errorMessage != null || nextSkip != null
|
||||
}
|
||||
|
||||
private fun String.displayLabel(): String =
|
||||
replaceFirstChar { char ->
|
||||
if (char.isLowerCase()) char.titlecase() else char.toString()
|
||||
|
|
|
|||
Loading…
Reference in a new issue