IkigaiMangas: Update domain and add override preference (#4640)
Update domain and add preference
This commit is contained in:
parent
08cb43435a
commit
0321569d77
|
@ -1,7 +1,7 @@
|
||||||
ext {
|
ext {
|
||||||
extName = 'Ikigai Mangas'
|
extName = 'Ikigai Mangas'
|
||||||
extClass = '.IkigaiMangas'
|
extClass = '.IkigaiMangas'
|
||||||
extVersionCode = 14
|
extVersionCode = 15
|
||||||
isNsfw = true
|
isNsfw = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,8 @@ package eu.kanade.tachiyomi.extension.es.ikigaimangas
|
||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
|
import android.widget.Toast
|
||||||
|
import androidx.preference.EditTextPreference
|
||||||
import androidx.preference.PreferenceScreen
|
import androidx.preference.PreferenceScreen
|
||||||
import androidx.preference.SwitchPreferenceCompat
|
import androidx.preference.SwitchPreferenceCompat
|
||||||
import eu.kanade.tachiyomi.lib.cookieinterceptor.CookieInterceptor
|
import eu.kanade.tachiyomi.lib.cookieinterceptor.CookieInterceptor
|
||||||
|
@ -31,7 +33,13 @@ import kotlin.concurrent.thread
|
||||||
|
|
||||||
class IkigaiMangas : HttpSource(), ConfigurableSource {
|
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"
|
private val apiBaseUrl: String = "https://panel.ikigaimangas.com"
|
||||||
|
|
||||||
override val lang: String = "es"
|
override val lang: String = "es"
|
||||||
|
@ -47,11 +55,13 @@ class IkigaiMangas : HttpSource(), ConfigurableSource {
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
override val client = network.cloudflareClient.newBuilder()
|
override val client by lazy {
|
||||||
.rateLimitHost(baseUrl.toHttpUrl(), 1, 2)
|
network.cloudflareClient.newBuilder()
|
||||||
.rateLimitHost(apiBaseUrl.toHttpUrl(), 2, 1)
|
.rateLimitHost(baseUrl.toHttpUrl(), 1, 2)
|
||||||
.addNetworkInterceptor(cookieInterceptor)
|
.rateLimitHost(apiBaseUrl.toHttpUrl(), 2, 1)
|
||||||
.build()
|
.addNetworkInterceptor(cookieInterceptor)
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
private val preferences: SharedPreferences =
|
private val preferences: SharedPreferences =
|
||||||
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
|
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
|
||||||
|
@ -245,9 +255,23 @@ class IkigaiMangas : HttpSource(), ConfigurableSource {
|
||||||
title = SHOW_NSFW_PREF_TITLE
|
title = SHOW_NSFW_PREF_TITLE
|
||||||
setDefaultValue(SHOW_NSFW_PREF_DEFAULT)
|
setDefaultValue(SHOW_NSFW_PREF_DEFAULT)
|
||||||
}.also { screen.addPreference(it) }
|
}.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.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? =
|
private inline fun <reified R> List<*>.firstInstanceOrNull(): R? =
|
||||||
filterIsInstance<R>().firstOrNull()
|
filterIsInstance<R>().firstOrNull()
|
||||||
|
@ -255,8 +279,25 @@ class IkigaiMangas : HttpSource(), ConfigurableSource {
|
||||||
private enum class FiltersState { NOT_FETCHED, FETCHING, FETCHED }
|
private enum class FiltersState { NOT_FETCHED, FETCHING, FETCHED }
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val SHOW_NSFW_PREF = "pref_show_nsfw"
|
private const val SHOW_NSFW_PREF = "pref_show_nsfw"
|
||||||
const val SHOW_NSFW_PREF_TITLE = "Mostrar contenido NSFW"
|
private const val SHOW_NSFW_PREF_TITLE = "Mostrar contenido NSFW"
|
||||||
const val SHOW_NSFW_PREF_DEFAULT = false
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue