feat(library): Add library preference to show empty categories during search/filtering (#1088)

* feat(library): Add library preference to show empty categories during search/filtering

* Add comment back

* Fix formatting

* subscribe to changes & refactor Regex

* format

---------

Co-authored-by: Cuong-Tran <cuongtran.tm@gmail.com>
This commit is contained in:
Fermín Cirella 2025-09-10 00:02:36 -03:00 committed by GitHub
parent 756da72536
commit 004b63dfb5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 30 additions and 10 deletions

View file

@ -50,6 +50,7 @@ import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
object SettingsLibraryScreen : SearchableSettings { object SettingsLibraryScreen : SearchableSettings {
@Suppress("unused")
private fun readResolve(): Any = SettingsLibraryScreen private fun readResolve(): Any = SettingsLibraryScreen
@Composable @Composable
@ -291,6 +292,12 @@ object SettingsLibraryScreen : SearchableSettings {
preference = libraryPreferences.hideMissingChapters(), preference = libraryPreferences.hideMissingChapters(),
title = stringResource(MR.strings.pref_hide_missing_chapter_indicators), title = stringResource(MR.strings.pref_hide_missing_chapter_indicators),
), ),
// KMK -->
Preference.PreferenceItem.SwitchPreference(
preference = libraryPreferences.showEmptyCategoriesSearch(),
title = stringResource(KMR.strings.pref_show_empty_categories_search),
),
// KMK <--
), ),
) )
} }

View file

@ -252,7 +252,8 @@ class LibraryScreenModel(
combine( combine(
libraryPreferences.sortingMode().changes(), libraryPreferences.sortingMode().changes(),
libraryPreferences.showHiddenCategories().changes(), libraryPreferences.showHiddenCategories().changes(),
::Pair, libraryPreferences.showEmptyCategoriesSearch().changes(),
::Triple,
), ),
combine( combine(
state.map { it.filterCategory }.distinctUntilChanged(), state.map { it.filterCategory }.distinctUntilChanged(),
@ -260,7 +261,7 @@ class LibraryScreenModel(
::Pair, ::Pair,
), ),
// KMK <-- // KMK <--
) { (data, groupType, noActiveFilterOrSearch), (sort, showHiddenCategories), (filterCategory, includedCategories) -> ) { (data, groupType, noActiveFilterOrSearch), (sort, showHiddenCategories, showEmptyCategoriesSearch), (filterCategory, includedCategories) ->
data.favorites data.favorites
.applyGrouping( .applyGrouping(
data.categories, data.categories,
@ -285,7 +286,7 @@ class LibraryScreenModel(
// KMK --> // KMK -->
.filter { .filter {
// Hide empty categories if no active filter or search // Hide empty categories if no active filter or search
noActiveFilterOrSearch || it.value.isNotEmpty() showEmptyCategoriesSearch || noActiveFilterOrSearch || it.value.isNotEmpty()
} }
.let { .let {
// Fall back to default category if no categories are present // Fall back to default category if no categories are present
@ -934,7 +935,6 @@ class LibraryScreenModel(
manga.ogTitle, manga.ogTitle,
// SY <-- // SY <--
manga.source, manga.source,
) )
} }
.let { if (amount != null) it.take(amount) else it } .let { if (amount != null) it.take(amount) else it }
@ -946,17 +946,25 @@ class LibraryScreenModel(
// SY --> // SY -->
fun cleanTitles() { fun cleanTitles() {
val regex1 = "\\[.*?]".toRegex()
val regex2 = "\\(.*?\\)".toRegex()
val regex3 = "\\{.*?\\}".toRegex()
val regex4 = ".*\\|".toRegex()
state.value.selectedManga.fastFilter { state.value.selectedManga.fastFilter {
it.isEhBasedManga() || it.isEhBasedManga() ||
it.source in nHentaiSourceIds it.source in nHentaiSourceIds
}.fastForEach { manga -> }.fastForEach { manga ->
val editedTitle = manga.title.replace("\\[.*?]".toRegex(), "").trim().replace("\\(.*?\\)".toRegex(), "").trim().replace("\\{.*?\\}".toRegex(), "").trim().let { val editedTitle = manga.title
if (it.contains("|")) { .replace(regex1, "").trim()
it.replace(".*\\|".toRegex(), "").trim() .replace(regex2, "").trim()
} else { .replace(regex3, "").trim()
it .let {
if (it.contains("|")) {
it.replace(regex4, "").trim()
} else {
it
}
} }
}
if (manga.title == editedTitle) return@fastForEach if (manga.title == editedTitle) return@fastForEach
val mangaInfo = CustomMangaInfo( val mangaInfo = CustomMangaInfo(
id = manga.id, id = manga.id,

View file

@ -224,6 +224,10 @@ class LibraryPreferences(
fun autoClearChapterCache() = preferenceStore.getBoolean("auto_clear_chapter_cache", false) fun autoClearChapterCache() = preferenceStore.getBoolean("auto_clear_chapter_cache", false)
fun hideMissingChapters() = preferenceStore.getBoolean("pref_hide_missing_chapter_indicators", false) fun hideMissingChapters() = preferenceStore.getBoolean("pref_hide_missing_chapter_indicators", false)
// KMK -->
fun showEmptyCategoriesSearch() = preferenceStore.getBoolean("show_empty_categories_search", false)
// KMK <--
// endregion // endregion
// region Swipe Actions // region Swipe Actions

View file

@ -93,6 +93,7 @@
<string name="action_display_language_icon">Use language icon</string> <string name="action_display_language_icon">Use language icon</string>
<string name="pref_library_filter_categories_details">Entries in excluded categories will not be shown even if they are also in included categories.</string> <string name="pref_library_filter_categories_details">Entries in excluded categories will not be shown even if they are also in included categories.</string>
<string name="updating">Updating</string> <string name="updating">Updating</string>
<string name="pref_show_empty_categories_search">Show empty categories during search/filtering.</string>
<!-- Extension section --> <!-- Extension section -->
<string name="extensions_page_need_refresh">Refresh extension page to update list.</string> <string name="extensions_page_need_refresh">Refresh extension page to update list.</string>
<string name="extensions_page_more">More extensions...</string> <string name="extensions_page_more">More extensions...</string>