From 99605056e33ccdc329a7caf9e458e6a4bc733144 Mon Sep 17 00:00:00 2001 From: Vetle Ledaal Date: Mon, 16 Sep 2024 12:18:54 +0200 Subject: [PATCH] HentaiVN.plus: update domain, add override URL setting (#5073) --- src/vi/hentaivnplus/build.gradle | 4 +- .../extension/vi/hentaivnplus/HentaiVNPlus.kt | 65 +++++++++++++++++-- 2 files changed, 61 insertions(+), 8 deletions(-) diff --git a/src/vi/hentaivnplus/build.gradle b/src/vi/hentaivnplus/build.gradle index 7744a193c..167510e00 100644 --- a/src/vi/hentaivnplus/build.gradle +++ b/src/vi/hentaivnplus/build.gradle @@ -2,8 +2,8 @@ ext { extName = 'HentaiVN.plus' extClass = '.HentaiVNPlus' themePkg = 'madara' - baseUrl = 'https://hentaivn.cafe' - overrideVersionCode = 1 + baseUrl = 'https://hentaivn.fit' + overrideVersionCode = 2 isNsfw = true } diff --git a/src/vi/hentaivnplus/src/eu/kanade/tachiyomi/extension/vi/hentaivnplus/HentaiVNPlus.kt b/src/vi/hentaivnplus/src/eu/kanade/tachiyomi/extension/vi/hentaivnplus/HentaiVNPlus.kt index f95b103bf..eb2931297 100644 --- a/src/vi/hentaivnplus/src/eu/kanade/tachiyomi/extension/vi/hentaivnplus/HentaiVNPlus.kt +++ b/src/vi/hentaivnplus/src/eu/kanade/tachiyomi/extension/vi/hentaivnplus/HentaiVNPlus.kt @@ -1,17 +1,70 @@ package eu.kanade.tachiyomi.extension.vi.hentaivnplus +import android.app.Application +import android.content.SharedPreferences +import android.widget.Toast +import androidx.preference.PreferenceScreen 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 HentaiVNPlus : Madara( - "HentaiVN.plus", - "https://hentaivn.cafe", - "vi", - dateFormat = SimpleDateFormat("MM/dd/yyyy", Locale.ROOT), -) { +class HentaiVNPlus : + Madara( + "HentaiVN.plus", + "https://hentaivn.fit", + "vi", + dateFormat = SimpleDateFormat("MM/dd/yyyy", Locale.ROOT), + ), + ConfigurableSource { override val useLoadMoreRequest = LoadMoreStrategy.Never override val useNewChapterEndpoint = false override val mangaSubString = "truyen-hentai" + + 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 = "Khởi chạy lại ứng dụng để áp dụng thay đổi." + private const val BASE_URL_PREF_TITLE = "Ghi đè URL cơ sở" + private const val BASE_URL_PREF = "overrideBaseUrl" + private const val BASE_URL_PREF_SUMMARY = + "Dành cho sử dụng tạm thời, cập nhật tiện ích sẽ xóa cài đặt." + } }