diff --git a/src/pt/hentaiteca/build.gradle b/src/pt/hentaiteca/build.gradle index 5de7c173a..870b3d36e 100644 --- a/src/pt/hentaiteca/build.gradle +++ b/src/pt/hentaiteca/build.gradle @@ -3,8 +3,12 @@ ext { extClass = '.HentaiTeca' themePkg = 'madara' baseUrl = 'https://hentaiteca.net' - overrideVersionCode = 1 + overrideVersionCode = 2 isNsfw = true } apply from: "$rootDir/common.gradle" + +dependencies { + implementation project(':lib:randomua') +} diff --git a/src/pt/hentaiteca/src/eu/kanade/tachiyomi/extension/pt/hentaiteca/HentaiTeca.kt b/src/pt/hentaiteca/src/eu/kanade/tachiyomi/extension/pt/hentaiteca/HentaiTeca.kt index f63de0c24..19fd2a4a2 100644 --- a/src/pt/hentaiteca/src/eu/kanade/tachiyomi/extension/pt/hentaiteca/HentaiTeca.kt +++ b/src/pt/hentaiteca/src/eu/kanade/tachiyomi/extension/pt/hentaiteca/HentaiTeca.kt @@ -1,20 +1,61 @@ package eu.kanade.tachiyomi.extension.pt.hentaiteca +import android.app.Application +import androidx.preference.PreferenceScreen +import eu.kanade.tachiyomi.lib.randomua.addRandomUAPreferenceToScreen +import eu.kanade.tachiyomi.lib.randomua.getPrefCustomUA +import eu.kanade.tachiyomi.lib.randomua.getPrefUAType +import eu.kanade.tachiyomi.lib.randomua.setRandomUserAgent import eu.kanade.tachiyomi.multisrc.madara.Madara import eu.kanade.tachiyomi.network.interceptor.rateLimit +import eu.kanade.tachiyomi.source.ConfigurableSource +import okhttp3.Headers import okhttp3.OkHttpClient +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get import java.text.SimpleDateFormat import java.util.Locale import java.util.concurrent.TimeUnit -class HentaiTeca : Madara( - "Hentai Teca", - "https://hentaiteca.net", - "pt-BR", - SimpleDateFormat("MMMMM dd, yyyy", Locale("pt", "BR")), -) { +class HentaiTeca : + Madara( + "Hentai Teca", + "https://hentaiteca.net", + "pt-BR", + SimpleDateFormat("dd/MM/yyyy", Locale("pt", "BR")), + ), + ConfigurableSource { + + private val preferences = Injekt.get().getSharedPreferences("source_$id", 0x0000) override val client: OkHttpClient = super.client.newBuilder() + .setRandomUserAgent( + preferences.getPrefUAType(), + preferences.getPrefCustomUA(), + ) .rateLimit(1, 2, TimeUnit.SECONDS) .build() + + override fun headersBuilder(): Headers.Builder = super.headersBuilder() + .addCustomUA() + + override val useLoadMoreRequest = LoadMoreStrategy.Never + + override fun setupPreferenceScreen(screen: PreferenceScreen) { + addRandomUAPreferenceToScreen(screen) + } + + /* + * Using Custom UA also in WebView + * */ + private fun Headers.Builder.addCustomUA(): Headers.Builder { + preferences.getPrefCustomUA() + .takeIf { !it.isNullOrBlank() } + ?.let { set(UA_KEY, it) } + return this + } + + companion object { + const val UA_KEY = "User-Agent" + } }