TempleScan(es): Add preference for domain change (#8828)
* update domain pref * update domain
This commit is contained in:
parent
a8e083aa40
commit
8fb7d54fee
@ -2,8 +2,8 @@ ext {
|
|||||||
extName = 'Temple Scan'
|
extName = 'Temple Scan'
|
||||||
extClass = '.TempleScanEsp'
|
extClass = '.TempleScanEsp'
|
||||||
themePkg = 'madara'
|
themePkg = 'madara'
|
||||||
baseUrl = 'https://templescanesp.kawi.lat'
|
baseUrl = 'https://templescanesp.vxviral.xyz'
|
||||||
overrideVersionCode = 1
|
overrideVersionCode = 2
|
||||||
isNsfw = true
|
isNsfw = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,29 +1,58 @@
|
|||||||
package eu.kanade.tachiyomi.extension.es.templescanesp
|
package eu.kanade.tachiyomi.extension.es.templescanesp
|
||||||
|
|
||||||
|
import android.content.SharedPreferences
|
||||||
|
import android.widget.Toast
|
||||||
|
import androidx.preference.EditTextPreference
|
||||||
|
import androidx.preference.PreferenceScreen
|
||||||
import eu.kanade.tachiyomi.multisrc.madara.Madara
|
import eu.kanade.tachiyomi.multisrc.madara.Madara
|
||||||
import eu.kanade.tachiyomi.network.interceptor.rateLimitHost
|
import eu.kanade.tachiyomi.network.interceptor.rateLimitHost
|
||||||
|
import eu.kanade.tachiyomi.source.ConfigurableSource
|
||||||
import eu.kanade.tachiyomi.source.model.SChapter
|
import eu.kanade.tachiyomi.source.model.SChapter
|
||||||
import eu.kanade.tachiyomi.source.model.SManga
|
import eu.kanade.tachiyomi.source.model.SManga
|
||||||
|
import keiyoushi.utils.getPreferences
|
||||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||||
import org.jsoup.nodes.Element
|
import org.jsoup.nodes.Element
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
|
||||||
class TempleScanEsp : Madara(
|
class TempleScanEsp :
|
||||||
|
Madara(
|
||||||
"Temple Scan",
|
"Temple Scan",
|
||||||
"https://templescanesp.kawi.lat",
|
"https://templescanesp.vxviral.xyz",
|
||||||
"es",
|
"es",
|
||||||
dateFormat = SimpleDateFormat("MMMM dd, yyyy", Locale("es")),
|
dateFormat = SimpleDateFormat("MMMM dd, yyyy", Locale("es")),
|
||||||
) {
|
),
|
||||||
|
ConfigurableSource {
|
||||||
|
|
||||||
|
private val isCi = System.getenv("CI") == "true"
|
||||||
|
|
||||||
|
override val baseUrl get() = when {
|
||||||
|
isCi -> super.baseUrl
|
||||||
|
else -> preferences.prefBaseUrl
|
||||||
|
}
|
||||||
|
|
||||||
override val versionId = 4
|
override val versionId = 4
|
||||||
|
|
||||||
override val mangaSubString = "serie"
|
override val mangaSubString = "serie"
|
||||||
|
|
||||||
override val useLoadMoreRequest = LoadMoreStrategy.Always
|
override val useLoadMoreRequest = LoadMoreStrategy.Always
|
||||||
|
|
||||||
override val client = super.client.newBuilder()
|
override val client by lazy {
|
||||||
|
super.client.newBuilder()
|
||||||
.rateLimitHost(baseUrl.toHttpUrl(), 3, 1)
|
.rateLimitHost(baseUrl.toHttpUrl(), 3, 1)
|
||||||
.build()
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
private val preferences = getPreferences {
|
||||||
|
this.getString(DEFAULT_BASE_URL_PREF, null).let { domain ->
|
||||||
|
if (domain != super.baseUrl) {
|
||||||
|
this.edit()
|
||||||
|
.putString(BASE_URL_PREF, super.baseUrl)
|
||||||
|
.putString(DEFAULT_BASE_URL_PREF, super.baseUrl)
|
||||||
|
.apply()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun popularMangaSelector() = "div.latest-poster"
|
override fun popularMangaSelector() = "div.latest-poster"
|
||||||
|
|
||||||
@ -57,4 +86,37 @@ class TempleScanEsp : Madara(
|
|||||||
private fun Element.imageFromStyle(): String {
|
private fun Element.imageFromStyle(): String {
|
||||||
return this.attr("style").substringAfter("url(").substringBefore(")")
|
return this.attr("style").substringAfter("url(").substringBefore(")")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun setupPreferenceScreen(screen: PreferenceScreen) {
|
||||||
|
EditTextPreference(screen.context).apply {
|
||||||
|
key = BASE_URL_PREF
|
||||||
|
title = "Editar URL de la fuente"
|
||||||
|
summary = "Para uso temporal, si la extensión se actualiza se perderá el cambio."
|
||||||
|
dialogTitle = "Editar URL de la fuente"
|
||||||
|
dialogMessage = "URL por defecto:\n${super.baseUrl}"
|
||||||
|
setDefaultValue(super.baseUrl)
|
||||||
|
setOnPreferenceChangeListener { _, _ ->
|
||||||
|
Toast.makeText(screen.context, "Reinicie la aplicación para aplicar los cambios", Toast.LENGTH_LONG).show()
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}.also { screen.addPreference(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private var _cachedBaseUrl: String? = null
|
||||||
|
private var SharedPreferences.prefBaseUrl: String
|
||||||
|
get() {
|
||||||
|
if (_cachedBaseUrl == null) {
|
||||||
|
_cachedBaseUrl = getString(BASE_URL_PREF, super.baseUrl)!!
|
||||||
|
}
|
||||||
|
return _cachedBaseUrl!!
|
||||||
|
}
|
||||||
|
set(value) {
|
||||||
|
_cachedBaseUrl = value
|
||||||
|
edit().putString(BASE_URL_PREF, value).apply()
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val BASE_URL_PREF = "overrideBaseUrl"
|
||||||
|
private const val DEFAULT_BASE_URL_PREF = "defaultBaseUrl"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user