Add option to hide entries already in library when browsing sources

Closes #2941
This commit is contained in:
arkon 2023-02-12 22:28:12 -05:00
parent a7cb33d8c9
commit 6348cbaeb7
4 changed files with 18 additions and 9 deletions

View file

@ -31,4 +31,6 @@ class SourcePreferences(
fun trustedSignatures() = preferenceStore.getStringSet("trusted_signatures", emptySet()) fun trustedSignatures() = preferenceStore.getStringSet("trusted_signatures", emptySet())
fun searchPinnedSourcesOnly() = preferenceStore.getBoolean("search_pinned_sources_only", false) fun searchPinnedSourcesOnly() = preferenceStore.getBoolean("search_pinned_sources_only", false)
fun hideInLibraryItems() = preferenceStore.getBoolean("browse_hide_in_library_items", false)
} }

View file

@ -43,12 +43,16 @@ object SettingsBrowseScreen : SearchableSettings {
), ),
), ),
Preference.PreferenceGroup( Preference.PreferenceGroup(
title = stringResource(R.string.action_global_search), title = stringResource(R.string.label_sources),
preferenceItems = listOf( preferenceItems = listOf(
Preference.PreferenceItem.SwitchPreference( Preference.PreferenceItem.SwitchPreference(
pref = sourcePreferences.searchPinnedSourcesOnly(), pref = sourcePreferences.searchPinnedSourcesOnly(),
title = stringResource(R.string.pref_search_pinned_sources_only), 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( Preference.PreferenceGroup(

View file

@ -10,6 +10,7 @@ import androidx.compose.ui.unit.dp
import androidx.paging.Pager import androidx.paging.Pager
import androidx.paging.PagingConfig import androidx.paging.PagingConfig
import androidx.paging.cachedIn import androidx.paging.cachedIn
import androidx.paging.filter
import androidx.paging.map import androidx.paging.map
import cafe.adriel.voyager.core.model.StateScreenModel import cafe.adriel.voyager.core.model.StateScreenModel
import cafe.adriel.voyager.core.model.coroutineScope import cafe.adriel.voyager.core.model.coroutineScope
@ -137,16 +138,17 @@ class BrowseSourceScreenModel(
PagingConfig(pageSize = 25), PagingConfig(pageSize = 25),
) { ) {
getRemoteManga.subscribe(sourceId, listing.query ?: "", listing.filters) getRemoteManga.subscribe(sourceId, listing.query ?: "", listing.filters)
}.flow }.flow.map { pagingData ->
.map { pagingData -> pagingData
pagingData.map { sManga -> .map { withIOContext { networkToLocalManga.await(it.toDomainManga(sourceId)) } }
val dbManga = withIOContext { networkToLocalManga.await(sManga.toDomainManga(sourceId)) } .filter { !sourcePreferences.hideInLibraryItems().get() || !it.favorite }
getManga.subscribe(dbManga.url, dbManga.source) .map {
getManga.subscribe(it.url, it.source)
.filterNotNull() .filterNotNull()
.onEach { initializeManga(it) } .onEach(::initializeManga)
.stateIn(coroutineScope) .stateIn(coroutineScope)
} }
} }
.cachedIn(coroutineScope) .cachedIn(coroutineScope)
} }
.stateIn(coroutineScope, SharingStarted.Lazily, emptyFlow()) .stateIn(coroutineScope, SharingStarted.Lazily, emptyFlow())

View file

@ -457,7 +457,8 @@
<!-- Browse section --> <!-- Browse section -->
<string name="pref_enable_automatic_extension_updates">Check for extension updates</string> <string name="pref_enable_automatic_extension_updates">Check for extension updates</string>
<string name="pref_search_pinned_sources_only">Only include pinned sources</string> <string name="pref_search_pinned_sources_only">Only search pinned sources in global search</string>
<string name="pref_hide_in_library_items">Hide entries already in library</string>
<!-- Backup section --> <!-- Backup section -->
<string name="pref_create_backup">Create backup</string> <string name="pref_create_backup">Create backup</string>