HentaiVN.plus: update domain, add override URL setting (#5073)

This commit is contained in:
Vetle Ledaal 2024-09-16 12:18:54 +02:00 committed by GitHub
parent 6c556804ea
commit 07dffdbb7e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 61 additions and 8 deletions

View File

@ -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
}

View File

@ -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<Application>().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."
}
}