From 5b09461ccf76963fef844d7550383205e8d33010 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 12 Dec 2020 16:17:08 -0500 Subject: [PATCH] Break out NSFW hiding/labeling into separate settings --- .../data/preference/PreferenceKeys.kt | 4 ++- .../data/preference/PreferenceValues.kt | 6 ---- .../data/preference/PreferencesHelper.kt | 5 +-- .../extension/util/ExtensionLoader.kt | 9 +++-- .../ui/browse/extension/ExtensionHolder.kt | 9 ++++- .../ui/browse/extension/ExtensionPresenter.kt | 3 +- .../ui/setting/SettingsBrowseController.kt | 36 +++++++++---------- app/src/main/res/values/strings.xml | 7 ++-- 8 files changed, 40 insertions(+), 39 deletions(-) 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 a4739ebcd..4e285d746 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 @@ -121,7 +121,9 @@ object PreferenceKeys { const val automaticExtUpdates = "automatic_ext_updates" - const val allowNsfwSource = "allow_nsfw_source" + 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/PreferenceValues.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt index d0afd208d..e60f7f508 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt @@ -37,10 +37,4 @@ object PreferenceValues { VERTICAL, BOTH } - - enum class NsfwAllowance { - ALLOWED, - PARTIAL, - BLOCKED - } } 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 ac50c3ae9..168a2b855 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 @@ -10,7 +10,6 @@ import com.tfcporciuncula.flow.Preference import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.preference.PreferenceValues.DisplayMode -import eu.kanade.tachiyomi.data.preference.PreferenceValues.NsfwAllowance import eu.kanade.tachiyomi.data.track.TrackService import eu.kanade.tachiyomi.data.track.anilist.Anilist import eu.kanade.tachiyomi.widget.ExtendedNavigationView @@ -225,7 +224,9 @@ class PreferencesHelper(val context: Context) { fun automaticExtUpdates() = flowPrefs.getBoolean(Keys.automaticExtUpdates, true) - fun allowNsfwSource() = flowPrefs.getEnum(Keys.allowNsfwSource, NsfwAllowance.ALLOWED) + 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 b41b9503a..78baabc5b 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 dalvik.system.PathClassLoader import eu.kanade.tachiyomi.annotations.Nsfw -import eu.kanade.tachiyomi.data.preference.PreferenceValues import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.extension.model.Extension import eu.kanade.tachiyomi.extension.model.LoadResult @@ -26,8 +25,8 @@ import uy.kohesive.injekt.injectLazy internal object ExtensionLoader { private val preferences: PreferencesHelper by injectLazy() - private val allowNsfwSource by lazy { - preferences.allowNsfwSource().get() + private val loadNsfwSource by lazy { + preferences.showNsfwSource().get() } private const val EXTENSION_FEATURE = "tachiyomi.extension" @@ -133,7 +132,7 @@ internal object ExtensionLoader { } val isNsfw = appInfo.metaData.getInt(METADATA_NSFW) == 1 - if (allowNsfwSource == PreferenceValues.NsfwAllowance.BLOCKED && isNsfw) { + if (!loadNsfwSource && isNsfw) { return LoadResult.Error("NSFW extension $pkgName not allowed") } @@ -218,7 +217,7 @@ internal object ExtensionLoader { * Checks whether a Source or SourceFactory is annotated with @Nsfw. */ private fun isSourceNsfw(clazz: Any): Boolean { - if (allowNsfwSource == PreferenceValues.NsfwAllowance.ALLOWED) { + if (loadNsfwSource) { return false } 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 1a56490b7..cdec1a95b 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 @@ -4,16 +4,23 @@ import android.view.View import eu.davidea.viewholders.FlexibleViewHolder import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.glide.GlideApp +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) : FlexibleViewHolder(view, adapter) { private val binding = ExtensionCardItemBinding.bind(view) + private val shouldLabelNsfw by lazy { + Injekt.get().labelNsfwExtension() + } + init { binding.extButton.setOnClickListener { adapter.buttonClickListener.onButtonClick(bindingAdapterPosition) @@ -30,7 +37,7 @@ class ExtensionHolder(view: View, val adapter: ExtensionAdapter) : extension is Extension.Untrusted -> itemView.context.getString(R.string.ext_untrusted) extension is Extension.Installed && extension.isObsolete -> itemView.context.getString(R.string.ext_obsolete) extension is Extension.Installed && extension.isUnofficial -> itemView.context.getString(R.string.ext_unofficial) - extension.isNsfw -> itemView.context.getString(R.string.ext_nsfw_short) + extension.isNsfw && shouldLabelNsfw -> itemView.context.getString(R.string.ext_nsfw_short) else -> "" }.toUpperCase() 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 6c892ffe0..e2f3b45cf 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 @@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.ui.browse.extension import android.app.Application import android.os.Bundle import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.data.preference.PreferenceValues import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.extension.ExtensionManager import eu.kanade.tachiyomi.extension.model.Extension @@ -56,7 +55,7 @@ open class ExtensionPresenter( private fun toItems(tuple: ExtensionTuple): List { val context = Injekt.get() val activeLangs = preferences.enabledLanguages().get() - val showNsfwExtensions = preferences.allowNsfwSource().get() != PreferenceValues.NsfwAllowance.BLOCKED + val showNsfwExtensions = preferences.showNsfwExtension().get() val (installed, untrusted, available) = tuple 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 9a1524558..bbdaf40bb 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,16 +2,15 @@ package eu.kanade.tachiyomi.ui.setting import androidx.preference.PreferenceScreen import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.data.preference.PreferenceValues +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.entriesRes import eu.kanade.tachiyomi.util.preference.infoPreference -import eu.kanade.tachiyomi.util.preference.listPreference import eu.kanade.tachiyomi.util.preference.onChange import eu.kanade.tachiyomi.util.preference.preferenceCategory 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() { @@ -48,21 +47,22 @@ class SettingsBrowseController : SettingsController() { preferenceCategory { titleRes = R.string.pref_category_nsfw_content - listPreference { - key = Keys.allowNsfwSource - titleRes = R.string.pref_allow_nsfw_sources - entriesRes = arrayOf( - R.string.pref_allow_nsfw_sources_allowed, - R.string.pref_allow_nsfw_sources_allowed_multisource, - R.string.pref_allow_nsfw_sources_blocked - ) - entryValues = arrayOf( - PreferenceValues.NsfwAllowance.ALLOWED.name, - PreferenceValues.NsfwAllowance.PARTIAL.name, - PreferenceValues.NsfwAllowance.BLOCKED.name - ) - defaultValue = PreferenceValues.NsfwAllowance.ALLOWED.name - summary = "%s" + switchPreference { + key = Keys.showNsfwSource + titleRes = R.string.pref_show_nsfw_source + 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(scope) } 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 ca2072a1e..724c7e645 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -173,10 +173,9 @@ Hide notification content 18+ content - 18+ sources - Show - Hide in sources but show in extensions list - Hide + Show in sources list + Show in extensions list + Label in extensions list This does not prevent unofficial or potentially incorrectly flagged extensions from surfacing 18+ content within the app.