mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 13:51:50 +01:00
Fix Filter not being applied in Browse Source (#7945)
This commit is contained in:
parent
99270e370e
commit
6b2b21edfa
@ -100,7 +100,7 @@ fun BrowseSourceScreen(
|
||||
},
|
||||
floatingActionButton = {
|
||||
BrowseSourceFloatingActionButton(
|
||||
isVisible = presenter.filters.isNotEmpty(),
|
||||
isVisible = presenter.filters.isNotEmpty() && presenter.currentFilter is BrowseSourcePresenter.Filter.UserInput,
|
||||
onFabClick = onFabClick,
|
||||
)
|
||||
},
|
||||
@ -126,7 +126,7 @@ fun BrowseSourceScreen(
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
) {
|
||||
FilterChip(
|
||||
selected = presenter.currentQuery == GetRemoteManga.QUERY_POPULAR,
|
||||
selected = presenter.currentFilter == BrowseSourcePresenter.Filter.Popular,
|
||||
onClick = {
|
||||
presenter.resetFilter()
|
||||
presenter.search(GetRemoteManga.QUERY_POPULAR)
|
||||
@ -145,7 +145,7 @@ fun BrowseSourceScreen(
|
||||
)
|
||||
if (presenter.source?.supportsLatest == true) {
|
||||
FilterChip(
|
||||
selected = presenter.currentQuery == GetRemoteManga.QUERY_LATEST,
|
||||
selected = presenter.currentFilter == BrowseSourcePresenter.Filter.Latest,
|
||||
onClick = {
|
||||
presenter.resetFilter()
|
||||
presenter.search(GetRemoteManga.QUERY_LATEST)
|
||||
@ -165,7 +165,7 @@ fun BrowseSourceScreen(
|
||||
}
|
||||
if (presenter.filters.isNotEmpty()) {
|
||||
FilterChip(
|
||||
selected = presenter.currentQuery != GetRemoteManga.QUERY_POPULAR && presenter.currentQuery != GetRemoteManga.QUERY_LATEST,
|
||||
selected = presenter.currentFilter is BrowseSourcePresenter.Filter.UserInput,
|
||||
onClick = onFabClick,
|
||||
leadingIcon = {
|
||||
Icon(
|
||||
|
@ -6,42 +6,36 @@ import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import eu.davidea.flexibleadapter.items.IFlexible
|
||||
import eu.kanade.domain.source.interactor.GetRemoteManga
|
||||
import eu.kanade.tachiyomi.source.CatalogueSource
|
||||
import eu.kanade.tachiyomi.source.model.FilterList
|
||||
import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourcePresenter
|
||||
import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourcePresenter.Filter
|
||||
import eu.kanade.tachiyomi.ui.browse.source.browse.toItems
|
||||
|
||||
@Stable
|
||||
interface BrowseSourceState {
|
||||
val source: CatalogueSource?
|
||||
var searchQuery: String?
|
||||
val currentQuery: String
|
||||
val currentFilter: Filter
|
||||
val isUserQuery: Boolean
|
||||
val filters: FilterList
|
||||
val filterItems: List<IFlexible<*>>
|
||||
val currentFilters: FilterList
|
||||
var dialog: BrowseSourcePresenter.Dialog?
|
||||
}
|
||||
|
||||
fun BrowseSourceState(initialQuery: String?): BrowseSourceState {
|
||||
if (initialQuery == GetRemoteManga.QUERY_POPULAR || initialQuery == GetRemoteManga.QUERY_LATEST) {
|
||||
return BrowseSourceStateImpl(initialCurrentQuery = initialQuery)
|
||||
return when (val filter = Filter.valueOf(initialQuery ?: "")) {
|
||||
Filter.Latest, Filter.Popular -> BrowseSourceStateImpl(initialCurrentFilter = filter)
|
||||
is Filter.UserInput -> BrowseSourceStateImpl(initialQuery = initialQuery, initialCurrentFilter = filter)
|
||||
}
|
||||
return BrowseSourceStateImpl(initialQuery = initialQuery)
|
||||
}
|
||||
|
||||
class BrowseSourceStateImpl(initialQuery: String? = null, initialCurrentQuery: String? = initialQuery) : BrowseSourceState {
|
||||
class BrowseSourceStateImpl(initialQuery: String? = null, initialCurrentFilter: Filter) : BrowseSourceState {
|
||||
override var source: CatalogueSource? by mutableStateOf(null)
|
||||
override var searchQuery: String? by mutableStateOf(initialQuery)
|
||||
override var currentQuery: String by mutableStateOf(initialCurrentQuery ?: "")
|
||||
override val isUserQuery: Boolean by derivedStateOf {
|
||||
currentQuery.isNotEmpty() &&
|
||||
currentQuery != GetRemoteManga.QUERY_POPULAR &&
|
||||
currentQuery != GetRemoteManga.QUERY_LATEST
|
||||
}
|
||||
override var currentFilter: Filter by mutableStateOf(initialCurrentFilter)
|
||||
override val isUserQuery: Boolean by derivedStateOf { currentFilter is Filter.UserInput && currentFilter.query.isNotEmpty() }
|
||||
override var filters: FilterList by mutableStateOf(FilterList())
|
||||
override val filterItems: List<IFlexible<*>> by derivedStateOf { filters.toItems() }
|
||||
override var currentFilters by mutableStateOf(FilterList())
|
||||
override var dialog: BrowseSourcePresenter.Dialog? by mutableStateOf(null)
|
||||
}
|
||||
|
@ -43,12 +43,12 @@ fun BrowseSourceToolbar(
|
||||
) {
|
||||
if (state.searchQuery == null) {
|
||||
BrowseSourceRegularToolbar(
|
||||
title = if (state.isUserQuery) state.currentQuery else source.name,
|
||||
title = if (state.isUserQuery) state.currentFilter.query else source.name,
|
||||
isLocalSource = source is LocalSource,
|
||||
displayMode = displayMode,
|
||||
onDisplayModeChange = onDisplayModeChange,
|
||||
navigateUp = navigateUp,
|
||||
onSearchClick = { state.searchQuery = if (state.isUserQuery) state.currentQuery else "" },
|
||||
onSearchClick = { state.searchQuery = if (state.isUserQuery) state.currentFilter.query else "" },
|
||||
onWebViewClick = onWebViewClick,
|
||||
onHelpClick = onHelpClick,
|
||||
scrollBehavior = scrollBehavior,
|
||||
|
@ -120,11 +120,11 @@ open class BrowseSourcePresenter(
|
||||
|
||||
@Composable
|
||||
fun getMangaList(): Flow<PagingData<DomainManga>> {
|
||||
return remember(currentQuery, currentFilters) {
|
||||
return remember(currentFilter) {
|
||||
Pager(
|
||||
PagingConfig(pageSize = 25),
|
||||
) {
|
||||
getRemoteManga.subscribe(sourceId, currentQuery, currentFilters)
|
||||
getRemoteManga.subscribe(sourceId, currentFilter.query, currentFilter.filters)
|
||||
}.flow
|
||||
.map {
|
||||
it.map {
|
||||
@ -156,13 +156,16 @@ open class BrowseSourcePresenter(
|
||||
}
|
||||
|
||||
fun resetFilter() {
|
||||
val newFilters = source!!.getFilterList()
|
||||
state.filters = newFilters
|
||||
state.currentFilters = state.filters
|
||||
if (currentFilter !is Filter.UserInput) return
|
||||
state.currentFilter = (currentFilter as Filter.UserInput).copy(filters = source!!.getFilterList())
|
||||
}
|
||||
|
||||
fun search(query: String? = null) {
|
||||
state.currentQuery = query ?: searchQuery ?: ""
|
||||
var new = Filter.valueOf(query ?: searchQuery ?: "")
|
||||
if (new is Filter.UserInput && currentFilter is Filter.UserInput) {
|
||||
new = new.copy(filters = currentFilter.filters)
|
||||
}
|
||||
state.currentFilter = new
|
||||
}
|
||||
|
||||
override fun onCreate(savedState: Bundle?) {
|
||||
@ -309,7 +312,10 @@ open class BrowseSourcePresenter(
|
||||
* @param filters a list of active filters.
|
||||
*/
|
||||
fun setSourceFilter(filters: FilterList) {
|
||||
state.currentFilters = filters
|
||||
state.currentFilter = when (val filter = currentFilter) {
|
||||
Filter.Latest, Filter.Popular -> Filter.UserInput(filters = filters)
|
||||
is Filter.UserInput -> filter.copy(filters = filters)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -341,6 +347,22 @@ open class BrowseSourcePresenter(
|
||||
}
|
||||
}
|
||||
|
||||
sealed class Filter(open val query: String, open val filters: FilterList) {
|
||||
object Popular : Filter(query = GetRemoteManga.QUERY_POPULAR, filters = FilterList())
|
||||
object Latest : Filter(query = GetRemoteManga.QUERY_LATEST, filters = FilterList())
|
||||
data class UserInput(override val query: String = "", override val filters: FilterList = FilterList()) : Filter(query = query, filters = filters)
|
||||
|
||||
companion object {
|
||||
fun valueOf(query: String): Filter {
|
||||
return when (query) {
|
||||
GetRemoteManga.QUERY_POPULAR -> Popular
|
||||
GetRemoteManga.QUERY_LATEST -> Latest
|
||||
else -> UserInput(query = query)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sealed class Dialog {
|
||||
data class RemoveManga(val manga: DomainManga) : Dialog()
|
||||
data class AddDuplicateManga(val manga: DomainManga, val duplicate: DomainManga) : Dialog()
|
||||
|
Loading…
Reference in New Issue
Block a user