From 41039a1bc019d2d5b16171ce2f91c6e185ddf11d Mon Sep 17 00:00:00 2001 From: Vetle Ledaal Date: Sun, 22 Sep 2024 08:47:16 +0200 Subject: [PATCH] LXHentai: update domain and override setting, fix page selector (#5156) --- src/vi/lxhentai/AndroidManifest.xml | 2 +- src/vi/lxhentai/build.gradle | 2 +- .../extension/vi/lxhentai/LxHentai.kt | 57 +++++++++++++++++-- 3 files changed, 55 insertions(+), 6 deletions(-) diff --git a/src/vi/lxhentai/AndroidManifest.xml b/src/vi/lxhentai/AndroidManifest.xml index 441d475c9..029f7f5e9 100644 --- a/src/vi/lxhentai/AndroidManifest.xml +++ b/src/vi/lxhentai/AndroidManifest.xml @@ -14,7 +14,7 @@ diff --git a/src/vi/lxhentai/build.gradle b/src/vi/lxhentai/build.gradle index 25201d3c9..8bb2f17a0 100644 --- a/src/vi/lxhentai/build.gradle +++ b/src/vi/lxhentai/build.gradle @@ -1,7 +1,7 @@ ext { extName = 'LXHentai' extClass = '.LxHentai' - extVersionCode = 7 + extVersionCode = 8 isNsfw = true } diff --git a/src/vi/lxhentai/src/eu/kanade/tachiyomi/extension/vi/lxhentai/LxHentai.kt b/src/vi/lxhentai/src/eu/kanade/tachiyomi/extension/vi/lxhentai/LxHentai.kt index b6ee2a288..c6f09f333 100644 --- a/src/vi/lxhentai/src/eu/kanade/tachiyomi/extension/vi/lxhentai/LxHentai.kt +++ b/src/vi/lxhentai/src/eu/kanade/tachiyomi/extension/vi/lxhentai/LxHentai.kt @@ -1,6 +1,11 @@ package eu.kanade.tachiyomi.extension.vi.lxhentai +import android.app.Application +import android.content.SharedPreferences +import android.widget.Toast +import androidx.preference.PreferenceScreen import eu.kanade.tachiyomi.network.GET +import eu.kanade.tachiyomi.source.ConfigurableSource import eu.kanade.tachiyomi.source.model.Filter import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.MangasPage @@ -16,14 +21,18 @@ import org.jsoup.nodes.Document import org.jsoup.nodes.Element import org.jsoup.select.Evaluator import rx.Observable +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get import java.text.SimpleDateFormat import java.util.Locale -class LxHentai : ParsedHttpSource() { +class LxHentai : ParsedHttpSource(), ConfigurableSource { override val name = "LXHentai" - override val baseUrl = "https://lxmanga.life" + private val defaultBaseUrl = "https://lxmanga.click" + + override val baseUrl by lazy { getPrefBaseUrl() } override val lang = "vi" @@ -176,8 +185,8 @@ class LxHentai : ParsedHttpSource() { } override fun pageListParse(document: Document): List = document - .select("div.text-center img.lazy") - .mapIndexed { idx, element -> Page(idx, "", element.attr("abs:src")) } + .select("div.text-center div.lazy") + .mapIndexed { idx, element -> Page(idx, "", element.attr("abs:data-src")) } override fun imageUrlParse(document: Document) = throw UnsupportedOperationException() @@ -294,9 +303,49 @@ class LxHentai : ParsedHttpSource() { Genre("LXHENTAI", 66), ) + private val preferences: SharedPreferences = + Injekt.get().getSharedPreferences("source_$id", 0x0000) + + init { + preferences.getString(DEFAULT_BASE_URL_PREF, null).let { prefDefaultBaseUrl -> + if (prefDefaultBaseUrl != defaultBaseUrl) { + preferences.edit() + .putString(BASE_URL_PREF, defaultBaseUrl) + .putString(DEFAULT_BASE_URL_PREF, defaultBaseUrl) + .apply() + } + } + } + + 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(defaultBaseUrl) + dialogTitle = BASE_URL_PREF_TITLE + dialogMessage = "Default: $defaultBaseUrl" + + setOnPreferenceChangeListener { _, _ -> + Toast.makeText(screen.context, RESTART_APP, Toast.LENGTH_LONG).show() + true + } + } + screen.addPreference(baseUrlPref) + } + + private fun getPrefBaseUrl(): String = preferences.getString(BASE_URL_PREF, defaultBaseUrl)!! + companion object { const val PREFIX_ID_SEARCH = "id:" val CHAPTER_NUMBER_REGEX = Regex("""[+\-]?([0-9]*[.])?[0-9]+""", RegexOption.IGNORE_CASE) + + 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." } }