From 97458d69986c01f8fc3f12bd084ec88dda1f3b7e Mon Sep 17 00:00:00 2001 From: nicki <72807749+curche@users.noreply.github.com> Date: Fri, 7 Jan 2022 00:29:49 +0530 Subject: [PATCH] MangaDex: Scanlation Group blocking (#10376) * Add (somewhat) working group blocking blocks an input scanlator group doesn't seem to block official/external-link groups * Fine tuning adjustments* - sanitise inputs as much as possible - add to summary a bit more - `setDefaultValue` looks to set once and never again. So even if EditText receives an empty String, it is still valid... Not sure if I could do it better * Increment mangadex.extversioncode --- src/all/mangadex/build.gradle | 2 +- .../extension/all/mangadex/MDConstants.kt | 10 +++++++ .../extension/all/mangadex/MangaDex.kt | 29 +++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/all/mangadex/build.gradle b/src/all/mangadex/build.gradle index 2fed37643..16b4d24bd 100644 --- a/src/all/mangadex/build.gradle +++ b/src/all/mangadex/build.gradle @@ -6,7 +6,7 @@ ext { extName = 'MangaDex' pkgNameSuffix = 'all.mangadex' extClass = '.MangaDexFactory' - extVersionCode = 149 + extVersionCode = 150 isNsfw = true } diff --git a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MDConstants.kt b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MDConstants.kt index c5c1bcfc8..3c2faaacf 100644 --- a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MDConstants.kt +++ b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MDConstants.kt @@ -80,4 +80,14 @@ object MDConstants { fun getOriginalLanguagePrefKey(dexLang: String): String { return "${originalLanguagePref}_$dexLang" } + + private const val blockedGroupsPref = "blockedGroups" + private const val groupMangaPlus = "4f1de6a2-f0c5-4ac5-bce5-02c7dbb67deb" + private const val groupComikey = "8d8ecf83-8d42-4f8c-add8-60963f9f28d9" + private const val groupBilibili = "06a9fecb-b608-4f19-b93c-7caab06b7f44" + private const val groupAzuki = "5fed0576-8b94-4f9a-b6a7-08eecd69800d" + const val blockedGroupsPrefDefaults = "$groupMangaPlus, $groupComikey, $groupBilibili, $groupAzuki" + fun getBlockedGroupsPrefKey(dexLang: String): String { + return "${blockedGroupsPref}_$dexLang" + } } diff --git a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDex.kt b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDex.kt index 9b34a16ba..dfcf5bc5f 100644 --- a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDex.kt +++ b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDex.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.extension.all.mangadex import android.app.Application import android.content.SharedPreferences import android.util.Log +import androidx.preference.EditTextPreference import androidx.preference.ListPreference import androidx.preference.MultiSelectListPreference import androidx.preference.PreferenceScreen @@ -173,6 +174,10 @@ abstract class MangaDex(override val lang: String, val dexLang: String) : MDConstants.getContentRatingPrefKey(dexLang), MDConstants.contentRatingPrefDefaults )?.forEach { addQueryParameter("contentRating[]", it) } + preferences.getString( + MDConstants.getBlockedGroupsPrefKey(dexLang), + MDConstants.blockedGroupsPrefDefaults + )?.split(",")?.forEach { if (it.isNotEmpty()) addQueryParameter("excludedGroups[]", it.trim()) } }.build().toString() return GET(url, headers, CacheControl.FORCE_NETWORK) } @@ -325,6 +330,10 @@ abstract class MangaDex(override val lang: String, val dexLang: String) : addQueryParameter("contentRating[]", "suggestive") addQueryParameter("contentRating[]", "erotica") addQueryParameter("contentRating[]", "pornographic") + preferences.getString( + MDConstants.getBlockedGroupsPrefKey(dexLang), + MDConstants.blockedGroupsPrefDefaults + )?.split(",")?.forEach { if (it.isNotEmpty()) addQueryParameter("excludedGroups[]", it.trim()) } }.build().toString() return GET(url, headers = headers, cache = CacheControl.FORCE_NETWORK) } @@ -501,11 +510,31 @@ abstract class MangaDex(override val lang: String, val dexLang: String) : } } + val blockedGroupsPref = EditTextPreference(screen.context).apply { + key = MDConstants.getBlockedGroupsPrefKey(dexLang) + title = "Block Groups by UUID" + summary = "Chapters from blocked groups will not show up in Latest or Manga feed.\n" + + "Enter as a Comma-separated list of group UUIDs" + setDefaultValue(MDConstants.blockedGroupsPrefDefaults) + setOnPreferenceChangeListener { _, newValue -> + val groupsBlocked = newValue.toString() + .split(",") + .map { it.trim() } + .filter { helper.containsUuid(it) } + .joinToString(separator = ", ") + + preferences.edit() + .putString(MDConstants.getBlockedGroupsPrefKey(dexLang), groupsBlocked) + .commit() + } + } + screen.addPreference(coverQualityPref) screen.addPreference(dataSaverPref) screen.addPreference(standardHttpsPortPref) screen.addPreference(contentRatingPref) screen.addPreference(originalLanguagePref) + screen.addPreference(blockedGroupsPref) } override fun getFilterList(): FilterList =