Hiperdex baseUrl option (#15303)

* Hiperdex baseUrl option

* remove ConfigurableSource, fix key

* use buildconfig

* update setOnPreferenceChangeListener
This commit is contained in:
Basara-Hatake 2023-02-12 19:27:27 +01:00 committed by GitHub
parent e1f59a845e
commit 1cddc25554
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 16 deletions

View File

@ -4,15 +4,14 @@ 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.extension.BuildConfig
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 : ConfigurableSource, Madara("Empire Webtoon", "https://webtoonempire.com", "ar", SimpleDateFormat("yyyy MMMMM dd", Locale("ar"))) {
class EmpireWebtoon : Madara("Empire Webtoon", "https://webtoonempire.com", "ar", SimpleDateFormat("yyyy MMMMM dd", Locale("ar"))) {
private val defaultBaseUrl = "https://webtoonempire.com"
@ -25,30 +24,26 @@ class EmpireWebtoon : ConfigurableSource, Madara("Empire Webtoon", "https://webt
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 = "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
key = BASE_URL_PREF
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
}
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

@ -1,7 +1,49 @@
package eu.kanade.tachiyomi.extension.en.hiperdex
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.madara.Madara
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
class Hiperdex : Madara("Hiperdex", "https://1sthiperdex.com", "en") {
override val useNewChapterEndpoint: Boolean = true
private val defaultBaseUrl = "https://1sthiperdex.com"
override val baseUrl by lazy { getPrefBaseUrl() }
private val preferences: SharedPreferences by lazy {
Injekt.get<Application>().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 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

@ -88,7 +88,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, overrideVersionCode = 1),
SingleLang("Empire Webtoon", "https://webtoonempire.com", "ar", isNsfw = true, overrideVersionCode = 2),
SingleLang("Eromiau", "https://www.eromiau.com", "es", isNsfw = true),
SingleLang("Esomanga", "https://esomanga.com", "tr", overrideVersionCode = 1),
SingleLang("Estufa de Cristal", "https://scanestufadecristal.site", "pt-BR", className = "EstufaDeCristal"),
@ -135,7 +135,7 @@ class MadaraGenerator : ThemeSourceGenerator {
SingleLang("HentaiZone", "https://hentaizone.xyz", "fr", isNsfw = true),
SingleLang("HerenScan", "https://herenscan.com", "es"),
SingleLang("HipercooL", "https://hipercool.xyz", "pt-BR", isNsfw = true, className = "Hipercool"),
SingleLang("Hiperdex", "https://1sthiperdex.com", "en", isNsfw = true, overrideVersionCode = 8),
SingleLang("Hiperdex", "https://1sthiperdex.com", "en", isNsfw = true, overrideVersionCode = 9),
SingleLang("Hizomanga", "https://hizomanga.com", "ar", overrideVersionCode = 1),
SingleLang("HM2D", "https://mangadistrict.com/hdoujin", "en", isNsfw = true, overrideVersionCode = 1),
SingleLang("hManhwa", "https://hmanhwa.com", "en", isNsfw = true, overrideVersionCode = 1),