MangaSwat: Added custom url setting (#16067)

added the custom url setting
This commit is contained in:
OncePunchedMan 2023-04-16 17:01:03 +02:00 committed by GitHub
parent 0bb01b70b8
commit d04dd2f18d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 1 deletions

View File

@ -1,5 +1,10 @@
package eu.kanade.tachiyomi.extension.ar.mangaswat package eu.kanade.tachiyomi.extension.ar.mangaswat
import android.app.Application
import android.content.SharedPreferences
import android.widget.Toast
import androidx.preference.PreferenceScreen
import eu.kanade.tachiyomi.extension.BuildConfig
import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia
import eu.kanade.tachiyomi.network.interceptor.rateLimit import eu.kanade.tachiyomi.network.interceptor.rateLimit
import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.Page
@ -8,6 +13,8 @@ import kotlinx.serialization.decodeFromString
import okhttp3.Headers import okhttp3.Headers
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import org.jsoup.nodes.Document import org.jsoup.nodes.Document
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Locale import java.util.Locale
@ -17,6 +24,14 @@ class MangaSwat : MangaThemesia(
"ar", "ar",
dateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.US), dateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.US),
) { ) {
private val defaultBaseUrl = "https://swatmanga.me"
override val baseUrl by lazy { getPrefBaseUrl() }
private val preferences: SharedPreferences by lazy {
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
}
override val client: OkHttpClient = super.client.newBuilder() override val client: OkHttpClient = super.client.newBuilder()
.rateLimit(1) .rateLimit(1)
.build() .build()
@ -48,4 +63,31 @@ class MangaSwat : MangaThemesia(
val source: String, val source: String,
val images: List<String>, val images: List<String>,
) )
companion object {
private const val RESTART_TACHIYOMI = "Restart Tachiyomi to apply new setting."
private const val BASE_URL_PREF_TITLE = "Override BaseUrl"
private const val BASE_URL_PREF = "overrideBaseUrl_v${BuildConfig.VERSION_CODE}"
private const val BASE_URL_PREF_SUMMARY = "For temporary uses. Updating the extension will erase this setting."
}
override fun setupPreferenceScreen(screen: PreferenceScreen) {
val baseUrlPref = androidx.preference.EditTextPreference(screen.context).apply {
key = BASE_URL_PREF
title = BASE_URL_PREF_TITLE
summary = BASE_URL_PREF_SUMMARY
this.setDefaultValue(defaultBaseUrl)
dialogTitle = BASE_URL_PREF_TITLE
setOnPreferenceChangeListener { _, _ ->
Toast.makeText(screen.context, RESTART_TACHIYOMI, Toast.LENGTH_LONG).show()
true
}
}
screen.addPreference(baseUrlPref)
super.setupPreferenceScreen(screen)
}
private fun getPrefBaseUrl(): String = preferences.getString(BASE_URL_PREF, defaultBaseUrl)!!
} }

View File

@ -68,7 +68,7 @@ class MangaThemesiaGenerator : ThemeSourceGenerator {
SingleLang("MangaWT", "https://mangawt.com", "tr", overrideVersionCode = 5), SingleLang("MangaWT", "https://mangawt.com", "tr", overrideVersionCode = 5),
SingleLang("Mangayaro", "https://mangayaro.net", "id"), SingleLang("Mangayaro", "https://mangayaro.net", "id"),
SingleLang("Manhwa Lover", "https://manhwalover.com", "en", isNsfw = true, overrideVersionCode = 1), SingleLang("Manhwa Lover", "https://manhwalover.com", "en", isNsfw = true, overrideVersionCode = 1),
SingleLang("MangaSwat", "https://swatmanga.me", "ar", overrideVersionCode = 7), SingleLang("MangaSwat", "https://swatmanga.me", "ar", overrideVersionCode = 8),
SingleLang("MangKomik", "https://mangkomik.net", "id", overrideVersionCode = 1), SingleLang("MangKomik", "https://mangkomik.net", "id", overrideVersionCode = 1),
SingleLang("Mangás Chan", "https://mangaschan.com", "pt-BR", className = "MangasChan"), SingleLang("Mangás Chan", "https://mangaschan.com", "pt-BR", className = "MangasChan"),
SingleLang("Manhwa Freak", "https://manhwafreak.com", "en", overrideVersionCode = 1), SingleLang("Manhwa Freak", "https://manhwafreak.com", "en", overrideVersionCode = 1),