Fix applying filter
This commit is contained in:
@@ -267,32 +267,50 @@ class FilterCoordinator @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun setQuery(value: String?) {
|
fun setQuery(value: String?) {
|
||||||
|
val newQuery = value?.trim()?.takeUnless { it.isEmpty() }
|
||||||
currentListFilter.update { oldValue ->
|
currentListFilter.update { oldValue ->
|
||||||
oldValue.copy(query = value?.trim()?.takeUnless { it.isEmpty() })
|
if (capabilities.isSearchWithFiltersSupported || newQuery == null) {
|
||||||
|
oldValue.copy(query = newQuery)
|
||||||
|
} else {
|
||||||
|
MangaListFilter(query = newQuery)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setLocale(value: Locale?) {
|
fun setLocale(value: Locale?) {
|
||||||
currentListFilter.update { oldValue ->
|
currentListFilter.update { oldValue ->
|
||||||
oldValue.copy(locale = value)
|
oldValue.copy(
|
||||||
|
locale = value,
|
||||||
|
query = oldValue.takeQueryIfSupported(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setOriginalLocale(value: Locale?) {
|
fun setOriginalLocale(value: Locale?) {
|
||||||
currentListFilter.update { oldValue ->
|
currentListFilter.update { oldValue ->
|
||||||
oldValue.copy(originalLocale = value)
|
oldValue.copy(
|
||||||
|
originalLocale = value,
|
||||||
|
query = oldValue.takeQueryIfSupported(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setYear(value: Int) {
|
fun setYear(value: Int) {
|
||||||
currentListFilter.update { oldValue ->
|
currentListFilter.update { oldValue ->
|
||||||
oldValue.copy(year = value)
|
oldValue.copy(
|
||||||
|
year = value,
|
||||||
|
query = oldValue.takeQueryIfSupported(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setYearRange(valueFrom: Int, valueTo: Int) {
|
fun setYearRange(valueFrom: Int, valueTo: Int) {
|
||||||
currentListFilter.update { oldValue ->
|
currentListFilter.update { oldValue ->
|
||||||
oldValue.copy(yearFrom = valueFrom, yearTo = valueTo)
|
oldValue.copy(
|
||||||
|
yearFrom = valueFrom,
|
||||||
|
yearTo = valueTo,
|
||||||
|
query = oldValue.takeQueryIfSupported(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -300,6 +318,7 @@ class FilterCoordinator @Inject constructor(
|
|||||||
currentListFilter.update { oldValue ->
|
currentListFilter.update { oldValue ->
|
||||||
oldValue.copy(
|
oldValue.copy(
|
||||||
states = if (isSelected) oldValue.states + value else oldValue.states - value,
|
states = if (isSelected) oldValue.states + value else oldValue.states - value,
|
||||||
|
query = oldValue.takeQueryIfSupported(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -308,6 +327,7 @@ class FilterCoordinator @Inject constructor(
|
|||||||
currentListFilter.update { oldValue ->
|
currentListFilter.update { oldValue ->
|
||||||
oldValue.copy(
|
oldValue.copy(
|
||||||
contentRating = if (isSelected) oldValue.contentRating + value else oldValue.contentRating - value,
|
contentRating = if (isSelected) oldValue.contentRating + value else oldValue.contentRating - value,
|
||||||
|
query = oldValue.takeQueryIfSupported(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -316,6 +336,7 @@ class FilterCoordinator @Inject constructor(
|
|||||||
currentListFilter.update { oldValue ->
|
currentListFilter.update { oldValue ->
|
||||||
oldValue.copy(
|
oldValue.copy(
|
||||||
types = if (isSelected) oldValue.types + value else oldValue.types - value,
|
types = if (isSelected) oldValue.types + value else oldValue.types - value,
|
||||||
|
query = oldValue.takeQueryIfSupported(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -330,6 +351,7 @@ class FilterCoordinator @Inject constructor(
|
|||||||
oldValue.copy(
|
oldValue.copy(
|
||||||
tags = newTags,
|
tags = newTags,
|
||||||
tagsExclude = oldValue.tagsExclude - newTags,
|
tagsExclude = oldValue.tagsExclude - newTags,
|
||||||
|
query = oldValue.takeQueryIfSupported(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -344,6 +366,7 @@ class FilterCoordinator @Inject constructor(
|
|||||||
oldValue.copy(
|
oldValue.copy(
|
||||||
tags = oldValue.tags - newTagsExclude,
|
tags = oldValue.tags - newTagsExclude,
|
||||||
tagsExclude = newTagsExclude,
|
tagsExclude = newTagsExclude,
|
||||||
|
query = oldValue.takeQueryIfSupported(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -352,6 +375,13 @@ class FilterCoordinator @Inject constructor(
|
|||||||
it.map { x -> x.availableTags.sortedWithSafe(TagTitleComparator(sourceLocale)) }
|
it.map { x -> x.availableTags.sortedWithSafe(TagTitleComparator(sourceLocale)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun MangaListFilter.takeQueryIfSupported() = when {
|
||||||
|
capabilities.isSearchWithFiltersSupported -> query
|
||||||
|
query.isNullOrEmpty() -> query
|
||||||
|
hasNonSearchOptions() -> null
|
||||||
|
else -> query
|
||||||
|
}
|
||||||
|
|
||||||
private fun getTopTags(limit: Int): Flow<Result<List<MangaTag>>> = combine(
|
private fun getTopTags(limit: Int): Flow<Result<List<MangaTag>>> = combine(
|
||||||
flow { emit(searchRepository.getTopTags(repository.source, limit)) },
|
flow { emit(searchRepository.getTopTags(repository.source, limit)) },
|
||||||
filterOptions.asFlow(),
|
filterOptions.asFlow(),
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import com.google.android.material.chip.Chip
|
|||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.flowOn
|
import kotlinx.coroutines.flow.flowOn
|
||||||
import org.koitharu.kotatsu.R
|
|
||||||
import org.koitharu.kotatsu.core.ui.BaseFragment
|
import org.koitharu.kotatsu.core.ui.BaseFragment
|
||||||
import org.koitharu.kotatsu.core.ui.widgets.ChipsView
|
import org.koitharu.kotatsu.core.ui.widgets.ChipsView
|
||||||
import org.koitharu.kotatsu.core.util.ext.isAnimationsEnabled
|
import org.koitharu.kotatsu.core.util.ext.isAnimationsEnabled
|
||||||
@@ -19,7 +18,6 @@ import org.koitharu.kotatsu.filter.ui.model.FilterHeaderModel
|
|||||||
import org.koitharu.kotatsu.filter.ui.tags.TagsCatalogSheet
|
import org.koitharu.kotatsu.filter.ui.tags.TagsCatalogSheet
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaTag
|
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import com.google.android.material.R as materialR
|
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class FilterHeaderFragment : BaseFragment<FragmentFilterHeaderBinding>(), ChipsView.OnChipClickListener,
|
class FilterHeaderFragment : BaseFragment<FragmentFilterHeaderBinding>(), ChipsView.OnChipClickListener,
|
||||||
@@ -68,17 +66,12 @@ class FilterHeaderFragment : BaseFragment<FragmentFilterHeaderBinding>(), ChipsV
|
|||||||
binding.root.isVisible = false
|
binding.root.isVisible = false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
binding.chipsTags.setChips(header.chips)
|
||||||
|
binding.root.isVisible = true
|
||||||
if (binding.root.context.isAnimationsEnabled) {
|
if (binding.root.context.isAnimationsEnabled) {
|
||||||
binding.scrollView.smoothScrollTo(0, 0)
|
binding.scrollView.smoothScrollTo(0, 0)
|
||||||
} else {
|
} else {
|
||||||
binding.scrollView.scrollTo(0, 0)
|
binding.scrollView.scrollTo(0, 0)
|
||||||
}
|
}
|
||||||
binding.chipsTags.setChips(header.chips + moreTagsChip())
|
|
||||||
binding.root.isVisible = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun moreTagsChip() = ChipsView.ChipModel(
|
|
||||||
title = getString(R.string.more),
|
|
||||||
icon = materialR.drawable.abc_ic_menu_overflow_material,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.koitharu.kotatsu.filter.ui
|
|||||||
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.ui.widgets.ChipsView
|
import org.koitharu.kotatsu.core.ui.widgets.ChipsView
|
||||||
import org.koitharu.kotatsu.filter.ui.model.FilterHeaderModel
|
import org.koitharu.kotatsu.filter.ui.model.FilterHeaderModel
|
||||||
import org.koitharu.kotatsu.filter.ui.model.FilterProperty
|
import org.koitharu.kotatsu.filter.ui.model.FilterProperty
|
||||||
@@ -86,6 +87,16 @@ class FilterHeaderProducer @Inject constructor(
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
val hasTags = result.any { it.data is MangaTag }
|
||||||
|
if (hasTags) {
|
||||||
|
result.addLast(moreTagsChip())
|
||||||
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun moreTagsChip() = ChipsView.ChipModel(
|
||||||
|
titleResId = R.string.more,
|
||||||
|
isDropdown = true,
|
||||||
|
// icon = materialR.drawable.abc_ic_menu_overflow_material,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user