[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:
e-shl 2022-01-04 15:44:27 +05:00 committed by GitHub
parent 7817a5fdde
commit 5cb8df48af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 62 additions and 15 deletions

View File

@ -6,7 +6,7 @@ ext {
extName = 'Remanga' extName = 'Remanga'
pkgNameSuffix = 'ru.remanga' pkgNameSuffix = 'ru.remanga'
extClass = '.Remanga' extClass = '.Remanga'
extVersionCode = 39 extVersionCode = 40
} }
dependencies { dependencies {

View File

@ -17,6 +17,7 @@ import android.content.SharedPreferences
import android.os.Build import android.os.Build
import android.text.InputType import android.text.InputType
import android.widget.Toast import android.widget.Toast
import androidx.preference.ListPreference
import eu.kanade.tachiyomi.lib.dataimage.DataImageInterceptor import eu.kanade.tachiyomi.lib.dataimage.DataImageInterceptor
import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.POST import eu.kanade.tachiyomi.network.POST
@ -56,9 +57,17 @@ import java.util.Locale
import kotlin.math.absoluteValue import kotlin.math.absoluteValue
import kotlin.random.Random import kotlin.random.Random
class Remanga : ConfigurableSource, HttpSource() { class Remanga : ConfigurableSource, HttpSource() {
private val preferences: SharedPreferences by lazy {
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
}
override val name = "Remanga" 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" override val lang = "ru"
@ -71,11 +80,7 @@ class Remanga : ConfigurableSource, HttpSource() {
override fun headersBuilder(): Headers.Builder = Headers.Builder() 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("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("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") .add("Referer", baseUrl.replace("api.", ""))
private val preferences: SharedPreferences by lazy {
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
}
private fun authIntercept(chain: Interceptor.Chain): Response { private fun authIntercept(chain: Interceptor.Chain): Response {
val request = chain.request() val request = chain.request()
@ -328,8 +333,11 @@ class Remanga : ConfigurableSource, HttpSource() {
} }
override fun chapterListParse(response: Response): List<SChapter> { override fun chapterListParse(response: Response): List<SChapter> {
val chapters = json.decodeFromString<SeriesWrapperDto<List<BookDto>>>(response.body!!.string()) var chapters = json.decodeFromString<SeriesWrapperDto<List<BookDto>>>(response.body!!.string()).content
return chapters.content.filter { !it.is_paid or (it.is_bought == true) }.map { chapter -> if (!preferences.getBoolean(PAID_PREF, false)) {
chapters = chapters.filter { !it.is_paid or (it.is_bought == true) }
}
return chapters.map { chapter ->
SChapter.create().apply { SChapter.create().apply {
chapter_number = chapter.chapter.split(".").take(2).joinToString(".").toFloat() chapter_number = chapter.chapter.split(".").take(2).joinToString(".").toFloat()
name = chapterName(chapter) name = chapterName(chapter)
@ -344,7 +352,7 @@ class Remanga : ConfigurableSource, HttpSource() {
private fun fixLink(link: String): String { private fun fixLink(link: String): String {
if (!link.startsWith("http")) { if (!link.startsWith("http")) {
return "https://remanga.org$link" return baseUrl.replace("api.", "") + link
} }
return link return link
} }
@ -600,11 +608,6 @@ class Remanga : ConfigurableSource, HttpSource() {
SearchFilter("яой", "43") 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 { private fun androidx.preference.PreferenceScreen.editTextPreference(title: String, default: String, value: String, isPassword: Boolean = false): androidx.preference.EditTextPreference {
return androidx.preference.EditTextPreference(context).apply { return androidx.preference.EditTextPreference(context).apply {
key = title 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 getPrefUsername(): String = preferences.getString(USERNAME_TITLE, USERNAME_DEFAULT)!!
private fun getPrefPassword(): String = preferences.getString(PASSWORD_TITLE, PASSWORD_DEFAULT)!! private fun getPrefPassword(): String = preferences.getString(PASSWORD_TITLE, PASSWORD_DEFAULT)!!
@ -641,10 +680,18 @@ class Remanga : ConfigurableSource, HttpSource() {
companion object { companion object {
private val MEDIA_TYPE = "application/json; charset=utf-8".toMediaTypeOrNull() private val MEDIA_TYPE = "application/json; charset=utf-8".toMediaTypeOrNull()
private const val USERNAME_TITLE = "Username" private const val USERNAME_TITLE = "Username"
private const val USERNAME_DEFAULT = "" private const val USERNAME_DEFAULT = ""
private const val PASSWORD_TITLE = "Password" private const val PASSWORD_TITLE = "Password"
private const val PASSWORD_DEFAULT = "" private const val PASSWORD_DEFAULT = ""
const val PREFIX_SLUG_SEARCH = "slug:" 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 = "Показывать платные главы"
} }
} }