Add authors to filter
This commit is contained in:
@@ -34,6 +34,9 @@ abstract class MangaDao {
|
|||||||
@Query("SELECT author FROM manga WHERE author LIKE :query GROUP BY author ORDER BY COUNT(author) DESC LIMIT :limit")
|
@Query("SELECT author FROM manga WHERE author LIKE :query GROUP BY author ORDER BY COUNT(author) DESC LIMIT :limit")
|
||||||
abstract suspend fun findAuthors(query: String, limit: Int): List<String>
|
abstract suspend fun findAuthors(query: String, limit: Int): List<String>
|
||||||
|
|
||||||
|
@Query("SELECT author FROM manga WHERE manga.source = :source AND author IS NOT NULL AND author != '' GROUP BY author ORDER BY COUNT(author) DESC LIMIT :limit")
|
||||||
|
abstract suspend fun findAuthorsBySource(source: String, limit: Int): List<String>
|
||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
@Query("SELECT * FROM manga WHERE (title LIKE :query OR alt_title LIKE :query) AND manga_id IN (SELECT manga_id FROM favourites UNION SELECT manga_id FROM history) LIMIT :limit")
|
@Query("SELECT * FROM manga WHERE (title LIKE :query OR alt_title LIKE :query) AND manga_id IN (SELECT manga_id FROM favourites UNION SELECT manga_id FROM history) LIMIT :limit")
|
||||||
abstract suspend fun searchByTitle(query: String, limit: Int): List<MangaWithTags>
|
abstract suspend fun searchByTitle(query: String, limit: Int): List<MangaWithTags>
|
||||||
|
|||||||
@@ -124,6 +124,20 @@ class FilterCoordinator @Inject constructor(
|
|||||||
MutableStateFlow(FilterProperty.EMPTY)
|
MutableStateFlow(FilterProperty.EMPTY)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val authors: StateFlow<FilterProperty<String>> = if (capabilities.isAuthorSearchSupported) {
|
||||||
|
combine(
|
||||||
|
flow { emit(searchRepository.getAuthors(repository.source, TAGS_LIMIT)) },
|
||||||
|
currentListFilter.distinctUntilChangedBy { it.author },
|
||||||
|
) { available, selected ->
|
||||||
|
FilterProperty(
|
||||||
|
availableItems = available,
|
||||||
|
selectedItems = setOfNotNull(selected.author),
|
||||||
|
)
|
||||||
|
}.stateIn(coroutineScope, SharingStarted.Lazily, FilterProperty.LOADING)
|
||||||
|
} else {
|
||||||
|
MutableStateFlow(FilterProperty.EMPTY)
|
||||||
|
}
|
||||||
|
|
||||||
val states: StateFlow<FilterProperty<MangaState>> = combine(
|
val states: StateFlow<FilterProperty<MangaState>> = combine(
|
||||||
filterOptions.asFlow(),
|
filterOptions.asFlow(),
|
||||||
currentListFilter.distinctUntilChangedBy { it.states },
|
currentListFilter.distinctUntilChangedBy { it.states },
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ class FilterSheetFragment : BaseAdaptiveSheet<SheetFilterBinding>(),
|
|||||||
filter.originalLocale.observe(viewLifecycleOwner, this::onOriginalLocaleChanged)
|
filter.originalLocale.observe(viewLifecycleOwner, this::onOriginalLocaleChanged)
|
||||||
filter.tags.observe(viewLifecycleOwner, this::onTagsChanged)
|
filter.tags.observe(viewLifecycleOwner, this::onTagsChanged)
|
||||||
filter.tagsExcluded.observe(viewLifecycleOwner, this::onTagsExcludedChanged)
|
filter.tagsExcluded.observe(viewLifecycleOwner, this::onTagsExcludedChanged)
|
||||||
|
filter.authors.observe(viewLifecycleOwner, this::onAuthorsChanged)
|
||||||
filter.states.observe(viewLifecycleOwner, this::onStateChanged)
|
filter.states.observe(viewLifecycleOwner, this::onStateChanged)
|
||||||
filter.contentTypes.observe(viewLifecycleOwner, this::onContentTypesChanged)
|
filter.contentTypes.observe(viewLifecycleOwner, this::onContentTypesChanged)
|
||||||
filter.contentRating.observe(viewLifecycleOwner, this::onContentRatingChanged)
|
filter.contentRating.observe(viewLifecycleOwner, this::onContentRatingChanged)
|
||||||
@@ -103,6 +104,7 @@ class FilterSheetFragment : BaseAdaptiveSheet<SheetFilterBinding>(),
|
|||||||
binding.chipsDemographics.onChipClickListener = this
|
binding.chipsDemographics.onChipClickListener = this
|
||||||
binding.chipsGenres.onChipClickListener = this
|
binding.chipsGenres.onChipClickListener = this
|
||||||
binding.chipsGenresExclude.onChipClickListener = this
|
binding.chipsGenresExclude.onChipClickListener = this
|
||||||
|
binding.chipsAuthor.onChipClickListener = this
|
||||||
binding.chipsSavedFilters.onChipLongClickListener = this
|
binding.chipsSavedFilters.onChipLongClickListener = this
|
||||||
binding.chipsSavedFilters.onChipCloseClickListener = this
|
binding.chipsSavedFilters.onChipCloseClickListener = this
|
||||||
binding.sliderYear.addOnChangeListener(this::onSliderValueChange)
|
binding.sliderYear.addOnChangeListener(this::onSliderValueChange)
|
||||||
@@ -199,6 +201,11 @@ class FilterSheetFragment : BaseAdaptiveSheet<SheetFilterBinding>(),
|
|||||||
is ContentRating -> filter.toggleContentRating(data, !chip.isChecked)
|
is ContentRating -> filter.toggleContentRating(data, !chip.isChecked)
|
||||||
is Demographic -> filter.toggleDemographic(data, !chip.isChecked)
|
is Demographic -> filter.toggleDemographic(data, !chip.isChecked)
|
||||||
is PersistableFilter -> filter.setAdjusted(data.filter)
|
is PersistableFilter -> filter.setAdjusted(data.filter)
|
||||||
|
is String -> if (chip.isChecked) {
|
||||||
|
filter.setAuthor(null)
|
||||||
|
} else {
|
||||||
|
filter.setAuthor(data)
|
||||||
|
}
|
||||||
null -> router.showTagsCatalogSheet(excludeMode = chip.parentView?.id == R.id.chips_genresExclude)
|
null -> router.showTagsCatalogSheet(excludeMode = chip.parentView?.id == R.id.chips_genresExclude)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -312,6 +319,22 @@ class FilterSheetFragment : BaseAdaptiveSheet<SheetFilterBinding>(),
|
|||||||
b.chipsGenresExclude.setChips(chips)
|
b.chipsGenresExclude.setChips(chips)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun onAuthorsChanged(value: FilterProperty<String>) {
|
||||||
|
val b = viewBinding ?: return
|
||||||
|
b.layoutAuthor.isGone = value.isEmpty()
|
||||||
|
if (value.isEmpty()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val chips = value.availableItems.map { author ->
|
||||||
|
ChipsView.ChipModel(
|
||||||
|
title = author,
|
||||||
|
isChecked = author in value.selectedItems,
|
||||||
|
data = author,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
b.chipsAuthor.setChips(chips)
|
||||||
|
}
|
||||||
|
|
||||||
private fun onStateChanged(value: FilterProperty<MangaState>) {
|
private fun onStateChanged(value: FilterProperty<MangaState>) {
|
||||||
val b = viewBinding ?: return
|
val b = viewBinding ?: return
|
||||||
b.layoutState.isGone = value.isEmpty()
|
b.layoutState.isGone = value.isEmpty()
|
||||||
|
|||||||
@@ -169,4 +169,8 @@ class MangaSearchRepository @Inject constructor(
|
|||||||
null,
|
null,
|
||||||
)?.use { cursor -> cursor.count } ?: 0
|
)?.use { cursor -> cursor.count } ?: 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun getAuthors(source: MangaSource, limit: Int): List<String> {
|
||||||
|
return db.getMangaDao().findAuthorsBySource(source.name, limit)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -162,6 +162,24 @@
|
|||||||
|
|
||||||
</org.koitharu.kotatsu.filter.ui.FilterFieldLayout>
|
</org.koitharu.kotatsu.filter.ui.FilterFieldLayout>
|
||||||
|
|
||||||
|
<org.koitharu.kotatsu.filter.ui.FilterFieldLayout
|
||||||
|
android:id="@+id/layout_author"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="@dimen/margin_small"
|
||||||
|
app:showMoreButton="false"
|
||||||
|
app:title="@string/author">
|
||||||
|
|
||||||
|
<org.koitharu.kotatsu.core.ui.widgets.ChipsView
|
||||||
|
android:id="@+id/chips_author"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginHorizontal="@dimen/margin_small"
|
||||||
|
android:layout_marginTop="@dimen/margin_small"
|
||||||
|
app:chipStyle="@style/Widget.Kotatsu.Chip.Filter" />
|
||||||
|
|
||||||
|
</org.koitharu.kotatsu.filter.ui.FilterFieldLayout>
|
||||||
|
|
||||||
<org.koitharu.kotatsu.filter.ui.FilterFieldLayout
|
<org.koitharu.kotatsu.filter.ui.FilterFieldLayout
|
||||||
android:id="@+id/layout_types"
|
android:id="@+id/layout_types"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|||||||
Reference in New Issue
Block a user