Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MangaThemesia] Option to hide paid chapters #6598

Merged
merged 7 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib-multisrc/mangathemesia/assets/i18n/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
@@ -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))"
}
}
2 changes: 1 addition & 1 deletion src/all/thunderscans/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ext {
extClass = '.ThunderScansFactory'
themePkg = 'mangathemesia'
baseUrl = 'https://en-thunderscans.com'
overrideVersionCode = 7
overrideVersionCode = 8
}

apply from: "$rootDir/common.gradle"
lord-ne marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,11 +21,39 @@ class LavaScans : MangaThemesiaAlt(
dateFormat = SimpleDateFormat("MMM d, yyy", Locale("ar")),
) {
override val id = 3209001028102012989

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 ThunderScans : MangaThemesiaAlt(
"Thunder Scans",
"https://en-thunderscans.com",
"en",
mangaUrlDirectory = "/comics",
)
) {
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,
)
}
}
2 changes: 1 addition & 1 deletion src/en/nightscans/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ext {
extClass = '.NightScans'
themePkg = 'mangathemesia'
baseUrl = 'https://nightsup.net'
overrideVersionCode = 8
overrideVersionCode = 9
isNsfw = true
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
)
}
}
Loading