mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
Unify NSFW flagging for sources/extensions
Co-Authored-By: arkon <4098258+arkon@users.noreply.github.com>
This commit is contained in:
parent
984ea915cc
commit
c76a2dd7a0
8 changed files with 10 additions and 63 deletions
|
@ -230,8 +230,6 @@ object PreferenceKeys {
|
|||
const val dohProvider = "doh_provider"
|
||||
|
||||
const val showNsfwSource = "show_nsfw_source"
|
||||
const val showNsfwExtension = "show_nsfw_extension"
|
||||
const val labelNsfwExtension = "label_nsfw_extension"
|
||||
|
||||
const val themeMangaDetails = "theme_manga_details"
|
||||
|
||||
|
|
|
@ -421,9 +421,7 @@ class PreferencesHelper(val context: Context) {
|
|||
|
||||
fun sideNavIconAlignment() = flowPrefs.getInt(Keys.sideNavIconAlignment, 1)
|
||||
|
||||
fun showNsfwSource() = flowPrefs.getBoolean(Keys.showNsfwSource, true)
|
||||
fun showNsfwExtension() = flowPrefs.getBoolean(Keys.showNsfwExtension, true)
|
||||
fun labelNsfwExtension() = prefs.getBoolean(Keys.labelNsfwExtension, true)
|
||||
fun showNsfwSources() = flowPrefs.getBoolean(Keys.showNsfwSource, true)
|
||||
|
||||
fun themeMangaDetails() = prefs.getBoolean(Keys.themeMangaDetails, true)
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ import android.content.pm.PackageManager
|
|||
import android.os.Build
|
||||
import dalvik.system.PathClassLoader
|
||||
import eu.kanade.tachiyomi.BuildConfig
|
||||
import eu.kanade.tachiyomi.annotations.Nsfw
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.extension.model.Extension
|
||||
|
@ -29,7 +28,7 @@ internal object ExtensionLoader {
|
|||
|
||||
private val preferences: PreferencesHelper by injectLazy()
|
||||
private val loadNsfwSource by lazy {
|
||||
preferences.showNsfwSource().get()
|
||||
preferences.showNsfwSources().get()
|
||||
}
|
||||
|
||||
private const val EXTENSION_FEATURE = "tachiyomi.extension"
|
||||
|
@ -168,13 +167,7 @@ internal object ExtensionLoader {
|
|||
try {
|
||||
when (val obj = Class.forName(it, false, classLoader).newInstance()) {
|
||||
is Source -> listOf(obj)
|
||||
is SourceFactory -> {
|
||||
if (isSourceNsfw(obj)) {
|
||||
emptyList()
|
||||
} else {
|
||||
obj.createSources()
|
||||
}
|
||||
}
|
||||
is SourceFactory -> obj.createSources()
|
||||
else -> throw Exception("Unknown source class type! ${obj.javaClass}")
|
||||
}
|
||||
} catch (e: Throwable) {
|
||||
|
@ -229,22 +222,4 @@ internal object ExtensionLoader {
|
|||
null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a Source or SourceFactory is annotated with @Nsfw.
|
||||
*/
|
||||
private fun isSourceNsfw(clazz: Any): Boolean {
|
||||
if (loadNsfwSource) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (clazz !is Source && clazz !is SourceFactory) {
|
||||
return false
|
||||
}
|
||||
|
||||
// Annotations are proxied, hence this janky way of checking for them
|
||||
return clazz.javaClass.annotations
|
||||
.flatMap { it.javaClass.interfaces.map { it.simpleName } }
|
||||
.firstOrNull { it == Nsfw::class.java.simpleName } != null
|
||||
}
|
||||
}
|
||||
|
|
|
@ -178,7 +178,7 @@ class ExtensionBottomPresenter(
|
|||
private fun toItems(tuple: ExtensionTuple): List<ExtensionItem> {
|
||||
val context = bottomSheet.context
|
||||
val activeLangs = preferences.enabledLanguages().get()
|
||||
val showNsfwExtensions = preferences.showNsfwExtension().get()
|
||||
val showNsfwSources = preferences.showNsfwSources().get()
|
||||
|
||||
val (installed, untrusted, available) = tuple
|
||||
|
||||
|
@ -193,10 +193,10 @@ class ExtensionBottomPresenter(
|
|||
firstLoad = false
|
||||
}
|
||||
|
||||
val updatesSorted = installed.filter { it.hasUpdate && (showNsfwExtensions || !it.isNsfw) }.sortedBy { it.name }
|
||||
val updatesSorted = installed.filter { it.hasUpdate && (showNsfwSources || !it.isNsfw) }.sortedBy { it.name }
|
||||
val sortOrder = InstalledExtensionsOrder.fromPreference(preferences)
|
||||
val installedSorted = installed
|
||||
.filter { !it.hasUpdate && (showNsfwExtensions || !it.isNsfw) }
|
||||
.filter { !it.hasUpdate && (showNsfwSources || !it.isNsfw) }
|
||||
.sortedWith(
|
||||
compareBy(
|
||||
{ !it.isObsolete },
|
||||
|
@ -218,7 +218,7 @@ class ExtensionBottomPresenter(
|
|||
installed.none { it.pkgName == avail.pkgName } &&
|
||||
untrusted.none { it.pkgName == avail.pkgName } &&
|
||||
(avail.lang in activeLangs || avail.lang == "all") &&
|
||||
(showNsfwExtensions || !avail.isNsfw)
|
||||
(showNsfwSources || !avail.isNsfw)
|
||||
}
|
||||
.sortedBy { it.name }
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@ import coil.clear
|
|||
import coil.load
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.image.coil.CoverViewTarget
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.databinding.ExtensionCardItemBinding
|
||||
import eu.kanade.tachiyomi.extension.model.Extension
|
||||
import eu.kanade.tachiyomi.extension.model.InstallStep
|
||||
|
@ -23,7 +22,6 @@ import eu.kanade.tachiyomi.util.system.LocaleHelper
|
|||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||
import eu.kanade.tachiyomi.util.system.timeSpanFromNow
|
||||
import eu.kanade.tachiyomi.util.view.resetStrokeColor
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import java.util.Locale
|
||||
|
||||
|
@ -40,10 +38,6 @@ class ExtensionHolder(view: View, val adapter: ExtensionAdapter) :
|
|||
}
|
||||
}
|
||||
|
||||
private val shouldLabelNsfw by lazy {
|
||||
Injekt.get<PreferencesHelper>().labelNsfwExtension()
|
||||
}
|
||||
|
||||
fun bind(item: ExtensionItem) {
|
||||
val extension = item.extension
|
||||
|
||||
|
@ -98,7 +92,7 @@ class ExtensionHolder(view: View, val adapter: ExtensionAdapter) :
|
|||
extension is Extension.Untrusted -> itemView.context.getString(R.string.untrusted)
|
||||
extension is Extension.Installed && extension.isObsolete -> itemView.context.getString(R.string.obsolete)
|
||||
extension is Extension.Installed && extension.isUnofficial -> itemView.context.getString(R.string.unofficial)
|
||||
extension.isNsfw && shouldLabelNsfw -> itemView.context.getString(R.string.nsfw_short)
|
||||
extension.isNsfw -> itemView.context.getString(R.string.nsfw_short)
|
||||
else -> ""
|
||||
}.uppercase(Locale.ROOT)
|
||||
binding.installProgress.progress = item.sessionProgress ?: 0
|
||||
|
|
|
@ -6,7 +6,6 @@ import android.os.Looper
|
|||
import android.view.GestureDetector
|
||||
import android.view.MotionEvent
|
||||
import android.view.ViewConfiguration
|
||||
import androidx.core.content.ContextCompat
|
||||
import kotlin.math.abs
|
||||
|
||||
/**
|
||||
|
|
|
@ -10,7 +10,6 @@ import eu.kanade.tachiyomi.BuildConfig
|
|||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.notification.Notifications
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceKeys
|
||||
import eu.kanade.tachiyomi.data.preference.asImmediateFlow
|
||||
import eu.kanade.tachiyomi.data.preference.asImmediateFlowIn
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.data.updater.AutoUpdaterJob
|
||||
|
@ -20,7 +19,6 @@ import eu.kanade.tachiyomi.ui.main.MainActivity
|
|||
import eu.kanade.tachiyomi.ui.migration.MigrationController
|
||||
import eu.kanade.tachiyomi.util.view.snack
|
||||
import eu.kanade.tachiyomi.util.view.withFadeTransaction
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
|
||||
class SettingsBrowseController : SettingsController() {
|
||||
|
@ -161,23 +159,10 @@ class SettingsBrowseController : SettingsController() {
|
|||
|
||||
switchPreference {
|
||||
key = PreferenceKeys.showNsfwSource
|
||||
titleRes = R.string.show_in_sources
|
||||
titleRes = R.string.show_in_sources_and_extensions
|
||||
summaryRes = R.string.requires_app_restart
|
||||
defaultValue = true
|
||||
}
|
||||
switchPreference {
|
||||
key = PreferenceKeys.showNsfwExtension
|
||||
titleRes = R.string.show_in_extensions
|
||||
defaultValue = true
|
||||
}
|
||||
switchPreference {
|
||||
key = PreferenceKeys.labelNsfwExtension
|
||||
titleRes = R.string.label_in_extensions
|
||||
defaultValue = true
|
||||
|
||||
preferences.showNsfwExtension().asImmediateFlow { isVisible = it }.launchIn(viewScope)
|
||||
}
|
||||
|
||||
infoPreference(R.string.does_not_prevent_unofficial_nsfw)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -816,9 +816,7 @@
|
|||
library</string>
|
||||
<string name="source_migration_guide">Source migration guide</string>
|
||||
<string name="nsfw_sources">NSFW (18+) sources</string>
|
||||
<string name="show_in_sources">Show in sources list</string>
|
||||
<string name="show_in_extensions">Show in extensions list</string>
|
||||
<string name="label_in_extensions">Label in extensions list</string>
|
||||
<string name="show_in_sources_and_extensions">Show in sources and extensions lists</string>
|
||||
<string name="does_not_prevent_unofficial_nsfw">This does not prevent unofficial or potentially incorrectly flagged extensions from surfacing NSFW (18+) content within the app.</string>
|
||||
|
||||
<!-- About section -->
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue