diff --git a/lib-multisrc/mangathemesia/assets/i18n/messages_en.properties b/lib-multisrc/mangathemesia/assets/i18n/messages_en.properties index 6b9e8b682..9abeb59d9 100644 --- a/lib-multisrc/mangathemesia/assets/i18n/messages_en.properties +++ b/lib-multisrc/mangathemesia/assets/i18n/messages_en.properties @@ -30,3 +30,5 @@ project_filter_warning=NOTE: Can't be used with other filter! project_filter_name=%s Project List page pref_dynamic_url_title=Automatically update dynamic URLs pref_dynamic_url_summary=Automatically update random numbers in manga URLs.\nHelps mitigating HTTP 404 errors during update and "in library" marks when browsing.\nNote: This setting may require clearing database in advanced settings and migrating all manga to the same source. +pref_hide_paid_chapters_title=Hide chapters which require a purchase +pref_hide_paid_chapters_summary=Hide chapters which must be purchased using coins.\nYou might want to disable this if you want to be notified of paid chapters so that you can go purchase them. diff --git a/lib-multisrc/mangathemesia/src/eu/kanade/tachiyomi/multisrc/mangathemesia/MangaThemesiaPaidChapterHelper.kt b/lib-multisrc/mangathemesia/src/eu/kanade/tachiyomi/multisrc/mangathemesia/MangaThemesiaPaidChapterHelper.kt new file mode 100644 index 000000000..6639c9755 --- /dev/null +++ b/lib-multisrc/mangathemesia/src/eu/kanade/tachiyomi/multisrc/mangathemesia/MangaThemesiaPaidChapterHelper.kt @@ -0,0 +1,30 @@ +package eu.kanade.tachiyomi.multisrc.mangathemesia + +import android.content.SharedPreferences +import androidx.preference.PreferenceScreen +import androidx.preference.SwitchPreferenceCompat +import eu.kanade.tachiyomi.lib.i18n.Intl + +class MangaThemesiaPaidChapterHelper( + private val hidePaidChaptersPrefKey: String = "pref_hide_paid_chapters", + private val lockedChapterSelector: String = "a[data-bs-target='#lockedChapterModal']", +) { + fun addHidePaidChaptersPreferenceToScreen(screen: PreferenceScreen, intl: Intl) { + SwitchPreferenceCompat(screen.context).apply { + key = hidePaidChaptersPrefKey + title = intl["pref_hide_paid_chapters_title"] + summary = intl["pref_hide_paid_chapters_summary"] + setDefaultValue(true) + }.also(screen::addPreference) + } + + fun getHidePaidChaptersPref(preferences: SharedPreferences) = preferences.getBoolean(hidePaidChaptersPrefKey, true) + + fun getChapterListSelectorBasedOnHidePaidChaptersPref(baseChapterListSelector: String, preferences: SharedPreferences): String { + if (!getHidePaidChaptersPref(preferences)) { + return baseChapterListSelector + } + + return ":is($baseChapterListSelector):not($lockedChapterSelector):not(:has($lockedChapterSelector))" + } +} diff --git a/src/all/thunderscans/build.gradle b/src/all/thunderscans/build.gradle index a5fe32ca3..99d5273bc 100644 --- a/src/all/thunderscans/build.gradle +++ b/src/all/thunderscans/build.gradle @@ -3,7 +3,7 @@ ext { extClass = '.ThunderScansFactory' themePkg = 'mangathemesia' baseUrl = 'https://en-thunderscans.com' - overrideVersionCode = 7 + overrideVersionCode = 8 } apply from: "$rootDir/common.gradle" diff --git a/src/all/thunderscans/src/eu/kanade/tachiyomi/extension/all/thunderscans/ThunderScansFactory.kt b/src/all/thunderscans/src/eu/kanade/tachiyomi/extension/all/thunderscans/ThunderScansFactory.kt index ad8bdc369..eb582d2a1 100644 --- a/src/all/thunderscans/src/eu/kanade/tachiyomi/extension/all/thunderscans/ThunderScansFactory.kt +++ b/src/all/thunderscans/src/eu/kanade/tachiyomi/extension/all/thunderscans/ThunderScansFactory.kt @@ -1,6 +1,8 @@ package eu.kanade.tachiyomi.extension.all.thunderscans +import androidx.preference.PreferenceScreen import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesiaAlt +import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesiaPaidChapterHelper import eu.kanade.tachiyomi.source.SourceFactory import java.text.SimpleDateFormat import java.util.Locale @@ -12,7 +14,29 @@ class ThunderScansFactory : SourceFactory { ) } -class LavaScans : MangaThemesiaAlt( +abstract class ThunderScansBase( + name: String, + baseUrl: String, + lang: String, + mangaUrlDirectory: String = "/manga", + dateFormat: SimpleDateFormat = SimpleDateFormat("MMMM dd, yyyy", Locale.US), +) : MangaThemesiaAlt(name, baseUrl, lang, mangaUrlDirectory, dateFormat) { + private val paidChapterHelper = MangaThemesiaPaidChapterHelper() + + override fun setupPreferenceScreen(screen: PreferenceScreen) { + super.setupPreferenceScreen(screen) + paidChapterHelper.addHidePaidChaptersPreferenceToScreen(screen, intl) + } + + override fun chapterListSelector(): String { + return paidChapterHelper.getChapterListSelectorBasedOnHidePaidChaptersPref( + super.chapterListSelector(), + preferences, + ) + } +} + +class LavaScans : ThunderScansBase( "Lava Scans", "https://lavatoons.com", "ar", @@ -21,7 +45,7 @@ class LavaScans : MangaThemesiaAlt( override val id = 3209001028102012989 } -class ThunderScans : MangaThemesiaAlt( +class ThunderScans : ThunderScansBase( "Thunder Scans", "https://en-thunderscans.com", "en", diff --git a/src/en/nightscans/build.gradle b/src/en/nightscans/build.gradle index 2c17f15e1..2e400d31a 100644 --- a/src/en/nightscans/build.gradle +++ b/src/en/nightscans/build.gradle @@ -3,7 +3,7 @@ ext { extClass = '.NightScans' themePkg = 'mangathemesia' baseUrl = 'https://nightsup.net' - overrideVersionCode = 8 + overrideVersionCode = 9 isNsfw = true } diff --git a/src/en/nightscans/src/eu/kanade/tachiyomi/extension/en/nightscans/NightScans.kt b/src/en/nightscans/src/eu/kanade/tachiyomi/extension/en/nightscans/NightScans.kt index 43a9a2c94..b209b1a47 100644 --- a/src/en/nightscans/src/eu/kanade/tachiyomi/extension/en/nightscans/NightScans.kt +++ b/src/en/nightscans/src/eu/kanade/tachiyomi/extension/en/nightscans/NightScans.kt @@ -1,6 +1,8 @@ package eu.kanade.tachiyomi.extension.en.nightscans +import androidx.preference.PreferenceScreen import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesiaAlt +import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesiaPaidChapterHelper import eu.kanade.tachiyomi.network.interceptor.rateLimit import okhttp3.OkHttpClient import java.util.concurrent.TimeUnit @@ -13,4 +15,18 @@ class NightScans : MangaThemesiaAlt("NIGHT SCANS", "https://nightsup.net", "en", override val client: OkHttpClient = super.client.newBuilder() .rateLimit(20, 4, TimeUnit.SECONDS) .build() + + private val paidChapterHelper = MangaThemesiaPaidChapterHelper() + + override fun setupPreferenceScreen(screen: PreferenceScreen) { + super.setupPreferenceScreen(screen) + paidChapterHelper.addHidePaidChaptersPreferenceToScreen(screen, intl) + } + + override fun chapterListSelector(): String { + return paidChapterHelper.getChapterListSelectorBasedOnHidePaidChaptersPref( + super.chapterListSelector(), + preferences, + ) + } }