Add baseUrl preference to NS. (#8088)

This commit is contained in:
Alessandro Jean 2021-07-12 21:24:15 -03:00 committed by GitHub
parent 5e29eabd36
commit 64f237fa78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 123 additions and 15 deletions

View File

@ -1,9 +1,16 @@
package eu.kanade.tachiyomi.extension.pt.neoxscanlator package eu.kanade.tachiyomi.extension.pt.neoxscanlator
import android.app.Application
import android.content.SharedPreferences
import android.widget.Toast
import androidx.preference.EditTextPreference
import androidx.preference.PreferenceScreen
import eu.kanade.tachiyomi.BuildConfig
import eu.kanade.tachiyomi.lib.ratelimit.RateLimitInterceptor import eu.kanade.tachiyomi.lib.ratelimit.RateLimitInterceptor
import eu.kanade.tachiyomi.multisrc.madara.Madara import eu.kanade.tachiyomi.multisrc.madara.Madara
import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.asObservable import eu.kanade.tachiyomi.network.asObservable
import eu.kanade.tachiyomi.source.ConfigurableSource
import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.FilterList
import eu.kanade.tachiyomi.source.model.MangasPage import eu.kanade.tachiyomi.source.model.MangasPage
import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.Page
@ -13,17 +20,21 @@ import okhttp3.OkHttpClient
import okhttp3.Request import okhttp3.Request
import okhttp3.Response import okhttp3.Response
import rx.Observable import rx.Observable
import java.lang.Exception import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Locale import java.util.Locale
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import kotlin.Exception
class NeoxScanlator : Madara( class NeoxScanlator :
"Neox Scanlator", Madara(
"https://neoxscans.com", "Neox Scanlator",
"pt-BR", DEFAULT_BASE_URL,
SimpleDateFormat("MMMMM dd, yyyy", Locale("pt", "BR")) "pt-BR",
) { SimpleDateFormat("MMMMM dd, yyyy", Locale("pt", "BR"))
),
ConfigurableSource {
override val client: OkHttpClient = network.cloudflareClient.newBuilder() override val client: OkHttpClient = network.cloudflareClient.newBuilder()
.connectTimeout(1, TimeUnit.MINUTES) .connectTimeout(1, TimeUnit.MINUTES)
@ -35,6 +46,14 @@ class NeoxScanlator : Madara(
override val altName = "Nome alternativo: " override val altName = "Nome alternativo: "
private val preferences: SharedPreferences by lazy {
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
}
override val baseUrl: String by lazy {
preferences.getString(BASE_URL_PREF_KEY, DEFAULT_BASE_URL)!!
}
override fun headersBuilder(): Headers.Builder = super.headersBuilder() override fun headersBuilder(): Headers.Builder = super.headersBuilder()
.add("Accept", ACCEPT) .add("Accept", ACCEPT)
.add("Accept-Language", ACCEPT_LANGUAGE) .add("Accept-Language", ACCEPT_LANGUAGE)
@ -79,6 +98,32 @@ class NeoxScanlator : Madara(
// Only status and order by filter work. // Only status and order by filter work.
override fun getFilterList(): FilterList = FilterList(super.getFilterList().slice(3..4)) override fun getFilterList(): FilterList = FilterList(super.getFilterList().slice(3..4))
override fun setupPreferenceScreen(screen: PreferenceScreen) {
val baseUrlPref = EditTextPreference(screen.context).apply {
key = BASE_URL_PREF_KEY
title = BASE_URL_PREF_TITLE
summary = BASE_URL_PREF_SUMMARY
setDefaultValue(DEFAULT_BASE_URL)
dialogTitle = BASE_URL_PREF_TITLE
dialogMessage = "Padrão: $DEFAULT_BASE_URL"
setOnPreferenceChangeListener { _, newValue ->
try {
val res = preferences.edit()
.putString(BASE_URL_PREF_KEY, newValue as String)
.commit()
Toast.makeText(screen.context, RESTART_TACHIYOMI, Toast.LENGTH_LONG).show()
res
} catch (e: Exception) {
e.printStackTrace()
false
}
}
}
screen.addPreference(baseUrlPref)
}
companion object { companion object {
private const val MIGRATION_MESSAGE = "O URL deste mangá mudou. " + private const val MIGRATION_MESSAGE = "O URL deste mangá mudou. " +
"Faça a migração do Neox para o Neox para atualizar a URL." "Faça a migração do Neox para o Neox para atualizar a URL."
@ -89,6 +134,14 @@ class NeoxScanlator : Madara(
private const val ACCEPT_LANGUAGE = "pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7,es;q=0.6,gl;q=0.5" private const val ACCEPT_LANGUAGE = "pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7,es;q=0.6,gl;q=0.5"
private const val REFERER = "https://google.com/" private const val REFERER = "https://google.com/"
private const val DEFAULT_BASE_URL = "https://neoxscans.com"
private const val BASE_URL_PREF_KEY = "base_url_${BuildConfig.VERSION_NAME}"
private const val BASE_URL_PREF_TITLE = "URL da fonte"
private const val BASE_URL_PREF_SUMMARY = "Para uso temporário. Quando você atualizar a " +
"extensão, esta configuração será apagada."
private const val RESTART_TACHIYOMI = "Reinicie o Tachiyomi para aplicar as configurações."
private val NOVEL_REGEX = "novel|livro".toRegex(RegexOption.IGNORE_CASE) private val NOVEL_REGEX = "novel|livro".toRegex(RegexOption.IGNORE_CASE)
} }
} }

View File

@ -1,22 +1,77 @@
package eu.kanade.tachiyomi.extension.pt.neoxxxscans package eu.kanade.tachiyomi.extension.pt.neoxxxscans
import android.app.Application
import android.content.SharedPreferences
import android.widget.Toast
import androidx.preference.EditTextPreference
import androidx.preference.PreferenceScreen
import eu.kanade.tachiyomi.BuildConfig
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.multisrc.madara.Madara import eu.kanade.tachiyomi.multisrc.madara.Madara
import eu.kanade.tachiyomi.source.ConfigurableSource
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Locale import java.util.Locale
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
@Nsfw @Nsfw
class NeoXXXScans : Madara( class NeoXXXScans :
"NeoXXX Scans", Madara(
"https://xxx.neoxscans.net", "NeoXXX Scans",
"pt-BR", DEFAULT_BASE_URL,
SimpleDateFormat("dd/MM/yyyy", Locale("pt", "BR")) "pt-BR",
) { SimpleDateFormat("dd/MM/yyyy", Locale("pt", "BR"))
),
ConfigurableSource {
override val client: OkHttpClient = super.client.newBuilder() override val client: OkHttpClient = super.client.newBuilder()
.addInterceptor(RateLimitInterceptor(1, 2, TimeUnit.SECONDS)) .addInterceptor(RateLimitInterceptor(1, 2, TimeUnit.SECONDS))
.build() .build()
private val preferences: SharedPreferences by lazy {
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
}
override val baseUrl: String by lazy {
preferences.getString(BASE_URL_PREF_KEY, DEFAULT_BASE_URL)!!
}
override fun setupPreferenceScreen(screen: PreferenceScreen) {
val baseUrlPref = EditTextPreference(screen.context).apply {
key = BASE_URL_PREF_KEY
title = BASE_URL_PREF_TITLE
summary = BASE_URL_PREF_SUMMARY
setDefaultValue(DEFAULT_BASE_URL)
dialogTitle = BASE_URL_PREF_TITLE
dialogMessage = "Padrão: $DEFAULT_BASE_URL"
setOnPreferenceChangeListener { _, newValue ->
try {
val res = preferences.edit()
.putString(BASE_URL_PREF_KEY, newValue as String)
.commit()
Toast.makeText(screen.context, RESTART_TACHIYOMI, Toast.LENGTH_LONG).show()
res
} catch (e: Exception) {
e.printStackTrace()
false
}
}
}
screen.addPreference(baseUrlPref)
}
companion object {
private const val DEFAULT_BASE_URL = "https://xxx.neoxscans.com"
private const val BASE_URL_PREF_KEY = "base_url_${BuildConfig.VERSION_NAME}"
private const val BASE_URL_PREF_TITLE = "URL da fonte"
private const val BASE_URL_PREF_SUMMARY = "Para uso temporário. Quando você atualizar a " +
"extensão, esta configuração será apagada."
private const val RESTART_TACHIYOMI = "Reinicie o Tachiyomi para aplicar as configurações."
}
} }

View File

@ -226,7 +226,7 @@ class MadaraGenerator : ThemeSourceGenerator {
SingleLang("ManyComic", "https://manycomic.com", "en", isNsfw = true, overrideVersionCode = 1), SingleLang("ManyComic", "https://manycomic.com", "en", isNsfw = true, overrideVersionCode = 1),
SingleLang("Mark Scans", "https://markscans.online", "pt-BR", overrideVersionCode = 2), SingleLang("Mark Scans", "https://markscans.online", "pt-BR", overrideVersionCode = 2),
SingleLang("MHentais", "https://mhentais.com", "pt-BR", isNsfw = true), SingleLang("MHentais", "https://mhentais.com", "pt-BR", isNsfw = true),
SingleLang("NeoXXX Scans", "https://xxx.neoxscans.net", "pt-BR", isNsfw = true, overrideVersionCode = 1), SingleLang("NeoXXX Scans", "https://xxx.neoxscans.com", "pt-BR", isNsfw = true, overrideVersionCode = 2),
SingleLang("Midnight Mess Scans", "https://midnightmess.org", "en", isNsfw = true, overrideVersionCode = 5), SingleLang("Midnight Mess Scans", "https://midnightmess.org", "en", isNsfw = true, overrideVersionCode = 5),
SingleLang("Milftoon", "https://milftoon.xxx", "en", isNsfw = true, overrideVersionCode = 2), SingleLang("Milftoon", "https://milftoon.xxx", "en", isNsfw = true, overrideVersionCode = 2),
SingleLang("Mixed Manga", "https://mixedmanga.com", "en", overrideVersionCode = 1), SingleLang("Mixed Manga", "https://mixedmanga.com", "en", overrideVersionCode = 1),
@ -238,7 +238,7 @@ class MadaraGenerator : ThemeSourceGenerator {
SingleLang("NeatManga", "https://neatmanga.com", "en", overrideVersionCode = 1), SingleLang("NeatManga", "https://neatmanga.com", "en", overrideVersionCode = 1),
SingleLang("NekoScan", "https://nekoscan.com", "en", overrideVersionCode = 1), SingleLang("NekoScan", "https://nekoscan.com", "en", overrideVersionCode = 1),
SingleLang("NekoBreaker Scan", "https://nekobreakerscan.com", "pt-BR"), SingleLang("NekoBreaker Scan", "https://nekobreakerscan.com", "pt-BR"),
SingleLang("Neox Scanlator", "https://neoxscans.com", "pt-BR", overrideVersionCode = 6), SingleLang("Neox Scanlator", "https://neoxscans.com", "pt-BR", overrideVersionCode = 7),
SingleLang("Night Comic", "https://www.nightcomic.com", "en", overrideVersionCode = 1), SingleLang("Night Comic", "https://www.nightcomic.com", "en", overrideVersionCode = 1),
SingleLang("Niji Translations", "https://niji-translations.com", "ar"), SingleLang("Niji Translations", "https://niji-translations.com", "ar"),
SingleLang("Ninjavi", "https://ninjavi.com", "ar", overrideVersionCode = 1), SingleLang("Ninjavi", "https://ninjavi.com", "ar", overrideVersionCode = 1),