IkigaiMangas: Update domain and add override preference (#4640)

Update domain and add preference
This commit is contained in:
bapeey 2024-08-16 01:28:09 -05:00 committed by Draff
parent 08cb43435a
commit 0321569d77
No known key found for this signature in database
GPG Key ID: E8A89F3211677653
2 changed files with 51 additions and 10 deletions

View File

@ -1,7 +1,7 @@
ext {
extName = 'Ikigai Mangas'
extClass = '.IkigaiMangas'
extVersionCode = 14
extVersionCode = 15
isNsfw = true
}

View File

@ -2,6 +2,8 @@ package eu.kanade.tachiyomi.extension.es.ikigaimangas
import android.app.Application
import android.content.SharedPreferences
import android.widget.Toast
import androidx.preference.EditTextPreference
import androidx.preference.PreferenceScreen
import androidx.preference.SwitchPreferenceCompat
import eu.kanade.tachiyomi.lib.cookieinterceptor.CookieInterceptor
@ -31,7 +33,13 @@ import kotlin.concurrent.thread
class IkigaiMangas : HttpSource(), ConfigurableSource {
override val baseUrl: String = "https://visor.ikigaiweb.lat"
private val defaultBaseUrl: String = "https://ikigaimangas.fraviral.com"
private val isCi = System.getenv("CI") == "true"
override val baseUrl get() = when {
isCi -> defaultBaseUrl
else -> preferences.getPrefBaseUrl()
}
private val apiBaseUrl: String = "https://panel.ikigaimangas.com"
override val lang: String = "es"
@ -47,11 +55,13 @@ class IkigaiMangas : HttpSource(), ConfigurableSource {
),
)
override val client = network.cloudflareClient.newBuilder()
.rateLimitHost(baseUrl.toHttpUrl(), 1, 2)
.rateLimitHost(apiBaseUrl.toHttpUrl(), 2, 1)
.addNetworkInterceptor(cookieInterceptor)
.build()
override val client by lazy {
network.cloudflareClient.newBuilder()
.rateLimitHost(baseUrl.toHttpUrl(), 1, 2)
.rateLimitHost(apiBaseUrl.toHttpUrl(), 2, 1)
.addNetworkInterceptor(cookieInterceptor)
.build()
}
private val preferences: SharedPreferences =
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
@ -245,9 +255,23 @@ class IkigaiMangas : HttpSource(), ConfigurableSource {
title = SHOW_NSFW_PREF_TITLE
setDefaultValue(SHOW_NSFW_PREF_DEFAULT)
}.also { screen.addPreference(it) }
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$defaultBaseUrl"
setDefaultValue(defaultBaseUrl)
setOnPreferenceChangeListener { _, _ ->
Toast.makeText(screen.context, RESTART_APP_MESSAGE, Toast.LENGTH_LONG).show()
true
}
}.also { screen.addPreference(it) }
}
private fun SharedPreferences.showNsfwPref() = getBoolean(SHOW_NSFW_PREF, SHOW_NSFW_PREF_DEFAULT)
private fun SharedPreferences.getPrefBaseUrl() = getString(BASE_URL_PREF, defaultBaseUrl)!!
private inline fun <reified R> List<*>.firstInstanceOrNull(): R? =
filterIsInstance<R>().firstOrNull()
@ -255,8 +279,25 @@ class IkigaiMangas : HttpSource(), ConfigurableSource {
private enum class FiltersState { NOT_FETCHED, FETCHING, FETCHED }
companion object {
const val SHOW_NSFW_PREF = "pref_show_nsfw"
const val SHOW_NSFW_PREF_TITLE = "Mostrar contenido NSFW"
const val SHOW_NSFW_PREF_DEFAULT = false
private const val SHOW_NSFW_PREF = "pref_show_nsfw"
private const val SHOW_NSFW_PREF_TITLE = "Mostrar contenido NSFW"
private const val SHOW_NSFW_PREF_DEFAULT = false
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 { domain ->
if (domain != defaultBaseUrl) {
preferences.edit()
.putString(BASE_URL_PREF, defaultBaseUrl)
.putString(DEFAULT_BASE_URL_PREF, defaultBaseUrl)
.apply()
}
}
}
}