[RU]Remanga domain switcher and optional show paid chapter (#10295)
* [RU]Remanga domain switcher and optional show paid chapter * typos * clarification
This commit is contained in:
parent
7817a5fdde
commit
5cb8df48af
|
@ -6,7 +6,7 @@ ext {
|
|||
extName = 'Remanga'
|
||||
pkgNameSuffix = 'ru.remanga'
|
||||
extClass = '.Remanga'
|
||||
extVersionCode = 39
|
||||
extVersionCode = 40
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
|
|
@ -17,6 +17,7 @@ import android.content.SharedPreferences
|
|||
import android.os.Build
|
||||
import android.text.InputType
|
||||
import android.widget.Toast
|
||||
import androidx.preference.ListPreference
|
||||
import eu.kanade.tachiyomi.lib.dataimage.DataImageInterceptor
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
import eu.kanade.tachiyomi.network.POST
|
||||
|
@ -56,9 +57,17 @@ import java.util.Locale
|
|||
import kotlin.math.absoluteValue
|
||||
import kotlin.random.Random
|
||||
class Remanga : ConfigurableSource, HttpSource() {
|
||||
|
||||
private val preferences: SharedPreferences by lazy {
|
||||
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
|
||||
}
|
||||
|
||||
override val name = "Remanga"
|
||||
|
||||
override val baseUrl = "https://api.remanga.org"
|
||||
private val baseOrig: String = "https://api.remanga.org"
|
||||
private val baseMirr: String = "https://api.xn--80aaig9ahr.xn--c1avg" // https://реманга.орг
|
||||
private var domain: String? = preferences.getString(DOMAIN_PREF, baseOrig)
|
||||
override val baseUrl = domain.toString()
|
||||
|
||||
override val lang = "ru"
|
||||
|
||||
|
@ -71,11 +80,7 @@ class Remanga : ConfigurableSource, HttpSource() {
|
|||
override fun headersBuilder(): Headers.Builder = Headers.Builder()
|
||||
.add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/78.0$userAgentRandomizer")
|
||||
.add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/jxl,image/webp,*/*;q=0.8")
|
||||
.add("Referer", "https://remanga.org")
|
||||
|
||||
private val preferences: SharedPreferences by lazy {
|
||||
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
|
||||
}
|
||||
.add("Referer", baseUrl.replace("api.", ""))
|
||||
|
||||
private fun authIntercept(chain: Interceptor.Chain): Response {
|
||||
val request = chain.request()
|
||||
|
@ -328,8 +333,11 @@ class Remanga : ConfigurableSource, HttpSource() {
|
|||
}
|
||||
|
||||
override fun chapterListParse(response: Response): List<SChapter> {
|
||||
val chapters = json.decodeFromString<SeriesWrapperDto<List<BookDto>>>(response.body!!.string())
|
||||
return chapters.content.filter { !it.is_paid or (it.is_bought == true) }.map { chapter ->
|
||||
var chapters = json.decodeFromString<SeriesWrapperDto<List<BookDto>>>(response.body!!.string()).content
|
||||
if (!preferences.getBoolean(PAID_PREF, false)) {
|
||||
chapters = chapters.filter { !it.is_paid or (it.is_bought == true) }
|
||||
}
|
||||
return chapters.map { chapter ->
|
||||
SChapter.create().apply {
|
||||
chapter_number = chapter.chapter.split(".").take(2).joinToString(".").toFloat()
|
||||
name = chapterName(chapter)
|
||||
|
@ -344,7 +352,7 @@ class Remanga : ConfigurableSource, HttpSource() {
|
|||
|
||||
private fun fixLink(link: String): String {
|
||||
if (!link.startsWith("http")) {
|
||||
return "https://remanga.org$link"
|
||||
return baseUrl.replace("api.", "") + link
|
||||
}
|
||||
return link
|
||||
}
|
||||
|
@ -600,11 +608,6 @@ class Remanga : ConfigurableSource, HttpSource() {
|
|||
SearchFilter("яой", "43")
|
||||
)
|
||||
|
||||
override fun setupPreferenceScreen(screen: androidx.preference.PreferenceScreen) {
|
||||
screen.addPreference(screen.editTextPreference(USERNAME_TITLE, USERNAME_DEFAULT, username))
|
||||
screen.addPreference(screen.editTextPreference(PASSWORD_TITLE, PASSWORD_DEFAULT, password, true))
|
||||
}
|
||||
|
||||
private fun androidx.preference.PreferenceScreen.editTextPreference(title: String, default: String, value: String, isPassword: Boolean = false): androidx.preference.EditTextPreference {
|
||||
return androidx.preference.EditTextPreference(context).apply {
|
||||
key = title
|
||||
|
@ -631,6 +634,42 @@ class Remanga : ConfigurableSource, HttpSource() {
|
|||
}
|
||||
}
|
||||
}
|
||||
override fun setupPreferenceScreen(screen: androidx.preference.PreferenceScreen) {
|
||||
val domainPref = ListPreference(screen.context).apply {
|
||||
key = DOMAIN_PREF
|
||||
title = DOMAIN_PREF_Title
|
||||
entries = arrayOf("Основной (remanga.org)", "Зеркало (реманга.орг)")
|
||||
entryValues = arrayOf(baseOrig, baseMirr)
|
||||
summary = "%s"
|
||||
setDefaultValue(baseOrig)
|
||||
setOnPreferenceChangeListener { _, newValue ->
|
||||
try {
|
||||
val res = preferences.edit().putString(DOMAIN_PREF, newValue as String).commit()
|
||||
val warning = "Для смены домена необходимо перезапустить приложение с полной остановкой."
|
||||
Toast.makeText(screen.context, warning, Toast.LENGTH_LONG).show()
|
||||
res
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
val paidChapterShow = androidx.preference.CheckBoxPreference(screen.context).apply {
|
||||
key = PAID_PREF
|
||||
title = PAID_PREF_Title
|
||||
summary = "Показывает не купленные главы(может вызвать ошибки при обновлении/автозагрузке)"
|
||||
setDefaultValue(false)
|
||||
|
||||
setOnPreferenceChangeListener { _, newValue ->
|
||||
val checkValue = newValue as Boolean
|
||||
preferences.edit().putBoolean(key, checkValue).commit()
|
||||
}
|
||||
}
|
||||
screen.addPreference(domainPref)
|
||||
screen.addPreference(paidChapterShow)
|
||||
screen.addPreference(screen.editTextPreference(USERNAME_TITLE, USERNAME_DEFAULT, username))
|
||||
screen.addPreference(screen.editTextPreference(PASSWORD_TITLE, PASSWORD_DEFAULT, password, true))
|
||||
}
|
||||
|
||||
private fun getPrefUsername(): String = preferences.getString(USERNAME_TITLE, USERNAME_DEFAULT)!!
|
||||
private fun getPrefPassword(): String = preferences.getString(PASSWORD_TITLE, PASSWORD_DEFAULT)!!
|
||||
|
@ -641,10 +680,18 @@ class Remanga : ConfigurableSource, HttpSource() {
|
|||
|
||||
companion object {
|
||||
private val MEDIA_TYPE = "application/json; charset=utf-8".toMediaTypeOrNull()
|
||||
|
||||
private const val USERNAME_TITLE = "Username"
|
||||
private const val USERNAME_DEFAULT = ""
|
||||
private const val PASSWORD_TITLE = "Password"
|
||||
private const val PASSWORD_DEFAULT = ""
|
||||
|
||||
const val PREFIX_SLUG_SEARCH = "slug:"
|
||||
|
||||
private const val DOMAIN_PREF = "REMangaDomain"
|
||||
private const val DOMAIN_PREF_Title = "Выбор домена"
|
||||
|
||||
private const val PAID_PREF = "PaidChapter"
|
||||
private const val PAID_PREF_Title = "Показывать платные главы"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue