Skip to content

Commit

Permalink
[MangaThemesia] Option to hide paid chapters (#6598)
Browse files Browse the repository at this point in the history
* Initial implementation

* Move implementation to helper

* Update gradle files

* Formatting

* Use base class
  • Loading branch information
lord-ne authored Dec 24, 2024
1 parent 99bbb29 commit b389786
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 4 deletions.
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"
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 @@ -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",
Expand All @@ -21,7 +45,7 @@ class LavaScans : MangaThemesiaAlt(
override val id = 3209001028102012989
}

class ThunderScans : MangaThemesiaAlt(
class ThunderScans : ThunderScansBase(
"Thunder Scans",
"https://en-thunderscans.com",
"en",
Expand Down
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,
)
}
}

0 comments on commit b389786

Please sign in to comment.