From 6348cbaeb7dc786309c1ed811ff23114583144a8 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 12 Feb 2023 22:28:12 -0500 Subject: [PATCH] Add option to hide entries already in library when browsing sources Closes #2941 --- .../domain/source/service/SourcePreferences.kt | 2 ++ .../more/settings/screen/SettingsBrowseScreen.kt | 6 +++++- .../source/browse/BrowseSourceScreenModel.kt | 16 +++++++++------- i18n/src/main/res/values/strings.xml | 3 ++- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/eu/kanade/domain/source/service/SourcePreferences.kt b/app/src/main/java/eu/kanade/domain/source/service/SourcePreferences.kt index 626c56544f..c81fa16329 100644 --- a/app/src/main/java/eu/kanade/domain/source/service/SourcePreferences.kt +++ b/app/src/main/java/eu/kanade/domain/source/service/SourcePreferences.kt @@ -31,4 +31,6 @@ class SourcePreferences( fun trustedSignatures() = preferenceStore.getStringSet("trusted_signatures", emptySet()) fun searchPinnedSourcesOnly() = preferenceStore.getBoolean("search_pinned_sources_only", false) + + fun hideInLibraryItems() = preferenceStore.getBoolean("browse_hide_in_library_items", false) } diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsBrowseScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsBrowseScreen.kt index 2e0c8f9cfc..773a896c0a 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsBrowseScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsBrowseScreen.kt @@ -43,12 +43,16 @@ object SettingsBrowseScreen : SearchableSettings { ), ), Preference.PreferenceGroup( - title = stringResource(R.string.action_global_search), + title = stringResource(R.string.label_sources), preferenceItems = listOf( Preference.PreferenceItem.SwitchPreference( pref = sourcePreferences.searchPinnedSourcesOnly(), title = stringResource(R.string.pref_search_pinned_sources_only), ), + Preference.PreferenceItem.SwitchPreference( + pref = sourcePreferences.hideInLibraryItems(), + title = stringResource(R.string.pref_hide_in_library_items), + ), ), ), Preference.PreferenceGroup( diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreenModel.kt index 6c2e5fc575..ef6b1b0613 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreenModel.kt @@ -10,6 +10,7 @@ import androidx.compose.ui.unit.dp import androidx.paging.Pager import androidx.paging.PagingConfig import androidx.paging.cachedIn +import androidx.paging.filter import androidx.paging.map import cafe.adriel.voyager.core.model.StateScreenModel import cafe.adriel.voyager.core.model.coroutineScope @@ -137,16 +138,17 @@ class BrowseSourceScreenModel( PagingConfig(pageSize = 25), ) { getRemoteManga.subscribe(sourceId, listing.query ?: "", listing.filters) - }.flow - .map { pagingData -> - pagingData.map { sManga -> - val dbManga = withIOContext { networkToLocalManga.await(sManga.toDomainManga(sourceId)) } - getManga.subscribe(dbManga.url, dbManga.source) + }.flow.map { pagingData -> + pagingData + .map { withIOContext { networkToLocalManga.await(it.toDomainManga(sourceId)) } } + .filter { !sourcePreferences.hideInLibraryItems().get() || !it.favorite } + .map { + getManga.subscribe(it.url, it.source) .filterNotNull() - .onEach { initializeManga(it) } + .onEach(::initializeManga) .stateIn(coroutineScope) } - } + } .cachedIn(coroutineScope) } .stateIn(coroutineScope, SharingStarted.Lazily, emptyFlow()) diff --git a/i18n/src/main/res/values/strings.xml b/i18n/src/main/res/values/strings.xml index 8036e40586..9c61e0ea7f 100644 --- a/i18n/src/main/res/values/strings.xml +++ b/i18n/src/main/res/values/strings.xml @@ -457,7 +457,8 @@ Check for extension updates - Only include pinned sources + Only search pinned sources in global search + Hide entries already in library Create backup