[RU]AllHentai switcher domain (#9171)

This commit is contained in:
e-shl 2021-09-22 16:55:00 +05:00 committed by GitHub
parent 4138a7ffb2
commit 3f404550d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 3 deletions

View File

@ -5,7 +5,7 @@ ext {
extName = 'AllHentai' extName = 'AllHentai'
pkgNameSuffix = 'ru.allhentai' pkgNameSuffix = 'ru.allhentai'
extClass = '.AllHentai' extClass = '.AllHentai'
extVersionCode = 10 extVersionCode = 11
containsNsfw = true containsNsfw = true
} }

View File

@ -1,9 +1,14 @@
package eu.kanade.tachiyomi.extension.ru.allhentai package eu.kanade.tachiyomi.extension.ru.allhentai
import android.app.Application
import android.content.SharedPreferences
import android.widget.Toast
import androidx.preference.PreferenceScreen
import eu.kanade.tachiyomi.annotations.Nsfw import eu.kanade.tachiyomi.annotations.Nsfw
import eu.kanade.tachiyomi.lib.ratelimit.RateLimitInterceptor import eu.kanade.tachiyomi.lib.ratelimit.RateLimitInterceptor
import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.asObservableSuccess import eu.kanade.tachiyomi.network.asObservableSuccess
import eu.kanade.tachiyomi.source.ConfigurableSource
import eu.kanade.tachiyomi.source.model.Filter import eu.kanade.tachiyomi.source.model.Filter
import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.FilterList
import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.Page
@ -19,17 +24,24 @@ import okhttp3.Response
import org.jsoup.nodes.Document import org.jsoup.nodes.Document
import org.jsoup.nodes.Element import org.jsoup.nodes.Element
import rx.Observable import rx.Observable
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import java.text.ParseException import java.text.ParseException
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Locale import java.util.Locale
import java.util.regex.Pattern import java.util.regex.Pattern
@Nsfw @Nsfw
class AllHentai : ParsedHttpSource() { class AllHentai : ConfigurableSource, ParsedHttpSource() {
private val preferences: SharedPreferences by lazy {
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
}
override val name = "AllHentai" override val name = "AllHentai"
override val baseUrl = "http://24.allhen.online" private var domain: String = preferences.getString(DOMAIN_TITLE, DOMAIN_DEFAULT)!!
override val baseUrl: String = domain
override val lang = "ru" override val lang = "ru"
@ -516,4 +528,32 @@ class AllHentai : ParsedHttpSource() {
private val tagsName = getTagsList().map { private val tagsName = getTagsList().map {
it.name it.name
}.toTypedArray() }.toTypedArray()
override fun setupPreferenceScreen(screen: androidx.preference.PreferenceScreen) {
screen.addPreference(screen.editTextPreference(DOMAIN_TITLE, DOMAIN_DEFAULT, domain))
}
private fun androidx.preference.PreferenceScreen.editTextPreference(title: String, default: String, value: String): androidx.preference.EditTextPreference {
return androidx.preference.EditTextPreference(context).apply {
key = title
this.title = title
summary = value
this.setDefaultValue(default)
dialogTitle = title
setOnPreferenceChangeListener { _, newValue ->
try {
val res = preferences.edit().putString(title, newValue as String).commit()
Toast.makeText(context, "Для смены домена необходимо перезапустить приложение с полной остановкой.", Toast.LENGTH_LONG).show()
res
} catch (e: Exception) {
e.printStackTrace()
false
}
}
}
}
companion object {
private const val DOMAIN_TITLE = "Домен"
private const val DOMAIN_DEFAULT = "http://23.allhen.online"
}
} }