Apply the Disable NSFW option to all lists (closes #1057)

master
Koitharu 2 years ago
parent 542ad29cd9
commit 903fef6791
Signed by: Koitharu
GPG Key ID: 676DEE768C17A9D7

@ -152,7 +152,7 @@ class FavouritesListViewModel @Inject constructor(
} }
private fun observeFavorites() = if (categoryId == NO_ID) { private fun observeFavorites() = if (categoryId == NO_ID) {
combine(sortOrder.filterNotNull(), quickFilter.appliedOptions, limit, ::Triple) combine(sortOrder.filterNotNull(), quickFilter.appliedOptions.combineWithSettings(), limit, ::Triple)
.flatMapLatest { repository.observeAll(it.first, it.second - ListFilterOption.Downloaded, it.third) } .flatMapLatest { repository.observeAll(it.first, it.second - ListFilterOption.Downloaded, it.third) }
} else { } else {
combine(quickFilter.appliedOptions, limit, ::Pair) combine(quickFilter.appliedOptions, limit, ::Pair)

@ -157,7 +157,7 @@ class HistoryListViewModel @Inject constructor(
} }
} }
private fun observeHistory() = combine(sortOrder, quickFilter.appliedOptions, limit, ::Triple) private fun observeHistory() = combine(sortOrder, quickFilter.appliedOptions.combineWithSettings(), limit, ::Triple)
.flatMapLatest { repository.observeAllWithHistory(it.first, it.second - ListFilterOption.Downloaded, it.third) } .flatMapLatest { repository.observeAllWithHistory(it.first, it.second - ListFilterOption.Downloaded, it.third) }
private suspend fun mapList( private suspend fun mapList(

@ -10,6 +10,7 @@ import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.onStart import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.plus import kotlinx.coroutines.plus
import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.core.prefs.AppSettings import org.koitharu.kotatsu.core.prefs.AppSettings
import org.koitharu.kotatsu.core.prefs.ListMode import org.koitharu.kotatsu.core.prefs.ListMode
import org.koitharu.kotatsu.core.prefs.observeAsFlow import org.koitharu.kotatsu.core.prefs.observeAsFlow
@ -19,6 +20,7 @@ import org.koitharu.kotatsu.core.ui.util.ReversibleAction
import org.koitharu.kotatsu.core.util.ext.MutableEventFlow import org.koitharu.kotatsu.core.util.ext.MutableEventFlow
import org.koitharu.kotatsu.core.util.ext.call import org.koitharu.kotatsu.core.util.ext.call
import org.koitharu.kotatsu.download.ui.worker.DownloadWorker import org.koitharu.kotatsu.download.ui.worker.DownloadWorker
import org.koitharu.kotatsu.list.domain.ListFilterOption
import org.koitharu.kotatsu.list.ui.model.ListModel import org.koitharu.kotatsu.list.ui.model.ListModel
import org.koitharu.kotatsu.parsers.model.Manga import org.koitharu.kotatsu.parsers.model.Manga
import org.koitharu.kotatsu.parsers.model.MangaTag import org.koitharu.kotatsu.parsers.model.MangaTag
@ -55,12 +57,22 @@ abstract class MangaListViewModel(
} }
} }
fun List<Manga>.skipNsfwIfNeeded() = if (settings.isNsfwContentDisabled) { protected fun List<Manga>.skipNsfwIfNeeded() = if (settings.isNsfwContentDisabled) {
filterNot { it.isNsfw } filterNot { it.isNsfw }
} else { } else {
this this
} }
protected fun Flow<Set<ListFilterOption>>.combineWithSettings(): Flow<Set<ListFilterOption>> = combine(
settings.observeAsFlow(AppSettings.KEY_DISABLE_NSFW) { isNsfwContentDisabled },
) { filters, skipNsfw ->
if (skipNsfw) {
filters + ListFilterOption.Inverted(ListFilterOption.Macro.NSFW, R.drawable.ic_sfw, R.string.sfw, null)
} else {
filters
}
}
protected fun observeListModeWithTriggers(): Flow<ListMode> = combine( protected fun observeListModeWithTriggers(): Flow<ListMode> = combine(
listMode, listMode,
settings.observe().filter { key -> settings.observe().filter { key ->

@ -71,6 +71,9 @@ class LocalMangaRepository @Inject constructor(
return emptyList() return emptyList()
} }
val list = getRawList() val list = getRawList()
if (settings.isNsfwContentDisabled) {
list.removeIf { it.manga.isNsfw }
}
when (filter) { when (filter) {
is MangaListFilter.Search -> { is MangaListFilter.Search -> {
list.retainAll { x -> x.isMatchesQuery(filter.query) } list.retainAll { x -> x.isMatchesQuery(filter.query) }

@ -39,7 +39,7 @@ class SuggestionsViewModel @Inject constructor(
.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Eagerly, settings.suggestionsListMode) .stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Eagerly, settings.suggestionsListMode)
override val content = combine( override val content = combine(
quickFilter.appliedOptions.flatMapLatest { repository.observeAll(0, it) }, quickFilter.appliedOptions.combineWithSettings().flatMapLatest { repository.observeAll(0, it) },
quickFilter.appliedOptions, quickFilter.appliedOptions,
observeListModeWithTriggers(), observeListModeWithTriggers(),
) { list, filters, mode -> ) { list, filters, mode ->

@ -188,7 +188,7 @@ class SuggestionsWorker @AssistedInject constructor(
val semaphore = Semaphore(MAX_PARALLELISM) val semaphore = Semaphore(MAX_PARALLELISM)
val producer = channelFlow { val producer = channelFlow {
for (it in sources.shuffled()) { for (it in sources.shuffled()) {
if (it.isNsfw() && appSettings.isSuggestionsExcludeNsfw) { if (it.isNsfw() && (appSettings.isSuggestionsExcludeNsfw || appSettings.isNsfwContentDisabled)) {
continue continue
} }
launch { launch {
@ -224,7 +224,7 @@ class SuggestionsWorker @AssistedInject constructor(
if (details.rating > 0 && details.rating < RATING_MIN) { if (details.rating > 0 && details.rating < RATING_MIN) {
continue continue
} }
if (details.isNsfw && appSettings.isSuggestionsExcludeNsfw) { if (details.isNsfw && (appSettings.isSuggestionsExcludeNsfw || appSettings.isNsfwContentDisabled)) {
continue continue
} }
if (details in tagsBlacklist) { if (details in tagsBlacklist) {

Loading…
Cancel
Save