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

View file

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

View file

@ -93,6 +93,7 @@
<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="updating">Updating</string>
<string name="pref_show_empty_categories_search">Show empty categories during search/filtering.</string>
<!-- Extension section -->
<string name="extensions_page_need_refresh">Refresh extension page to update list.</string>
<string name="extensions_page_more">More extensions...</string>