mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-30 22:07:57 +01:00 
			
		
		
		
	Break out NSFW hiding/labeling into separate settings
This commit is contained in:
		| @@ -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" | ||||
|  | ||||
|   | ||||
| @@ -37,10 +37,4 @@ object PreferenceValues { | ||||
|         VERTICAL, | ||||
|         BOTH | ||||
|     } | ||||
|  | ||||
|     enum class NsfwAllowance { | ||||
|         ALLOWED, | ||||
|         PARTIAL, | ||||
|         BLOCKED | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -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) | ||||
|  | ||||
|   | ||||
| @@ -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 | ||||
|         } | ||||
|  | ||||
|   | ||||
| @@ -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<PreferencesHelper>().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() | ||||
|  | ||||
|   | ||||
| @@ -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<ExtensionItem> { | ||||
|         val context = Injekt.get<Application>() | ||||
|         val activeLangs = preferences.enabledLanguages().get() | ||||
|         val showNsfwExtensions = preferences.allowNsfwSource().get() != PreferenceValues.NsfwAllowance.BLOCKED | ||||
|         val showNsfwExtensions = preferences.showNsfwExtension().get() | ||||
|  | ||||
|         val (installed, untrusted, available) = tuple | ||||
|  | ||||
|   | ||||
| @@ -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) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user