From 8a52a4db06057a4ea047fd8da83093fe5701b86e Mon Sep 17 00:00:00 2001 From: Alessandro Jean Date: Sat, 21 Aug 2021 20:37:28 -0300 Subject: [PATCH] Fix build error due to CookieManager. (#8716) --- .../extension/en/tapastic/Tapastic.kt | 104 +++++++++--------- 1 file changed, 53 insertions(+), 51 deletions(-) diff --git a/src/en/tapastic/src/eu/kanade/tachiyomi/extension/en/tapastic/Tapastic.kt b/src/en/tapastic/src/eu/kanade/tachiyomi/extension/en/tapastic/Tapastic.kt index decdd247a..872ca983c 100644 --- a/src/en/tapastic/src/eu/kanade/tachiyomi/extension/en/tapastic/Tapastic.kt +++ b/src/en/tapastic/src/eu/kanade/tachiyomi/extension/en/tapastic/Tapastic.kt @@ -38,68 +38,30 @@ import java.util.Locale class Tapastic : ConfigurableSource, ParsedHttpSource() { - // Preferences - - private val preferences: SharedPreferences by lazy { - Injekt.get().getSharedPreferences("source_$id", 0x0000) - } - - override fun setupPreferenceScreen(screen: PreferenceScreen) { - val chapterVisibilityPref = SwitchPreferenceCompat(screen.context).apply { - key = CHAPTER_VIS_PREF_KEY - title = "Show paywalled chapters" - summary = "Tapas requires login/payment for some chapters. Enable to always show paywalled chapters." - setDefaultValue(true) - - setOnPreferenceChangeListener { _, newValue -> - val checkValue = newValue as Boolean - preferences.edit().putBoolean(CHAPTER_VIS_PREF_KEY, checkValue).commit() - } - } - screen.addPreference(chapterVisibilityPref) - - val lockPref = SwitchPreferenceCompat(screen.context).apply { - key = SHOW_LOCK_PREF_KEY - title = "Show lock icon" - summary = "Enable to continue showing \uD83D\uDD12 for locked chapters after login." - setDefaultValue(false) - - setOnPreferenceChangeListener { _, newValue -> - val checkValue = newValue as Boolean - preferences.edit().putBoolean(SHOW_LOCK_PREF_KEY, checkValue).commit() - } - } - screen.addPreference(lockPref) - } - - private fun showLockedChapterPref() = preferences.getBoolean(CHAPTER_VIS_PREF_KEY, false) - private fun showLockPref() = preferences.getBoolean(SHOW_LOCK_PREF_KEY, false) - - companion object { - private const val CHAPTER_VIS_PREF_KEY = "lockedChapterVisibility" - private const val SHOW_LOCK_PREF_KEY = "showChapterLock" - } - - // Info - override val lang = "en" - override val supportsLatest = true - override val name = "Tapas" // originally Tapastic - override val baseUrl = "https://tapas.io" + // Originally Tapastic override val id = 3825434541981130345 + override val name = "Tapas" + + override val lang = "en" + + override val baseUrl = "https://tapas.io" + + override val supportsLatest = true + + private val webViewCookieManager: CookieManager by lazy { CookieManager.getInstance() } + override val client: OkHttpClient = super.client.newBuilder() .cookieJar( // Syncs okhttp with webview cookies, allowing logged-in users do logged-in stuff object : CookieJar { - private val webviewCookieManager = CookieManager.getInstance() - override fun saveFromResponse(url: HttpUrl, cookies: List) { for (cookie in cookies) { - webviewCookieManager.setCookie(url.toString(), cookie.toString()) + webViewCookieManager.setCookie(url.toString(), cookie.toString()) } } override fun loadForRequest(url: HttpUrl): MutableList { - val cookiesString = webviewCookieManager.getCookie(url.toString()) + val cookiesString = webViewCookieManager.getCookie(url.toString()) if (cookiesString != null && cookiesString.isNotEmpty()) { val cookieHeaders = cookiesString.split("; ").toList() @@ -134,9 +96,44 @@ class Tapastic : ConfigurableSource, ParsedHttpSource() { ) .build() + private val preferences: SharedPreferences by lazy { + Injekt.get().getSharedPreferences("source_$id", 0x0000) + } + override fun headersBuilder(): Headers.Builder = Headers.Builder() .add("Referer", "https://m.tapas.io") + override fun setupPreferenceScreen(screen: PreferenceScreen) { + val chapterVisibilityPref = SwitchPreferenceCompat(screen.context).apply { + key = CHAPTER_VIS_PREF_KEY + title = "Show paywalled chapters" + summary = "Tapas requires login/payment for some chapters. Enable to always show paywalled chapters." + setDefaultValue(true) + + setOnPreferenceChangeListener { _, newValue -> + val checkValue = newValue as Boolean + preferences.edit().putBoolean(CHAPTER_VIS_PREF_KEY, checkValue).commit() + } + } + screen.addPreference(chapterVisibilityPref) + + val lockPref = SwitchPreferenceCompat(screen.context).apply { + key = SHOW_LOCK_PREF_KEY + title = "Show lock icon" + summary = "Enable to continue showing \uD83D\uDD12 for locked chapters after login." + setDefaultValue(false) + + setOnPreferenceChangeListener { _, newValue -> + val checkValue = newValue as Boolean + preferences.edit().putBoolean(SHOW_LOCK_PREF_KEY, checkValue).commit() + } + } + screen.addPreference(lockPref) + } + + private fun showLockedChapterPref() = preferences.getBoolean(CHAPTER_VIS_PREF_KEY, false) + private fun showLockPref() = preferences.getBoolean(SHOW_LOCK_PREF_KEY, false) + // Popular override fun popularMangaRequest(page: Int): Request = @@ -430,4 +427,9 @@ class Tapastic : ConfigurableSource, ParsedHttpSource() { val isMature: Boolean fun addToUri(uri: HttpUrl.Builder) } + + companion object { + private const val CHAPTER_VIS_PREF_KEY = "lockedChapterVisibility" + private const val SHOW_LOCK_PREF_KEY = "showChapterLock" + } }