From a2cf210a524894e5c1d1f062e4813086b46777a4 Mon Sep 17 00:00:00 2001 From: arkon Date: Mon, 13 Sep 2021 17:49:58 -0400 Subject: [PATCH] Unify NSFW flagging for sources/extensions Since multisource extensions are no longer a thing, we now simply rely on the flag at the extension level, i.e. the per-Source/SourceFactory `@Nsfw` annotation is no longer checked. We'll have to remove all of the annotation usages from the existing sources, which will also effectively break the setting for older versions of the app. --- .../eu/kanade/tachiyomi/annotations/Nsfw.kt | 1 + .../data/preference/PreferenceKeys.kt | 2 -- .../data/preference/PreferencesHelper.kt | 2 -- .../extension/util/ExtensionLoader.kt | 28 +------------------ .../kanade/tachiyomi/source/SourceManager.kt | 1 - .../ui/browse/extension/ExtensionHolder.kt | 8 +----- .../ui/browse/extension/ExtensionPresenter.kt | 8 +++--- .../ui/setting/SettingsBrowseController.kt | 14 ---------- app/src/main/res/values/strings.xml | 4 +-- 9 files changed, 8 insertions(+), 60 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/annotations/Nsfw.kt b/app/src/main/java/eu/kanade/tachiyomi/annotations/Nsfw.kt index 964a427025..bc22dde13a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/annotations/Nsfw.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/annotations/Nsfw.kt @@ -1,5 +1,6 @@ package eu.kanade.tachiyomi.annotations +// TODO: remove this when no longer used in extensions @Retention(AnnotationRetention.RUNTIME) @Target(AnnotationTarget.CLASS) annotation class Nsfw diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt index 02ddf2fab8..0fe8892db0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt @@ -154,8 +154,6 @@ object PreferenceKeys { const val automaticExtUpdates = "automatic_ext_updates" const val showNsfwSource = "show_nsfw_source" - const val showNsfwExtension = "show_nsfw_extension" - const val labelNsfwExtension = "label_nsfw_extension" const val startScreen = "start_screen" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index ffb26b7bed..d5c2b2ecae 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -271,8 +271,6 @@ class PreferencesHelper(val context: Context) { fun automaticExtUpdates() = flowPrefs.getBoolean(Keys.automaticExtUpdates, true) fun showNsfwSource() = flowPrefs.getBoolean(Keys.showNsfwSource, true) - fun showNsfwExtension() = flowPrefs.getBoolean(Keys.showNsfwExtension, true) - fun labelNsfwExtension() = prefs.getBoolean(Keys.labelNsfwExtension, true) fun extensionUpdatesCount() = flowPrefs.getInt("ext_updates_count", 0) diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionLoader.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionLoader.kt index c2ec940411..cea2269942 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionLoader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionLoader.kt @@ -6,7 +6,6 @@ import android.content.pm.PackageInfo import android.content.pm.PackageManager import androidx.core.content.pm.PackageInfoCompat import dalvik.system.PathClassLoader -import eu.kanade.tachiyomi.annotations.Nsfw import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.extension.model.Extension import eu.kanade.tachiyomi.extension.model.LoadResult @@ -154,13 +153,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) { @@ -168,7 +161,6 @@ internal object ExtensionLoader { return LoadResult.Error(e) } } - .filter { !isSourceNsfw(it) } val langs = sources.filterIsInstance() .map { it.lang } @@ -215,22 +207,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 - } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/SourceManager.kt b/app/src/main/java/eu/kanade/tachiyomi/source/SourceManager.kt index 4f8657b91a..29afe39046 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/SourceManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/SourceManager.kt @@ -11,7 +11,6 @@ import rx.Observable open class SourceManager(private val context: Context) { private val sourcesMap = mutableMapOf() - private val stubSourcesMap = mutableMapOf() init { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionHolder.kt index e99e174872..cc92957d0e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionHolder.kt @@ -5,12 +5,10 @@ import coil.clear import coil.load import eu.davidea.viewholders.FlexibleViewHolder import eu.kanade.tachiyomi.R -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 import eu.kanade.tachiyomi.util.system.LocaleHelper -import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get class ExtensionHolder(view: View, val adapter: ExtensionAdapter) : @@ -18,10 +16,6 @@ class ExtensionHolder(view: View, val adapter: ExtensionAdapter) : private val binding = ExtensionCardItemBinding.bind(view) - private val shouldLabelNsfw by lazy { - Injekt.get().labelNsfwExtension() - } - init { binding.extButton.setOnClickListener { adapter.buttonClickListener.onButtonClick(bindingAdapterPosition) @@ -38,7 +32,7 @@ class ExtensionHolder(view: View, val adapter: ExtensionAdapter) : extension is Extension.Untrusted -> itemView.context.getString(R.string.ext_untrusted) extension is Extension.Installed && extension.isUnofficial -> itemView.context.getString(R.string.ext_unofficial) extension is Extension.Installed && extension.isObsolete -> itemView.context.getString(R.string.ext_obsolete) - extension.isNsfw && shouldLabelNsfw -> itemView.context.getString(R.string.ext_nsfw_short) + extension.isNsfw -> itemView.context.getString(R.string.ext_nsfw_short) else -> "" }.uppercase() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionPresenter.kt index d736053db8..31f7c25b0d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionPresenter.kt @@ -55,14 +55,14 @@ open class ExtensionPresenter( private fun toItems(tuple: ExtensionTuple): List { val context = Injekt.get() val activeLangs = preferences.enabledLanguages().get() - val showNsfwExtensions = preferences.showNsfwExtension().get() + val showNsfwSources = preferences.showNsfwSource().get() val (installed, untrusted, available) = tuple val items = mutableListOf() - val updatesSorted = installed.filter { it.hasUpdate && (showNsfwExtensions || !it.isNsfw) }.sortedBy { it.name } - val installedSorted = installed.filter { !it.hasUpdate && (showNsfwExtensions || !it.isNsfw) }.sortedWith(compareBy({ !it.isObsolete }, { it.name })) + val updatesSorted = installed.filter { it.hasUpdate && (showNsfwSources || !it.isNsfw) }.sortedBy { it.name } + val installedSorted = installed.filter { !it.hasUpdate && (showNsfwSources || !it.isNsfw) }.sortedWith(compareBy({ !it.isObsolete }, { it.name })) val untrustedSorted = untrusted.sortedBy { it.name } val availableSorted = available // Filter out already installed extensions and disabled languages @@ -70,7 +70,7 @@ open class ExtensionPresenter( 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 } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBrowseController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBrowseController.kt index 4156b9c21a..f2956a1140 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBrowseController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBrowseController.kt @@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.ui.setting import androidx.preference.PreferenceScreen import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.data.preference.asImmediateFlow import eu.kanade.tachiyomi.extension.ExtensionUpdateJob import eu.kanade.tachiyomi.util.preference.defaultValue import eu.kanade.tachiyomi.util.preference.infoPreference @@ -11,7 +10,6 @@ import eu.kanade.tachiyomi.util.preference.preferenceCategory import eu.kanade.tachiyomi.util.preference.summaryRes import eu.kanade.tachiyomi.util.preference.switchPreference import eu.kanade.tachiyomi.util.preference.titleRes -import kotlinx.coroutines.flow.launchIn import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys class SettingsBrowseController : SettingsController() { @@ -54,18 +52,6 @@ class SettingsBrowseController : SettingsController() { summaryRes = R.string.requires_app_restart defaultValue = true } - switchPreference { - key = Keys.showNsfwExtension - titleRes = R.string.pref_show_nsfw_extension - defaultValue = true - } - switchPreference { - key = Keys.labelNsfwExtension - titleRes = R.string.pref_label_nsfw_extension - defaultValue = true - - preferences.showNsfwExtension().asImmediateFlow { isVisible = it }.launchIn(viewScope) - } infoPreference(R.string.parental_controls_info) } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d85a87d63c..1abb300cf2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -189,9 +189,7 @@ Hide notification content NSFW (18+) sources - Show in sources list - Show in extensions list - Label in extensions list + Show in sources and extensions lists This does not prevent unofficial or potentially incorrectly flagged extensions from surfacing NSFW (18+) content within the app. Recently