From 0321569d7734c2cd708b866fb56d01d028c32555 Mon Sep 17 00:00:00 2001 From: bapeey <90949336+bapeey@users.noreply.github.com> Date: Fri, 16 Aug 2024 01:28:09 -0500 Subject: [PATCH] IkigaiMangas: Update domain and add override preference (#4640) Update domain and add preference --- src/es/ikigaimangas/build.gradle | 2 +- .../extension/es/ikigaimangas/IkigaiMangas.kt | 59 ++++++++++++++++--- 2 files changed, 51 insertions(+), 10 deletions(-) diff --git a/src/es/ikigaimangas/build.gradle b/src/es/ikigaimangas/build.gradle index fcc6edb3f..c0030ff46 100644 --- a/src/es/ikigaimangas/build.gradle +++ b/src/es/ikigaimangas/build.gradle @@ -1,7 +1,7 @@ ext { extName = 'Ikigai Mangas' extClass = '.IkigaiMangas' - extVersionCode = 14 + extVersionCode = 15 isNsfw = true } diff --git a/src/es/ikigaimangas/src/eu/kanade/tachiyomi/extension/es/ikigaimangas/IkigaiMangas.kt b/src/es/ikigaimangas/src/eu/kanade/tachiyomi/extension/es/ikigaimangas/IkigaiMangas.kt index f968e0582..3a89426ae 100644 --- a/src/es/ikigaimangas/src/eu/kanade/tachiyomi/extension/es/ikigaimangas/IkigaiMangas.kt +++ b/src/es/ikigaimangas/src/eu/kanade/tachiyomi/extension/es/ikigaimangas/IkigaiMangas.kt @@ -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().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 List<*>.firstInstanceOrNull(): R? = filterIsInstance().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() + } + } } }