From 67fcfb842f0983c5b8deb7f2629f3d58414d2ec5 Mon Sep 17 00:00:00 2001 From: Vetle Ledaal Date: Mon, 19 Aug 2024 12:22:10 +0200 Subject: [PATCH] Doujinku: update domain, add override URL setting (#4680) --- src/id/doujinku/build.gradle | 4 +- .../extension/id/doujinku/Doujinku.kt | 65 +++++++++++++++++-- 2 files changed, 61 insertions(+), 8 deletions(-) diff --git a/src/id/doujinku/build.gradle b/src/id/doujinku/build.gradle index a1a5245b6..8d9f17637 100644 --- a/src/id/doujinku/build.gradle +++ b/src/id/doujinku/build.gradle @@ -2,8 +2,8 @@ ext { extName = 'Doujinku' extClass = '.Doujinku' themePkg = 'mangathemesia' - baseUrl = 'https://doujinku.org' - overrideVersionCode = 0 + baseUrl = 'https://doujinku.xyz' + overrideVersionCode = 1 isNsfw = true } diff --git a/src/id/doujinku/src/eu/kanade/tachiyomi/extension/id/doujinku/Doujinku.kt b/src/id/doujinku/src/eu/kanade/tachiyomi/extension/id/doujinku/Doujinku.kt index 1a0e0c918..47d155e09 100644 --- a/src/id/doujinku/src/eu/kanade/tachiyomi/extension/id/doujinku/Doujinku.kt +++ b/src/id/doujinku/src/eu/kanade/tachiyomi/extension/id/doujinku/Doujinku.kt @@ -1,12 +1,65 @@ package eu.kanade.tachiyomi.extension.id.doujinku +import android.app.Application +import android.content.SharedPreferences +import android.widget.Toast +import androidx.preference.PreferenceScreen import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia +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 Doujinku : MangaThemesia( - "Doujinku", - "https://doujinku.org", - "id", - dateFormat = SimpleDateFormat("MMMM d, yyyy", Locale("id")), -) +class Doujinku : + MangaThemesia( + "Doujinku", + "https://doujinku.xyz", + "id", + dateFormat = SimpleDateFormat("MMMM d, yyyy", Locale("id")), + ), + ConfigurableSource { + private val preferences: SharedPreferences = + Injekt.get().getSharedPreferences("source_$id", 0x0000) + + init { + preferences.getString(DEFAULT_BASE_URL_PREF, null).let { prefDefaultBaseUrl -> + if (prefDefaultBaseUrl != super.baseUrl) { + preferences.edit() + .putString(BASE_URL_PREF, super.baseUrl) + .putString(DEFAULT_BASE_URL_PREF, super.baseUrl) + .apply() + } + } + } + + override val baseUrl by lazy { getPrefBaseUrl() } + + 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 + setDefaultValue(super.baseUrl) + dialogTitle = BASE_URL_PREF_TITLE + dialogMessage = "Default: ${super.baseUrl}" + + setOnPreferenceChangeListener { _, _ -> + Toast.makeText(screen.context, RESTART_APP, Toast.LENGTH_LONG).show() + true + } + } + screen.addPreference(baseUrlPref) + } + + private fun getPrefBaseUrl(): String = preferences.getString(BASE_URL_PREF, super.baseUrl)!! + + companion object { + private const val DEFAULT_BASE_URL_PREF = "defaultBaseUrl" + private const val RESTART_APP = "Restart app to apply new setting." + private const val BASE_URL_PREF_TITLE = "Override BaseUrl" + private const val BASE_URL_PREF = "overrideBaseUrl" + private const val BASE_URL_PREF_SUMMARY = + "For temporary uses. Updating the extension will erase this setting." + } +}