Apply the Disable NSFW option to all lists (closes #1057)
This commit is contained in:
@@ -152,7 +152,7 @@ class FavouritesListViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
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) }
|
||||
} else {
|
||||
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) }
|
||||
|
||||
private suspend fun mapList(
|
||||
|
||||
@@ -10,6 +10,7 @@ import kotlinx.coroutines.flow.filter
|
||||
import kotlinx.coroutines.flow.onStart
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.plus
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||
import org.koitharu.kotatsu.core.prefs.ListMode
|
||||
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.call
|
||||
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.parsers.model.Manga
|
||||
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 }
|
||||
} else {
|
||||
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(
|
||||
listMode,
|
||||
settings.observe().filter { key ->
|
||||
|
||||
@@ -71,6 +71,9 @@ class LocalMangaRepository @Inject constructor(
|
||||
return emptyList()
|
||||
}
|
||||
val list = getRawList()
|
||||
if (settings.isNsfwContentDisabled) {
|
||||
list.removeIf { it.manga.isNsfw }
|
||||
}
|
||||
when (filter) {
|
||||
is MangaListFilter.Search -> {
|
||||
list.retainAll { x -> x.isMatchesQuery(filter.query) }
|
||||
|
||||
@@ -39,7 +39,7 @@ class SuggestionsViewModel @Inject constructor(
|
||||
.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Eagerly, settings.suggestionsListMode)
|
||||
|
||||
override val content = combine(
|
||||
quickFilter.appliedOptions.flatMapLatest { repository.observeAll(0, it) },
|
||||
quickFilter.appliedOptions.combineWithSettings().flatMapLatest { repository.observeAll(0, it) },
|
||||
quickFilter.appliedOptions,
|
||||
observeListModeWithTriggers(),
|
||||
) { list, filters, mode ->
|
||||
|
||||
@@ -188,7 +188,7 @@ class SuggestionsWorker @AssistedInject constructor(
|
||||
val semaphore = Semaphore(MAX_PARALLELISM)
|
||||
val producer = channelFlow {
|
||||
for (it in sources.shuffled()) {
|
||||
if (it.isNsfw() && appSettings.isSuggestionsExcludeNsfw) {
|
||||
if (it.isNsfw() && (appSettings.isSuggestionsExcludeNsfw || appSettings.isNsfwContentDisabled)) {
|
||||
continue
|
||||
}
|
||||
launch {
|
||||
@@ -224,7 +224,7 @@ class SuggestionsWorker @AssistedInject constructor(
|
||||
if (details.rating > 0 && details.rating < RATING_MIN) {
|
||||
continue
|
||||
}
|
||||
if (details.isNsfw && appSettings.isSuggestionsExcludeNsfw) {
|
||||
if (details.isNsfw && (appSettings.isSuggestionsExcludeNsfw || appSettings.isNsfwContentDisabled)) {
|
||||
continue
|
||||
}
|
||||
if (details in tagsBlacklist) {
|
||||
|
||||
Reference in New Issue
Block a user