NewToki/ManaToki: migrate preferences (#13560)
* NewToki/ManaToki: migrate preferences * migrate on start
This commit is contained in:
parent
d571a309f5
commit
a5187d9148
|
@ -5,7 +5,7 @@ ext {
|
|||
extName = 'NewToki / ManaToki'
|
||||
pkgNameSuffix = 'ko.newtoki'
|
||||
extClass = '.TokiFactory'
|
||||
extVersionCode = 24
|
||||
extVersionCode = 25
|
||||
isNsfw = true
|
||||
}
|
||||
|
||||
|
|
|
@ -12,14 +12,12 @@ import org.jsoup.nodes.Element
|
|||
* ManaToki is too big to support in a Factory File., So split into separate file.
|
||||
*/
|
||||
|
||||
object ManaToki : NewToki("ManaToki", "comic") {
|
||||
object ManaToki : NewToki("ManaToki", "comic", manaTokiPreferences) {
|
||||
// / ! DO NOT CHANGE THIS ! Only the site name changed from newtoki.
|
||||
override val id = MANATOKI_ID
|
||||
|
||||
override val baseUrl get() = "https://$MANATOKI_PREFIX$domainNumber.net"
|
||||
|
||||
override val preferences = manaTokiPreferences
|
||||
|
||||
private val chapterRegex by lazy { Regex(""" [ \d,~.-]+화$""") }
|
||||
|
||||
fun latestUpdatesElementParse(element: Element): SManga {
|
||||
|
|
|
@ -14,7 +14,6 @@ import eu.kanade.tachiyomi.source.model.SManga
|
|||
import eu.kanade.tachiyomi.source.online.ParsedHttpSource
|
||||
import eu.kanade.tachiyomi.util.asJsoup
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Response
|
||||
import org.jsoup.Jsoup
|
||||
import org.jsoup.nodes.Document
|
||||
|
@ -30,18 +29,17 @@ import java.util.concurrent.TimeUnit
|
|||
*
|
||||
* Based on https://github.com/gnuboard/gnuboard5
|
||||
**/
|
||||
abstract class NewToki(override val name: String, private val boardName: String) : ConfigurableSource, ParsedHttpSource() {
|
||||
abstract class NewToki(
|
||||
override val name: String,
|
||||
private val boardName: String,
|
||||
private val preferences: SharedPreferences,
|
||||
) : ParsedHttpSource(), ConfigurableSource {
|
||||
|
||||
override val lang: String = "ko"
|
||||
override val supportsLatest = true
|
||||
|
||||
override val client: OkHttpClient by lazy {
|
||||
buildClient(withRateLimit = false)
|
||||
}
|
||||
|
||||
protected val rateLimitedClient: OkHttpClient by lazy {
|
||||
buildClient(withRateLimit = true)
|
||||
}
|
||||
override val client by lazy { buildClient(withRateLimit = false) }
|
||||
private val rateLimitedClient by lazy { buildClient(withRateLimit = true) }
|
||||
|
||||
private fun buildClient(withRateLimit: Boolean) =
|
||||
network.cloudflareClient.newBuilder()
|
||||
|
@ -260,10 +258,6 @@ abstract class NewToki(override val name: String, private val boardName: String)
|
|||
// We are able to get the image URL directly from the page list
|
||||
override fun imageUrlParse(document: Document) = throw UnsupportedOperationException("This method should not be called!")
|
||||
|
||||
override fun getFilterList() = FilterList()
|
||||
|
||||
abstract val preferences: SharedPreferences
|
||||
|
||||
override fun setupPreferenceScreen(screen: androidx.preference.PreferenceScreen) {
|
||||
getPreferencesInternal(screen.context).map(screen::addPreference)
|
||||
}
|
||||
|
|
|
@ -6,14 +6,12 @@ import eu.kanade.tachiyomi.source.model.FilterList
|
|||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||
import okhttp3.Request
|
||||
|
||||
object NewTokiWebtoon : NewToki("NewToki", "webtoon") {
|
||||
object NewTokiWebtoon : NewToki("NewToki", "webtoon", newTokiPreferences) {
|
||||
// / ! DO NOT CHANGE THIS ! Prevent to treating as a new site
|
||||
override val id = NEWTOKI_ID
|
||||
|
||||
override val baseUrl get() = "https://$NEWTOKI_PREFIX$domainNumber.com"
|
||||
|
||||
override val preferences = newTokiPreferences
|
||||
|
||||
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
|
||||
val url = ("$baseUrl/webtoon" + (if (page > 1) "/p$page" else "")).toHttpUrl().newBuilder()
|
||||
filters.forEach { filter ->
|
||||
|
|
|
@ -14,8 +14,8 @@ const val NEWTOKI_ID = 1977818283770282459L // "NewToki (Webtoon)/ko/1"
|
|||
const val MANATOKI_PREFIX = "manatoki"
|
||||
const val NEWTOKI_PREFIX = "newtoki"
|
||||
|
||||
val manaTokiPreferences = getSharedPreferences(MANATOKI_ID)
|
||||
val newTokiPreferences = getSharedPreferences(NEWTOKI_ID)
|
||||
val manaTokiPreferences = getSharedPreferences(MANATOKI_ID).migrate()
|
||||
val newTokiPreferences = getSharedPreferences(NEWTOKI_ID).migrate()
|
||||
|
||||
fun getPreferencesInternal(context: Context) = arrayOf(
|
||||
|
||||
|
@ -54,6 +54,22 @@ var SharedPreferences.domainNumber: String
|
|||
val SharedPreferences.rateLimitPeriod: Int
|
||||
get() = getString(RATE_LIMIT_PERIOD_PREF, RATE_LIMIT_PERIOD_DEFAULT)!!.toInt().coerceIn(1, RATE_LIMIT_PERIOD_MAX)
|
||||
|
||||
private fun SharedPreferences.migrate(): SharedPreferences {
|
||||
if ("Override BaseUrl" !in this) return this // already migrated
|
||||
val editor = edit().clear() // clear all legacy preferences listed below
|
||||
val oldValue = try { // this was a long
|
||||
getLong(RATE_LIMIT_PERIOD_PREF, -1).toInt()
|
||||
} catch (_: ClassCastException) {
|
||||
-1
|
||||
}
|
||||
if (oldValue != -1) { // convert to string
|
||||
val newValue = oldValue.coerceIn(1, RATE_LIMIT_PERIOD_MAX)
|
||||
editor.putString(RATE_LIMIT_PERIOD_PREF, newValue.toString())
|
||||
}
|
||||
editor.apply()
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* Don't use the following legacy keys:
|
||||
* - "Override BaseUrl"
|
||||
|
|
Loading…
Reference in New Issue