NoblesseTranslations: Update domain and add override preference (#3668)

* Update domain + override preference

* Remove lazy
This commit is contained in:
bapeey 2024-06-22 02:25:14 -05:00 committed by Draff
parent 02ddcb00e6
commit e46b669169
No known key found for this signature in database
GPG Key ID: E8A89F3211677653
2 changed files with 60 additions and 8 deletions

View File

@ -2,8 +2,8 @@ ext {
extName = 'Noblesse Translations'
extClass = '.NoblesseTranslations'
themePkg = 'madara'
baseUrl = 'https://www.nobledicion.com'
overrideVersionCode = 3
baseUrl = 'https://www.actualizamrd.com'
overrideVersionCode = 4
}
apply from: "$rootDir/common.gradle"

View File

@ -1,15 +1,31 @@
package eu.kanade.tachiyomi.extension.es.noblessetranslations
import android.app.Application
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.source.ConfigurableSource
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import java.text.SimpleDateFormat
import java.util.Locale
class NoblesseTranslations : Madara(
class NoblesseTranslations :
Madara(
"Noblesse Translations",
"https://www.nobledicion.com",
"https://www.actualizamrd.com",
"es",
dateFormat = SimpleDateFormat("MMMM d, yyyy", Locale("es")),
) {
),
ConfigurableSource {
private val preferences: SharedPreferences =
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
override val baseUrl by lazy { getPrefBaseUrl() }
override val useNewChapterEndpoint = true
override val useLoadMoreRequest = LoadMoreStrategy.Always
override val mangaSubString = "manga"
@ -17,4 +33,40 @@ class NoblesseTranslations : Madara(
override val mangaDetailsSelectorDescription = "div.summary_content > div.post-content div.manga-summary"
override val mangaDetailsSelectorStatus = "div.summary_content > div.post-content div.post-content_item:has(div.summary-heading:contains(Status)) div.summary-content"
override val mangaDetailsSelectorTag = "div.tags-content a.notUsed" // Site uses this for the scanlator
override fun setupPreferenceScreen(screen: PreferenceScreen) {
EditTextPreference(screen.context).apply {
key = BASE_URL_PREF
title = BASE_URL_PREF_TITLE
summary = BASE_URL_PREF_SUMMARY
dialogTitle = BASE_URL_PREF_TITLE
dialogMessage = "URL por defecto:\n${super.baseUrl}"
setDefaultValue(super.baseUrl)
setOnPreferenceChangeListener { _, newValue ->
Toast.makeText(screen.context, RESTART_APP_MESSAGE, Toast.LENGTH_LONG).show()
true
}
}.also { screen.addPreference(it) }
}
private fun getPrefBaseUrl(): String = preferences.getString(BASE_URL_PREF, super.baseUrl)!!
companion object {
private const val BASE_URL_PREF = "overrideBaseUrl"
private const val BASE_URL_PREF_TITLE = "Editar URL de la fuente"
private const val BASE_URL_PREF_SUMMARY = "Para uso temporal, si la extensión se actualiza se perderá el cambio."
private const val DEFAULT_BASE_URL_PREF = "defaultBaseUrl"
private const val RESTART_APP_MESSAGE = "Reinicie la aplicación para aplicar los cambios"
}
init {
preferences.getString(DEFAULT_BASE_URL_PREF, null).let { defaultBaseUrl ->
if (defaultBaseUrl != super.baseUrl) {
preferences.edit()
.putString(BASE_URL_PREF, super.baseUrl)
.putString(DEFAULT_BASE_URL_PREF, super.baseUrl)
.apply()
}
}
}
}