From c9e86fbbf704e77f2080667f30ae1956d9168f3b Mon Sep 17 00:00:00 2001 From: Wisest_wizard <76830230+suhan-paradkar@users.noreply.github.com> Date: Mon, 15 Aug 2022 17:53:58 +0100 Subject: [PATCH] Empire Webtoon: Add option to change BaseURL (#12887) --- .../madara/empirewebtoon/src/EmpireWebtoon.kt | 50 ++++++++++++++++++- .../multisrc/madara/MadaraGenerator.kt | 2 +- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/multisrc/overrides/madara/empirewebtoon/src/EmpireWebtoon.kt b/multisrc/overrides/madara/empirewebtoon/src/EmpireWebtoon.kt index d420efd7c..9624e60e6 100644 --- a/multisrc/overrides/madara/empirewebtoon/src/EmpireWebtoon.kt +++ b/multisrc/overrides/madara/empirewebtoon/src/EmpireWebtoon.kt @@ -1,7 +1,55 @@ package eu.kanade.tachiyomi.extension.ar.empirewebtoon +import android.app.Application +import android.content.SharedPreferences +import android.widget.Toast +import androidx.preference.PreferenceScreen +import eu.kanade.tachiyomi.AppInfo 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 EmpireWebtoon : Madara("Empire Webtoon", "https://webtoonempire.com", "ar", SimpleDateFormat("yyyy MMMMM dd", Locale("ar"))) +class EmpireWebtoon : ConfigurableSource, Madara("Empire Webtoon", "https://webtoonempire.com", "ar", SimpleDateFormat("yyyy MMMMM dd", Locale("ar"))) { + + private val defaultBaseUrl = "https://webtoonempire.com" + + override val baseUrl by lazy { getPrefBaseUrl() } + + private val preferences: SharedPreferences by lazy { + Injekt.get().getSharedPreferences("source_$id", 0x0000) + } + + companion object { + private const val RESTART_TACHIYOMI = "Restart Tachiyomi to apply new setting." + private const val BASE_URL_PREF_TITLE = "Override BaseUrl" + private val BASE_URL_PREF = "overrideBaseUrl_v${AppInfo.getVersionName()}" + 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 + title = BASE_URL_PREF_TITLE + summary = BASE_URL_PREF_SUMMARY + this.setDefaultValue(defaultBaseUrl) + dialogTitle = BASE_URL_PREF_TITLE + + setOnPreferenceChangeListener { _, newValue -> + try { + val res = preferences.edit().putString(BASE_URL_PREF, newValue as String).commit() + Toast.makeText(screen.context, RESTART_TACHIYOMI, Toast.LENGTH_LONG).show() + res + } catch (e: Exception) { + e.printStackTrace() + false + } + } + } + screen.addPreference(baseUrlPref) + } + + private fun getPrefBaseUrl(): String = preferences.getString(BASE_URL_PREF, defaultBaseUrl)!! +} diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/madara/MadaraGenerator.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/madara/MadaraGenerator.kt index 63c47207d..fd8c036eb 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/madara/MadaraGenerator.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/madara/MadaraGenerator.kt @@ -98,7 +98,7 @@ class MadaraGenerator : ThemeSourceGenerator { SingleLang("Drope Scan", "https://dropescan.com", "pt-BR", overrideVersionCode = 4), SingleLang("EGY Manga", "https://egymanga.net", "ar", overrideVersionCode = 1), SingleLang("Emperor Scan", "https://emperorscan.com/", "es"), - SingleLang("Empire Webtoon", "https://webtoonempire.com", "ar", isNsfw = true), + SingleLang("Empire Webtoon", "https://webtoonempire.com", "ar", isNsfw = true, overrideVersionCode = 1), SingleLang("Eromanhwas", "https://eromanhwas.com", "en"), SingleLang("Eromiau", "https://www.eromiau.com", "es", isNsfw = true), SingleLang("Esomanga", "http://esomanga.com", "tr"),