diff --git a/build.gradle b/build.gradle index c10799633..b1686df58 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ buildscript { - ext.kotlin_version = '1.4.10' - ext.coroutines_version = '1.3.9' + ext.kotlin_version = '1.4.32' + ext.coroutines_version = '1.4.3' repositories { mavenCentral() google() diff --git a/buildSrc/src/main/kotlin/Config.kt b/buildSrc/src/main/kotlin/Config.kt index 4a296469a..fe87a5100 100644 --- a/buildSrc/src/main/kotlin/Config.kt +++ b/buildSrc/src/main/kotlin/Config.kt @@ -1,6 +1,6 @@ object Config { const val compileSdk = 29 - const val minSdk = 16 + const val minSdk = 21 const val targetSdk = 29 const val buildTools = "29.0.3" } diff --git a/common-dependencies.gradle b/common-dependencies.gradle index 888a3df16..fd767b181 100644 --- a/common-dependencies.gradle +++ b/common-dependencies.gradle @@ -1,18 +1,18 @@ // used both in common.gradle and themesources library dependencies { // Lib 1.2, but using specific commit so we don't need to bump up the version - compileOnly "com.github.tachiyomiorg:extensions-lib:a596412" + compileOnly "com.github.tachiyomiorg:extensions-lib:cc271c3" // These are provided by the app itself compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" compileOnly 'com.github.inorichi.injekt:injekt-core:65b0440' - compileOnly 'com.squareup.okhttp3:okhttp:3.10.0' - compileOnly 'io.reactivex:rxjava:1.3.6' - compileOnly 'org.jsoup:jsoup:1.10.2' - compileOnly 'com.google.code.gson:gson:2.8.2' + compileOnly 'com.squareup.okhttp3:okhttp:4.9.1' + compileOnly 'io.reactivex:rxjava:1.3.8' + compileOnly 'org.jsoup:jsoup:1.13.1' + compileOnly 'com.google.code.gson:gson:2.8.6' compileOnly 'com.github.salomonbrys.kotson:kotson:2.5.0' implementation project(":annotations") compileOnly project(':duktape-stub') -} \ No newline at end of file +} diff --git a/gradle.properties b/gradle.properties index a85c021b0..ae3b5127c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. -org.gradle.jvmargs=-Xmx2048m +org.gradle.jvmargs=-Xmx3072m # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit diff --git a/lib/ratelimit/src/main/java/eu/kanade/tachiyomi/lib/ratelimit/SpecificHostRateLimitInterceptor.kt b/lib/ratelimit/src/main/java/eu/kanade/tachiyomi/lib/ratelimit/SpecificHostRateLimitInterceptor.kt index 3a237c860..b9e8ee9b5 100644 --- a/lib/ratelimit/src/main/java/eu/kanade/tachiyomi/lib/ratelimit/SpecificHostRateLimitInterceptor.kt +++ b/lib/ratelimit/src/main/java/eu/kanade/tachiyomi/lib/ratelimit/SpecificHostRateLimitInterceptor.kt @@ -11,8 +11,8 @@ import java.util.concurrent.TimeUnit * * Examples: * - * httpUrl = Httpurl.parse("api.manga.com"), permits = 5, period = 1, unit = seconds => 5 requests per second to api.manga.com - * httpUrl = Httpurl.parse("imagecdn.manga.com"), permits = 10, period = 2, unit = minutes => 10 requests per 2 minutes to imagecdn.manga.com + * httpUrl = "api.manga.com".toHttpUrlOrNull(), permits = 5, period = 1, unit = seconds => 5 requests per second to api.manga.com + * httpUrl = "imagecdn.manga.com".toHttpUrlOrNull(), permits = 10, period = 2, unit = minutes => 10 requests per 2 minutes to imagecdn.manga.com * * @param httpUrl {HttpUrl} The url host that this interceptor should handle. Will get url's host by using HttpUrl.host() * @param permits {Int} Number of requests allowed within a period of units. diff --git a/multisrc/overrides/eromuse/erofus/src/Erofus.kt b/multisrc/overrides/eromuse/erofus/src/Erofus.kt index 08de650af..f604b9eb3 100644 --- a/multisrc/overrides/eromuse/erofus/src/Erofus.kt +++ b/multisrc/overrides/eromuse/erofus/src/Erofus.kt @@ -7,7 +7,7 @@ import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.MangasPage import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.util.asJsoup -import okhttp3.HttpUrl +import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.Response import rx.Observable @@ -32,7 +32,7 @@ class Erofus : EroMuse("Erofus", "https://www.erofus.com") { pageStack.addLast(StackItem("$baseUrl/?search=$query&sort=$currentSortingMode&page=1", SEARCH_RESULTS_OR_BASE)) } else { val albumFilter = filterList.filterIsInstance().first().selection() - val url = HttpUrl.parse(baseUrl + albumFilter.pathSegments)!!.newBuilder() + val url = (baseUrl + albumFilter.pathSegments).toHttpUrl().newBuilder() .addQueryParameter("sort", currentSortingMode) .addQueryParameter("page", "1") @@ -48,7 +48,7 @@ class Erofus : EroMuse("Erofus", "https://www.erofus.com") { override fun mangaDetailsParse(response: Response): SManga { return SManga.create().apply { with(response.asJsoup()) { - setUrlWithoutDomain(response.request().url().toString()) + setUrlWithoutDomain(response.request.url.toString()) thumbnail_url = select("$albumSelector img").firstOrNull()?.imgAttr() author = when (getAlbumType(url)) { AUTHOR -> { diff --git a/multisrc/overrides/fmreader/heroscan/src/HeroScan.kt b/multisrc/overrides/fmreader/heroscan/src/HeroScan.kt index f5ffa1ade..a03a0e800 100644 --- a/multisrc/overrides/fmreader/heroscan/src/HeroScan.kt +++ b/multisrc/overrides/fmreader/heroscan/src/HeroScan.kt @@ -8,7 +8,7 @@ class HeroScan : FMReader("HeroScan", "https://heroscan.com", "en") { .addInterceptor { chain -> val originalRequest = chain.request() chain.proceed(originalRequest).let { response -> - if (response.code() == 403 && originalRequest.url().host().contains("b-cdn")) { + if (response.code == 403 && originalRequest.url.host.contains("b-cdn")) { response.close() chain.proceed(originalRequest.newBuilder().removeHeader("Referer").addHeader("Referer", "https://isekaiscan.com").build()) } else { diff --git a/multisrc/overrides/fmreader/manhwa18net/src/Manhwa18NetFactory.kt b/multisrc/overrides/fmreader/manhwa18net/src/Manhwa18NetFactory.kt index c91843740..63a63d4fa 100644 --- a/multisrc/overrides/fmreader/manhwa18net/src/Manhwa18NetFactory.kt +++ b/multisrc/overrides/fmreader/manhwa18net/src/Manhwa18NetFactory.kt @@ -24,7 +24,7 @@ class Manhwa18Net : FMReader("Manhwa18.net", "https://manhwa18.net", "en") { GET("$baseUrl/$requestPath?listType=pagination&page=$page&sort=last_update&sort_type=DESC&ungenre=raw", headers) override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { - val noRawsUrl = super.searchMangaRequest(page, query, filters).url().newBuilder().addQueryParameter("ungenre", "raw").toString() + val noRawsUrl = super.searchMangaRequest(page, query, filters).url.newBuilder().addQueryParameter("ungenre", "raw").toString() return GET(noRawsUrl, headers) } @@ -35,7 +35,7 @@ class Manhwa18Net : FMReader("Manhwa18.net", "https://manhwa18.net", "en") { class Manhwa18NetRaw : FMReader("Manhwa18.net", "https://manhwa18.net", "ko") { override val requestPath = "manga-list-genre-raw.html" override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { - val onlyRawsUrl = super.searchMangaRequest(page, query, filters).url().newBuilder().addQueryParameter("genre", "raw").toString() + val onlyRawsUrl = super.searchMangaRequest(page, query, filters).url.newBuilder().addQueryParameter("genre", "raw").toString() return GET(onlyRawsUrl, headers) } diff --git a/multisrc/overrides/foolslide/foolslidecustomizable/src/FoolSlideCustomizableFactory.kt b/multisrc/overrides/foolslide/foolslidecustomizable/src/FoolSlideCustomizableFactory.kt index f566c8341..cfaab650c 100644 --- a/multisrc/overrides/foolslide/foolslidecustomizable/src/FoolSlideCustomizableFactory.kt +++ b/multisrc/overrides/foolslide/foolslidecustomizable/src/FoolSlideCustomizableFactory.kt @@ -5,10 +5,8 @@ import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.SourceFactory import android.app.Application import android.content.SharedPreferences -import android.support.v7.preference.EditTextPreference -import android.support.v7.preference.PreferenceScreen import android.widget.Toast -import eu.kanade.tachiyomi.extension.BuildConfig +import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.source.ConfigurableSource import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -49,30 +47,6 @@ class FoolSlideCustomizable : ConfigurableSource, FoolSlide("FoolSlide Customiza screen.addPreference(baseUrlPref) } - override fun setupPreferenceScreen(screen: PreferenceScreen) { - val baseUrlPref = EditTextPreference(screen.context).apply { - key = BASE_URL_PREF_TITLE - title = BASE_URL_PREF_TITLE - summary = BASE_URL_PREF_SUMMARY - this.setDefaultValue(DEFAULT_BASEURL) - dialogTitle = BASE_URL_PREF_TITLE - dialogMessage = "Default: $DEFAULT_BASEURL" - - setOnPreferenceChangeListener { _, newValue -> - try { - val res = preferences.edit().putString(BASE_URL_PREF, newValue as String).commit() - Toast.makeText(screen.context, RESTART_TACHIYOMI, Toast.LENGTH_LONG).show() - res - } catch (e: Exception) { - e.printStackTrace() - false - } - } - } - - screen.addPreference(baseUrlPref) - } - /** * Tell the user to include /directory/ in the URL even though we remove it * To increase the chance they input a usable URL diff --git a/multisrc/overrides/foolslide/hniscantrad/src/HNIScantradFactory.kt b/multisrc/overrides/foolslide/hniscantrad/src/HNIScantradFactory.kt index 954daa864..88a3e9f17 100644 --- a/multisrc/overrides/foolslide/hniscantrad/src/HNIScantradFactory.kt +++ b/multisrc/overrides/foolslide/hniscantrad/src/HNIScantradFactory.kt @@ -43,7 +43,7 @@ class HNIScantradEN : FoolSlide("HNI-Scantrad", "https://hni-scantrad.com", "en" } } override fun pageListParse(response: Response): List { - return Regex("""imageArray\[\d+]='(.*)'""").findAll(response.body()!!.string()).toList().mapIndexed { i, mr -> + return Regex("""imageArray\[\d+]='(.*)'""").findAll(response.body!!.string()).toList().mapIndexed { i, mr -> Page(i, "", "$baseUrl$urlModifier/${mr.groupValues[1]}") } } diff --git a/multisrc/overrides/madara/doujinhentai/src/DoujinHentai.kt b/multisrc/overrides/madara/doujinhentai/src/DoujinHentai.kt index 54977fcfc..26e2b4f00 100644 --- a/multisrc/overrides/madara/doujinhentai/src/DoujinHentai.kt +++ b/multisrc/overrides/madara/doujinhentai/src/DoujinHentai.kt @@ -6,7 +6,7 @@ import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.source.model.Filter import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.SManga -import okhttp3.HttpUrl +import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.Request import org.jsoup.nodes.Element import java.text.SimpleDateFormat @@ -29,7 +29,7 @@ class DoujinHentai : Madara("DoujinHentai", "https://doujinhentai.net", "es", Si override fun popularMangaNextPageSelector() = "a[rel=next]" override fun latestUpdatesRequest(page: Int): Request = GET("$baseUrl/lista-manga-hentai?orderby=last&page=$page", headers) override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { - val url = HttpUrl.parse(baseUrl)!!.newBuilder() + val url = baseUrl.toHttpUrl().newBuilder() if (query.isNotBlank()) { url.addPathSegment("search") url.addQueryParameter("query", query) // query returns results all on one page diff --git a/multisrc/overrides/madara/manhuaga/src/Manhuaga.kt b/multisrc/overrides/madara/manhuaga/src/Manhuaga.kt index e3c5e23d4..9e8ddf99d 100644 --- a/multisrc/overrides/madara/manhuaga/src/Manhuaga.kt +++ b/multisrc/overrides/madara/manhuaga/src/Manhuaga.kt @@ -8,7 +8,7 @@ class Manhuaga : Madara("Manhuaga", "https://manhuaga.com", "en") { .addInterceptor { chain -> val originalRequest = chain.request() chain.proceed(originalRequest).let { response -> - if (response.code() == 403) { + if (response.code == 403) { response.close() chain.proceed(originalRequest.newBuilder().removeHeader("Referer").addHeader("Referer", "https://manhuaga.com").build()) } else { diff --git a/multisrc/overrides/mangabox/mangakakalots/src/Mangakakalots.kt b/multisrc/overrides/mangabox/mangakakalots/src/Mangakakalots.kt index 184139563..26ad6743d 100644 --- a/multisrc/overrides/mangabox/mangakakalots/src/Mangakakalots.kt +++ b/multisrc/overrides/mangabox/mangakakalots/src/Mangakakalots.kt @@ -10,7 +10,7 @@ class Mangakakalots : MangaBox("Mangakakalots (unoriginal)", "https://mangakakal override fun searchMangaParse(response: Response): MangasPage { val document = response.asJsoup() val mangas = document.select(searchMangaSelector()).map { mangaFromElement(it) } - val hasNextPage = !response.request().url().toString() + val hasNextPage = !response.request.url.toString() .contains(document.select(searchMangaNextPageSelector()).attr("href")) return MangasPage(mangas, hasNextPage) diff --git a/multisrc/overrides/mangasproject/leitornet/src/LeitorNet.kt b/multisrc/overrides/mangasproject/leitornet/src/LeitorNet.kt index ffc5e592e..cd176544f 100644 --- a/multisrc/overrides/mangasproject/leitornet/src/LeitorNet.kt +++ b/multisrc/overrides/mangasproject/leitornet/src/LeitorNet.kt @@ -25,7 +25,7 @@ class LeitorNet : MangasProject("Leitor.net", "https://leitor.net", "pt-BR") { * Temporary fix to bypass Cloudflare. */ override fun pageListRequest(chapter: SChapter): Request { - val newHeaders = super.pageListRequest(chapter).headers().newBuilder() + val newHeaders = super.pageListRequest(chapter).headers.newBuilder() .set("Referer", "https://mangalivre.net/home") .build() diff --git a/multisrc/overrides/mangasproject/mangalivre/src/MangaLivre.kt b/multisrc/overrides/mangasproject/mangalivre/src/MangaLivre.kt index 872834f0b..20f086072 100644 --- a/multisrc/overrides/mangasproject/mangalivre/src/MangaLivre.kt +++ b/multisrc/overrides/mangasproject/mangalivre/src/MangaLivre.kt @@ -21,7 +21,7 @@ class MangaLivre : MangasProject("Mangá Livre", "https://mangalivre.net", "pt-B .build() override fun popularMangaRequest(page: Int): Request { - val originalRequestUrl = super.popularMangaRequest(page).url().toString() + val originalRequestUrl = super.popularMangaRequest(page).url.toString() return GET(originalRequestUrl + DEFAULT_TYPE, sourceHeaders) } @@ -30,7 +30,7 @@ class MangaLivre : MangasProject("Mangá Livre", "https://mangalivre.net", "pt-B return super.searchMangaRequest(page, query, filters) } - val popularRequestUrl = super.popularMangaRequest(page).url().toString() + val popularRequestUrl = super.popularMangaRequest(page).url.toString() val type = filters.filterIsInstance() .firstOrNull()?.selected?.value ?: DEFAULT_TYPE @@ -38,7 +38,7 @@ class MangaLivre : MangasProject("Mangá Livre", "https://mangalivre.net", "pt-B } override fun searchMangaParse(response: Response): MangasPage { - if (response.request().url().pathSegments().contains("search")) { + if (response.request.url.pathSegments.contains("search")) { return super.searchMangaParse(response) } diff --git a/multisrc/overrides/wpmangastream/komikcast/src/KomikCast.kt b/multisrc/overrides/wpmangastream/komikcast/src/KomikCast.kt index a19ede0f5..539ed0ec8 100644 --- a/multisrc/overrides/wpmangastream/komikcast/src/KomikCast.kt +++ b/multisrc/overrides/wpmangastream/komikcast/src/KomikCast.kt @@ -8,7 +8,7 @@ import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga -import okhttp3.HttpUrl +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.OkHttpClient import okhttp3.Request import org.jsoup.nodes.Document @@ -39,7 +39,7 @@ class KomikCast : WPMangaStream("Komik Cast", "https://komikcast.com", "id") { override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { val url = if (query.isNotBlank()) { - val url = HttpUrl.parse("$baseUrl/page/$page")!!.newBuilder() + val url = "$baseUrl/page/$page".toHttpUrlOrNull()!!.newBuilder() val pattern = "\\s+".toRegex() val q = query.replace(pattern, "+") if (query.isNotEmpty()) { @@ -49,7 +49,7 @@ class KomikCast : WPMangaStream("Komik Cast", "https://komikcast.com", "id") { } url.toString() } else { - val url = HttpUrl.parse("$baseUrl/daftar-komik/page/$page")!!.newBuilder() + val url = "$baseUrl/daftar-komik/page/$page".toHttpUrlOrNull()!!.newBuilder() var orderBy: String (if (filters.isEmpty()) getFilterList() else filters).forEach { filter -> when (filter) { diff --git a/multisrc/overrides/wpmangastream/komikgo/src/KomikGO.kt b/multisrc/overrides/wpmangastream/komikgo/src/KomikGO.kt index b2218de10..b1bc14b0d 100644 --- a/multisrc/overrides/wpmangastream/komikgo/src/KomikGO.kt +++ b/multisrc/overrides/wpmangastream/komikgo/src/KomikGO.kt @@ -10,7 +10,7 @@ import okhttp3.Request import org.jsoup.nodes.Document import org.jsoup.nodes.Element import eu.kanade.tachiyomi.source.model.Filter -import okhttp3.HttpUrl +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import eu.kanade.tachiyomi.lib.ratelimit.RateLimitInterceptor import java.util.concurrent.TimeUnit import okhttp3.OkHttpClient @@ -48,7 +48,7 @@ class KomikGO : WPMangaStream("Komik GO", "https://komikgo.com", "id") { } override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { - val url = HttpUrl.parse("$baseUrl/page/$page")!!.newBuilder() + val url = "$baseUrl/page/$page".toHttpUrlOrNull()!!.newBuilder() url.addQueryParameter("post_type", "wp-manga") val pattern = "\\s+".toRegex() val q = query.replace(pattern, "+") diff --git a/multisrc/overrides/wpmangastream/mangaswat/src/MangaSwat.kt b/multisrc/overrides/wpmangastream/mangaswat/src/MangaSwat.kt index e176c1526..8699955b5 100644 --- a/multisrc/overrides/wpmangastream/mangaswat/src/MangaSwat.kt +++ b/multisrc/overrides/wpmangastream/mangaswat/src/MangaSwat.kt @@ -21,7 +21,7 @@ class MangaSwat : WPMangaStream("MangaSwat", "https://mangaswat.com", "ar") { private class Sucuri : Interceptor { override fun intercept(chain: Interceptor.Chain): Response { val response = chain.proceed(chain.request()) - if (response.header("x-sucuri-cache").isNullOrEmpty() && response.request().url().toString().contains("//mangaswat.com")) + if (response.header("x-sucuri-cache").isNullOrEmpty() && response.request.url.toString().contains("//mangaswat.com")) throw IOException("Site protected, open webview | موقع محمي ، عرض ويب مفتوح") return response } diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/comicake/ComiCake.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/comicake/ComiCake.kt index 5114651ce..32ea95e7b 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/comicake/ComiCake.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/comicake/ComiCake.kt @@ -1,7 +1,7 @@ package eu.kanade.tachiyomi.multisrc.comicake import android.os.Build -import eu.kanade.tachiyomi.extensions.BuildConfig +import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.asObservableSuccess import eu.kanade.tachiyomi.source.model.FilterList @@ -45,7 +45,7 @@ abstract class ComiCake( } override fun popularMangaParse(response: Response): MangasPage { - val res = response.body()!!.string() + val res = response.body!!.string() return getMangasPageFromComicsResponse(res) } @@ -97,7 +97,7 @@ abstract class ComiCake( } override fun mangaDetailsParse(response: Response): SManga { - val comicJson = JSONObject(response.body()!!.string()) + val comicJson = JSONObject(response.body!!.string()) return parseComicJson(comicJson, true) } @@ -130,7 +130,7 @@ abstract class ComiCake( } override fun searchMangaParse(response: Response): MangasPage { - val res = response.body()!!.string() + val res = response.body!!.string() return getMangasPageFromComicsResponse(res) } @@ -139,7 +139,7 @@ abstract class ComiCake( } override fun latestUpdatesParse(response: Response): MangasPage { - val res = response.body()!!.string() + val res = response.body!!.string() return getMangasPageFromComicsResponse(res, true) } @@ -156,7 +156,7 @@ abstract class ComiCake( } override fun chapterListParse(response: Response): List { - val chapterJson = JSONObject(response.body()!!.string()) + val chapterJson = JSONObject(response.body!!.string()) val results = chapterJson.getJSONArray("results") val ret = ArrayList() for (i in 0 until results.length()) { @@ -166,7 +166,7 @@ abstract class ComiCake( } override fun pageListParse(response: Response): List { - val webPub = JSONObject(response.body()!!.string()) + val webPub = JSONObject(response.body!!.string()) val readingOrder = webPub.getJSONArray("readingOrder") val ret = ArrayList() for (i in 0 until readingOrder.length()) { diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/eromuse/EroMuse.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/eromuse/EroMuse.kt index 857412f7b..5cf63985d 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/eromuse/EroMuse.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/eromuse/EroMuse.kt @@ -10,7 +10,7 @@ import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.util.asJsoup -import okhttp3.HttpUrl +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.Response @@ -59,9 +59,9 @@ open class EroMuse(override val name: String, override val baseUrl: String) : Ht if (url.contains(pageQueryRegex)) { url.replace(pageQueryRegex, "page=$int") } else { - val httpUrl = HttpUrl.parse(url)!! - val builder = if (httpUrl.pathSegments().last().toIntOrNull() is Int) { - httpUrl.newBuilder().removePathSegment(httpUrl.pathSegments().lastIndex) + val httpUrl = url.toHttpUrlOrNull()!! + val builder = if (httpUrl.pathSegments.last().toIntOrNull() is Int) { + httpUrl.newBuilder().removePathSegment(httpUrl.pathSegments.lastIndex) } else { httpUrl.newBuilder() } @@ -165,7 +165,7 @@ open class EroMuse(override val name: String, override val baseUrl: String) : Ht protected fun stackRequest(): Request { stackItem = pageStack.removeLast() val url = if (stackItem.pageType == AUTHOR && currentSortingMode.isNotEmpty() && !stackItem.url.contains("sort")) { - HttpUrl.parse(stackItem.url)!!.newBuilder().addQueryParameter("sort", currentSortingMode).toString() + stackItem.url.toHttpUrlOrNull()!!.newBuilder().addQueryParameter("sort", currentSortingMode).toString() } else { stackItem.url } @@ -208,14 +208,14 @@ open class EroMuse(override val name: String, override val baseUrl: String) : Ht currentSortingMode = filterList.filterIsInstance().first().toQueryValue() if (query.isNotBlank()) { - val url = HttpUrl.parse("$baseUrl/search?q=$query")!!.newBuilder().apply { + val url = "$baseUrl/search?q=$query".toHttpUrlOrNull()!!.newBuilder().apply { if (currentSortingMode.isNotEmpty()) addQueryParameter("sort", currentSortingMode) addQueryParameter("page", "1") } pageStack.addLast(StackItem(url.toString(), SEARCH_RESULTS_OR_BASE)) } else { val albumFilter = filterList.filterIsInstance().first().selection() - val url = HttpUrl.parse("$baseUrl/comics/${albumFilter.pathSegments}")!!.newBuilder().apply { + val url = "$baseUrl/comics/${albumFilter.pathSegments}".toHttpUrlOrNull()!!.newBuilder().apply { if (currentSortingMode.isNotEmpty()) addQueryParameter("sort", currentSortingMode) if (albumFilter.pageType != AUTHOR) addQueryParameter("page", "1") } @@ -236,7 +236,7 @@ open class EroMuse(override val name: String, override val baseUrl: String) : Ht override fun mangaDetailsParse(response: Response): SManga { return SManga.create().apply { with(response.asJsoup()) { - setUrlWithoutDomain(response.request().url().toString()) + setUrlWithoutDomain(response.request.url.toString()) thumbnail_url = select("$albumSelector img").firstOrNull()?.imgAttr() author = when (getAlbumType(url)) { AUTHOR -> { @@ -278,7 +278,7 @@ open class EroMuse(override val name: String, override val baseUrl: String) : Ht chapters.add( SChapter.create().apply { name = "Chapter" - setUrlWithoutDomain(response.request().url().toString()) + setUrlWithoutDomain(response.request.url.toString()) } ) } diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/fmreader/FMReader.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/fmreader/FMReader.kt index 0b62a19fe..94de1ea25 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/fmreader/FMReader.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/fmreader/FMReader.kt @@ -11,7 +11,7 @@ import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.ParsedHttpSource import eu.kanade.tachiyomi.util.asJsoup import okhttp3.Headers -import okhttp3.HttpUrl +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.Response @@ -62,7 +62,7 @@ abstract class FMReader( GET("$baseUrl/$requestPath?listType=pagination&page=$page&$popularSort&sort_type=DESC", headers) override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { - val url = HttpUrl.parse("$baseUrl/$requestPath?")!!.newBuilder() + val url = "$baseUrl/$requestPath?".toHttpUrlOrNull()!!.newBuilder() .addQueryParameter("name", query) .addQueryParameter("page", page.toString()) (if (filters.isEmpty()) getFilterList() else filters).forEach { filter -> diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/foolslide/FoolSlide.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/foolslide/FoolSlide.kt index d68dbe457..80625f9b1 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/foolslide/FoolSlide.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/foolslide/FoolSlide.kt @@ -135,7 +135,7 @@ abstract class FoolSlide( /** * Transform a GET request into a POST request that automatically authorizes all adult content */ - private fun allowAdult(request: Request) = allowAdult(request.url().toString()) + private fun allowAdult(request: Request) = allowAdult(request.url.toString()) private fun allowAdult(url: String): Request { return POST( diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/luscious/Luscious.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/luscious/Luscious.kt index a651f7eea..502a80a3d 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/luscious/Luscious.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/luscious/Luscious.kt @@ -1,5 +1,10 @@ package eu.kanade.tachiyomi.multisrc.luscious +import android.app.Application +import android.content.SharedPreferences +import androidx.preference.CheckBoxPreference +import androidx.preference.ListPreference +import androidx.preference.PreferenceScreen import com.github.salomonbrys.kotson.addProperty import com.github.salomonbrys.kotson.fromJson import com.github.salomonbrys.kotson.get @@ -9,6 +14,7 @@ import com.google.gson.JsonArray import com.google.gson.JsonObject import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.asObservableSuccess +import eu.kanade.tachiyomi.source.ConfigurableSource import eu.kanade.tachiyomi.source.model.Filter import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.MangasPage @@ -16,23 +22,13 @@ import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.HttpSource -import okhttp3.HttpUrl +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.Response import rx.Observable -import android.app.Application -import android.content.SharedPreferences -import android.net.Uri -import androidx.preference.CheckBoxPreference -import androidx.preference.PreferenceScreen -import androidx.preference.ListPreference -import eu.kanade.tachiyomi.source.ConfigurableSource import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get -import android.support.v7.preference.CheckBoxPreference as LegacyCheckBoxPreference -import android.support.v7.preference.PreferenceScreen as LegacyPreferenceScreen -import android.support.v7.preference.ListPreference as LegacyListPreference abstract class Luscious( override val name: String, @@ -138,7 +134,7 @@ abstract class Luscious( private fun buildAlbumListRequest(page: Int, filters: FilterList, query: String = ""): Request { val input = buildAlbumListRequestInput(page, filters, query) - val url = HttpUrl.parse(apiBaseUrl)!!.newBuilder() + val url = apiBaseUrl.toHttpUrlOrNull()!!.newBuilder() .addQueryParameter("operationName", "AlbumList") .addQueryParameter("query", ALBUM_LIST_REQUEST_GQL) .addQueryParameter("variables", input.toString()) @@ -147,7 +143,7 @@ abstract class Luscious( } private fun parseAlbumListResponse(response: Response): MangasPage { - val data = gson.fromJson(response.body()!!.string()) + val data = gson.fromJson(response.body!!.string()) with(data["data"]["album"]["list"]) { return MangasPage( this["items"].asJsonArray.map { @@ -170,7 +166,7 @@ abstract class Luscious( private fun buildAlbumInfoRequest(id: String): Request { val input = buildAlbumInfoRequestInput(id) - val url = HttpUrl.parse(apiBaseUrl)!!.newBuilder() + val url = apiBaseUrl.toHttpUrlOrNull()!!.newBuilder() .addQueryParameter("operationName", "AlbumGet") .addQueryParameter("query", albumInfoQuery) .addQueryParameter("variables", input.toString()) @@ -208,12 +204,12 @@ abstract class Luscious( false -> { var nextPage = true var page = 2 - val id = response.request().url().queryParameter("variables").toString() + val id = response.request.url.queryParameter("variables").toString() .let { gson.fromJson(it)["input"]["filters"].asJsonArray } .let { it.first { f -> f["name"].asString == "album_id" } } .let { it["value"].asString } - var data = gson.fromJson(response.body()!!.string()) + var data = gson.fromJson(response.body!!.string()) .let { it["data"]["picture"]["list"].asJsonObject } while (nextPage) { @@ -231,7 +227,7 @@ abstract class Luscious( } if (nextPage) { val newPage = client.newCall(GET(buildAlbumPicturesPageUrl(id, page, sortPagesByOption))).execute() - data = gson.fromJson(newPage.body()!!.string()) + data = gson.fromJson(newPage.body!!.string()) .let { it["data"]["picture"]["list"].asJsonObject } } page++ @@ -272,7 +268,7 @@ abstract class Luscious( private fun buildAlbumPicturesPageUrl(id: String, page: Int, sortPagesByOption: String): String { val input = buildAlbumPicturesRequestInput(id, page, sortPagesByOption) - return HttpUrl.parse(apiBaseUrl)!!.newBuilder() + return apiBaseUrl.toHttpUrlOrNull()!!.newBuilder() .addQueryParameter("operationName", "AlbumListOwnPictures") .addQueryParameter("query", ALBUM_PICTURES_REQUEST_GQL) .addQueryParameter("variables", input.toString()) @@ -283,12 +279,12 @@ abstract class Luscious( val pages = mutableListOf() var nextPage = true var page = 2 - val id = response.request().url().queryParameter("variables").toString() + val id = response.request.url.queryParameter("variables").toString() .let { gson.fromJson(it)["input"]["filters"].asJsonArray } .let { it.first { f -> f["name"].asString == "album_id" } } .let { it["value"].asString } - var data = gson.fromJson(response.body()!!.string()) + var data = gson.fromJson(response.body!!.string()) .let { it["data"]["picture"]["list"].asJsonObject } while (nextPage) { @@ -305,7 +301,7 @@ abstract class Luscious( } if (nextPage) { val newPage = client.newCall(GET(buildAlbumPicturesPageUrl(id, page, sortPagesByOption))).execute() - data = gson.fromJson(newPage.body()!!.string()) + data = gson.fromJson(newPage.body!!.string()) .let { it["data"]["picture"]["list"].asJsonObject } } page++ @@ -341,7 +337,7 @@ abstract class Luscious( return client.newCall(GET(page.url, headers)) .asObservableSuccess() .map { - val data = gson.fromJson(it.body()!!.string()).let { data -> + val data = gson.fromJson(it.body!!.string()).let { data -> data["data"]["picture"]["list"].asJsonObject } when (getResolutionPref()){ @@ -360,7 +356,7 @@ abstract class Luscious( } override fun mangaDetailsParse(response: Response): SManga { - val data = gson.fromJson(response.body()!!.string()) + val data = gson.fromJson(response.body!!.string()) with(data["data"]["album"]["get"]) { val manga = SManga.create() manga.url = this["url"].asString @@ -790,37 +786,6 @@ abstract class Luscious( screen.addPreference(mergeChapterPref) } - override fun setupPreferenceScreen(screen: LegacyPreferenceScreen) { - val resolutionPref = LegacyListPreference(screen.context).apply { - key = "${RESOLUTION_PREF_KEY}_$lang" - title = RESOLUTION_PREF_TITLE - entries = RESOLUTION_PREF_ENTRIES - entryValues = RESOLUTION_PREF_ENTRY_VALUES - setDefaultValue(RESOLUTION_PREF_DEFAULT_VALUE) - summary = "%s" - - setOnPreferenceChangeListener { _, newValue -> - val selected = newValue as String - val index = findIndexOfValue(selected) - val entry = entryValues[index] as String - preferences.edit().putString("${RESOLUTION_PREF_KEY}_$lang", entry).commit() - } - } - val mergeChapterPref = LegacyCheckBoxPreference(screen.context).apply { - key = "${MERGE_CHAPTER_PREF_KEY}_$lang" - title = MERGE_CHAPTER_PREF_TITLE - summary = MERGE_CHAPTER_PREF_SUMMARY - setDefaultValue(MERGE_CHAPTER_PREF_DEFAULT_VALUE) - - setOnPreferenceChangeListener { _, newValue -> - val checkValue = newValue as Boolean - preferences.edit().putBoolean("${MERGE_CHAPTER_PREF_KEY}_$lang", checkValue).commit() - } - } - screen.addPreference(resolutionPref) - screen.addPreference(mergeChapterPref) - } - private fun getMergeChapterPref(): Boolean = preferences.getBoolean("${MERGE_CHAPTER_PREF_KEY}_$lang", MERGE_CHAPTER_PREF_DEFAULT_VALUE) private fun getResolutionPref(): String? = preferences.getString("${RESOLUTION_PREF_KEY}_$lang", RESOLUTION_PREF_DEFAULT_VALUE) } diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/madara/Madara.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/madara/Madara.kt index 850c7b0a7..23056fdb5 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/madara/Madara.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/madara/Madara.kt @@ -14,7 +14,7 @@ import eu.kanade.tachiyomi.util.asJsoup import okhttp3.CacheControl import okhttp3.FormBody import okhttp3.Headers -import okhttp3.HttpUrl +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.RequestBody @@ -123,9 +123,9 @@ abstract class Madara( if (!response.isSuccessful) { response.close() // Error message for exceeding last page - if (response.code() == 404) + if (response.code == 404) error("Already on the Last Page!") - else throw Exception("HTTP error ${response.code()}") + else throw Exception("HTTP error ${response.code}") } } .map { response -> @@ -138,7 +138,7 @@ abstract class Madara( protected open fun searchPage(page: Int): String = "page/$page/" override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { - val url = HttpUrl.parse("$baseUrl/${searchPage(page)}")!!.newBuilder() + val url = "$baseUrl/${searchPage(page)}".toHttpUrlOrNull()!!.newBuilder() url.addQueryParameter("s", query) url.addQueryParameter("post_type", "wp-manga") filters.forEach { filter -> diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangabox/MangaBox.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangabox/MangaBox.kt index 84fbcb7ba..9d6644f5a 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangabox/MangaBox.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangabox/MangaBox.kt @@ -10,7 +10,7 @@ import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.ParsedHttpSource import eu.kanade.tachiyomi.util.asJsoup import okhttp3.Headers -import okhttp3.HttpUrl +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.Response @@ -80,7 +80,7 @@ abstract class MangaBox( return if (query.isNotBlank() && getAdvancedGenreFilters().isEmpty()) { GET("$baseUrl/$simpleQueryPath${normalizeSearchQuery(query)}?page=$page", headers) } else { - val url = HttpUrl.parse(baseUrl)!!.newBuilder() + val url = baseUrl.toHttpUrlOrNull()!!.newBuilder() if (getAdvancedGenreFilters().isNotEmpty()) { url.addPathSegment("advanced_search") url.addQueryParameter("page", page.toString()) @@ -206,7 +206,8 @@ abstract class MangaBox( element.select("a").let { url = it.attr("abs:href").substringAfter(baseUrl) // intentionally not using setUrlWithoutDomain name = it.text() - scanlator = HttpUrl.parse(it.attr("abs:href"))!!.host() // show where chapters are actually from + scanlator = + it.attr("abs:href").toHttpUrlOrNull()!!.host // show where chapters are actually from } date_upload = parseChapterDate(element.selectDateFromElement().text(), scanlator!!) ?: 0 } diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangadventure/MangAdventure.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangadventure/MangAdventure.kt index 12661b697..41f0be0c3 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangadventure/MangAdventure.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangadventure/MangAdventure.kt @@ -2,7 +2,7 @@ package eu.kanade.tachiyomi.multisrc.mangadventure import android.net.Uri import android.os.Build.VERSION -import eu.kanade.tachiyomi.extensions.BuildConfig +import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.asObservableSuccess import eu.kanade.tachiyomi.source.model.Filter diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangadventure/MangAdventureExtensions.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangadventure/MangAdventureExtensions.kt index 14e3596c5..6a9ea3c66 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangadventure/MangAdventureExtensions.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangadventure/MangAdventureExtensions.kt @@ -9,7 +9,7 @@ import org.json.JSONObject import java.text.DecimalFormat /** Returns the body of a response as a `String`. */ -fun Response.asString(): String = body()!!.string() +fun Response.asString(): String = body!!.string() /** * Formats the number according to [fmt]. diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangasproject/MangasProject.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangasproject/MangasProject.kt index 83d79de5d..848090bb8 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangasproject/MangasProject.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangasproject/MangasProject.kt @@ -16,7 +16,7 @@ import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.util.asJsoup import okhttp3.FormBody import okhttp3.Headers -import okhttp3.HttpUrl +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.Response @@ -64,7 +64,7 @@ abstract class MangasProject( val popularMangas = result["most_read"].array .map { popularMangaItemParse(it.obj) } - val hasNextPage = response.request().url().queryParameter("page")!!.toInt() < 10 + val hasNextPage = response.request.url.queryParameter("page")!!.toInt() < 10 return MangasPage(popularMangas, hasNextPage) } @@ -85,7 +85,7 @@ abstract class MangasProject( val latestMangas = result["releases"].array .map { latestMangaItemParse(it.obj) } - val hasNextPage = response.request().url().queryParameter("page")!!.toInt() < 5 + val hasNextPage = response.request.url.queryParameter("page")!!.toInt() < 5 return MangasPage(latestMangas, hasNextPage) } @@ -197,7 +197,7 @@ abstract class MangasProject( throw Exception(MANGA_REMOVED) } - val mangaUrl = response.request().url().toString().replace(baseUrl, "") + val mangaUrl = response.request.url.toString().replace(baseUrl, "") val mangaId = mangaUrl.substringAfterLast("/") var page = 1 @@ -277,13 +277,13 @@ abstract class MangasProject( } open fun getChapterUrl(response: Response): String { - return response.request().url().toString() + return response.request.url.toString() } protected open fun getReaderToken(document: Document): String? { return document.select("script[src*=\"reader.\"]").firstOrNull() ?.attr("abs:src") - ?.let { HttpUrl.parse(it) } + ?.let { it.toHttpUrlOrNull() } ?.queryParameter("token") } @@ -301,10 +301,10 @@ abstract class MangasProject( private fun Response.asJsonObject(): JsonObject { if (!isSuccessful) { - throw Exception("HTTP error ${code()}") + throw Exception("HTTP error $code") } - return JSON_PARSER.parse(body()!!.string()).obj + return JSON_PARSER.parse(body!!.string()).obj } private fun String.toDate(): Long { diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/nepnep/NepNep.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/nepnep/NepNep.kt index 4cb8df952..2f201779b 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/nepnep/NepNep.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/nepnep/NepNep.kt @@ -259,7 +259,7 @@ abstract class NepNep( val indexChapter = json["Chapter"].string SChapter.create().apply { name = json["ChapterName"].nullString.let { if (it.isNullOrEmpty()) "${json["Type"].string} ${chapterImage(indexChapter, true)}" else it } - url = "/read-online/" + response.request().url().toString().substringAfter("/manga/") + chapterURLEncode(indexChapter) + url = "/read-online/" + response.request.url.toString().substringAfter("/manga/") + chapterURLEncode(indexChapter) date_upload = try { json["Date"].nullString?.let { dateFormat.parse("$it +0600")?.time } ?: 0 } catch (_: Exception) { diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/nyahentai/NyaHentai.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/nyahentai/NyaHentai.kt index dc754b0d4..b60fd7ae9 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/nyahentai/NyaHentai.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/nyahentai/NyaHentai.kt @@ -112,7 +112,7 @@ abstract class NyaHentai ( listOf( SChapter.create().apply { name = "Single Chapter" - setUrlWithoutDomain(response.request().url().toString()) + setUrlWithoutDomain(response.request.url.toString()) } ) } @@ -185,7 +185,7 @@ abstract class NyaHentai ( } override fun searchMangaParse(response: Response): MangasPage { - return if (response.request().url().toString().contains("tag?")) { + return if (response.request.url.toString().contains("tag?")) { response.asJsoup().select("table.table tbody tr a:first-of-type").attr("abs:href").let { if (it.isNotEmpty()) { tagUrl = it diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/paprika/Paprika.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/paprika/Paprika.kt index b3f995da9..a13051ba3 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/paprika/Paprika.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/paprika/Paprika.kt @@ -8,7 +8,7 @@ import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.ParsedHttpSource import eu.kanade.tachiyomi.util.asJsoup -import okhttp3.HttpUrl +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.Response @@ -67,7 +67,7 @@ abstract class Paprika( return if (query.isNotBlank()) { GET("$baseUrl/search?q=$query&page=$page") } else { - val url = HttpUrl.parse("$baseUrl/mangas/")!!.newBuilder() + val url = "$baseUrl/mangas/".toHttpUrlOrNull()!!.newBuilder() filters.forEach { filter -> when (filter) { is GenreFilter -> url.addPathSegment(filter.toUriPart()) diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/paprika/PaprikaAlt.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/paprika/PaprikaAlt.kt index d5f3c158b..04b728757 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/paprika/PaprikaAlt.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/paprika/PaprikaAlt.kt @@ -5,7 +5,7 @@ import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.util.asJsoup -import okhttp3.HttpUrl +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.Request import okhttp3.Response import org.jsoup.nodes.Document @@ -36,7 +36,7 @@ abstract class PaprikaAlt( return if (query.isNotBlank()) { GET("$baseUrl/search?s=$query&post_type=manga&page=$page") } else { - val url = HttpUrl.parse("$baseUrl/genres/")!!.newBuilder() + val url = "$baseUrl/genres/".toHttpUrlOrNull()!!.newBuilder() filters.forEach { filter -> when (filter) { is GenreFilter -> url.addPathSegment(filter.toUriPart()) diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/webtoons/Webtoons.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/webtoons/Webtoons.kt index 109c81048..f8112ccc0 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/webtoons/Webtoons.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/webtoons/Webtoons.kt @@ -5,12 +5,17 @@ import eu.kanade.tachiyomi.source.model.Filter.Header import eu.kanade.tachiyomi.source.model.Filter.Select import eu.kanade.tachiyomi.source.model.Filter.Separator import eu.kanade.tachiyomi.source.model.FilterList +import eu.kanade.tachiyomi.source.model.MangasPage +import eu.kanade.tachiyomi.source.model.Page +import eu.kanade.tachiyomi.source.model.SChapter +import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.ParsedHttpSource import eu.kanade.tachiyomi.util.asJsoup import okhttp3.Cookie import okhttp3.CookieJar import okhttp3.Headers import okhttp3.HttpUrl +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.Response @@ -18,12 +23,8 @@ import org.json.JSONObject import org.jsoup.nodes.Document import org.jsoup.nodes.Element import java.text.SimpleDateFormat -import eu.kanade.tachiyomi.source.model.Page -import eu.kanade.tachiyomi.source.model.SChapter -import eu.kanade.tachiyomi.source.model.SManga -import eu.kanade.tachiyomi.source.model.MangasPage -import java.util.Locale import java.util.Calendar +import java.util.Locale open class Webtoons( override val name: String, @@ -129,7 +130,7 @@ open class Webtoons( override fun latestUpdatesNextPageSelector(): String? = null override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { - val url = HttpUrl.parse("$baseUrl/$langCode/search?keyword=$query")?.newBuilder()!! + val url = "$baseUrl/$langCode/search?keyword=$query".toHttpUrlOrNull()?.newBuilder()!! val uriPart = (filters.find { it is SearchType } as? SearchType)?.toUriPart() ?: "" url.addQueryParameter("searchType", uriPart) @@ -232,7 +233,7 @@ open class Webtoons( val docUrl = docUrlRegex.find(docString)!!.destructured.toList()[0] val motiontoonPath = motiontoonPathRegex.find(docString)!!.destructured.toList()[0] - val motiontoonJson = JSONObject(client.newCall(GET(docUrl, headers)).execute().body()!!.string()).getJSONObject("assets").getJSONObject("image") + val motiontoonJson = JSONObject(client.newCall(GET(docUrl, headers)).execute().body!!.string()).getJSONObject("assets").getJSONObject("image") val keys = motiontoonJson.keys().asSequence().toList().filter { it.contains("layer") } diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/webtoons/WebtoonsTranslate.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/webtoons/WebtoonsTranslate.kt index dfb7749e5..e8d186e12 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/webtoons/WebtoonsTranslate.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/webtoons/WebtoonsTranslate.kt @@ -8,7 +8,7 @@ import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga import okhttp3.Headers -import okhttp3.HttpUrl +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.Request import okhttp3.Response import org.json.JSONObject @@ -26,8 +26,8 @@ open class WebtoonsTranslate ( // popularMangaRequest already returns manga sorted by latest update override val supportsLatest = false - private val apiBaseUrl = HttpUrl.parse("https://global.apis.naver.com")!! - private val mobileBaseUrl = HttpUrl.parse("https://m.webtoons.com")!! + private val apiBaseUrl = "https://global.apis.naver.com".toHttpUrlOrNull()!! + private val mobileBaseUrl = "https://m.webtoons.com".toHttpUrlOrNull()!! private val thumbnailBaseUrl = "https://mwebtoon-phinf.pstatic.net" private val pageListUrlPattern = "/lineWebtoon/ctrans/translatedEpisodeDetail_jsonp.json?titleNo=%s&episodeNo=%d&languageCode=%s&teamVersion=%d" @@ -56,11 +56,11 @@ open class WebtoonsTranslate ( override fun popularMangaRequest(page: Int): Request = mangaRequest(page, pageSize) override fun popularMangaParse(response: Response): MangasPage { - val offset = response.request().url().queryParameter("offset")!!.toInt() + val offset = response.request.url.queryParameter("offset")!!.toInt() var totalCount: Int val mangas = mutableListOf() - JSONObject(response.body()!!.string()).let { json -> + JSONObject(response.body!!.string()).let { json -> json.getString("code").let { code -> if (code != "000") throw Exception("Error getting popular manga: error code $code") } @@ -118,7 +118,7 @@ open class WebtoonsTranslate ( private fun searchMangaParse(response: Response, query: String): MangasPage { val mangas = mutableListOf() - JSONObject(response.body()!!.string()).let { json -> + JSONObject(response.body!!.string()).let { json -> json.getString("code").let { code -> if (code != "000") throw Exception("Error getting manga: error code $code") } @@ -168,7 +168,7 @@ open class WebtoonsTranslate ( override fun pageListParse(document: Document): List = throw Exception("Not used") override fun chapterListRequest(manga: SManga): Request { - val titleNo = HttpUrl.parse(manga.url)!! + val titleNo = manga.url.toHttpUrlOrNull()!! .queryParameter("titleNo") val chapterUrl = apiBaseUrl .resolve("/lineWebtoon/ctrans/translatedEpisodes_jsonp.json")!! @@ -182,7 +182,7 @@ open class WebtoonsTranslate ( } override fun chapterListParse(response: Response): List { - val chapterData = response.body()!!.string() + val chapterData = response.body!!.string() val chapterJson = JSONObject(chapterData) val responseCode = chapterJson.getString("code") if (responseCode != "000") { @@ -217,7 +217,7 @@ open class WebtoonsTranslate ( } override fun pageListParse(response: Response): List { - val pageJson = JSONObject(response.body()!!.string()) + val pageJson = JSONObject(response.body!!.string()) val results = pageJson.getJSONObject("result").getJSONArray("imageInfo") val ret = ArrayList() for (i in 0 until results.length()) { diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/wpcomics/WPComics.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/wpcomics/WPComics.kt index dda9c1cbc..9ec6ad39f 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/wpcomics/WPComics.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/wpcomics/WPComics.kt @@ -8,7 +8,7 @@ import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.ParsedHttpSource import okhttp3.Headers -import okhttp3.HttpUrl +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.OkHttpClient import okhttp3.Request import org.jsoup.nodes.Document @@ -78,7 +78,7 @@ abstract class WPComics( return if (filterList.isEmpty()) { GET("$baseUrl/?s=$query&post_type=comics&page=$page") } else { - val url = HttpUrl.parse("$baseUrl/$searchPath")!!.newBuilder() + val url = "$baseUrl/$searchPath".toHttpUrlOrNull()!!.newBuilder() filterList.forEach { filter -> when (filter) { diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/wpmangastream/WPMangaStream.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/wpmangastream/WPMangaStream.kt index a811fd2a4..b90da89c0 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/wpmangastream/WPMangaStream.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/wpmangastream/WPMangaStream.kt @@ -1,10 +1,8 @@ package eu.kanade.tachiyomi.multisrc.wpmangastream +//import eu.kanade.tachiyomi.lib.ratelimit.RateLimitInterceptor // added to override import android.app.Application import android.content.SharedPreferences -import android.support.v7.preference.ListPreference -import android.support.v7.preference.PreferenceScreen -//import eu.kanade.tachiyomi.lib.ratelimit.RateLimitInterceptor // added to override import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.source.ConfigurableSource import eu.kanade.tachiyomi.source.model.Filter @@ -15,7 +13,7 @@ import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.ParsedHttpSource import eu.kanade.tachiyomi.util.asJsoup import okhttp3.Headers -import okhttp3.HttpUrl +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.Response @@ -67,23 +65,6 @@ abstract class WPMangaStream( screen.addPreference(thumbsPref) } - override fun setupPreferenceScreen(screen: PreferenceScreen) { - val thumbsPref = ListPreference(screen.context).apply { - key = SHOW_THUMBNAIL_PREF_Title - title = SHOW_THUMBNAIL_PREF_Title - entries = arrayOf("Show high quality", "Show mid quality", "Show low quality") - entryValues = arrayOf("0", "1", "2") - summary = "%s" - - setOnPreferenceChangeListener { _, newValue -> - val selected = newValue as String - val index = this.findIndexOfValue(selected) - preferences.edit().putInt(SHOW_THUMBNAIL_PREF, index).commit() - } - } - screen.addPreference(thumbsPref) - } - private fun getShowThumbnail(): Int = preferences.getInt(SHOW_THUMBNAIL_PREF, 0) //private val rateLimitInterceptor = RateLimitInterceptor(4) @@ -106,7 +87,7 @@ abstract class WPMangaStream( } override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { - val url = HttpUrl.parse("$baseUrl/manga/")!!.newBuilder() + val url = "$baseUrl/manga/".toHttpUrlOrNull()!!.newBuilder() url.addQueryParameter("title", query) url.addQueryParameter("page", page.toString()) filters.forEach { filter -> diff --git a/src/all/batoto/src/eu/kanade/tachiyomi/extension/all/batoto/BatoTo.kt b/src/all/batoto/src/eu/kanade/tachiyomi/extension/all/batoto/BatoTo.kt index c2c274c5a..ffeecc5f7 100644 --- a/src/all/batoto/src/eu/kanade/tachiyomi/extension/all/batoto/BatoTo.kt +++ b/src/all/batoto/src/eu/kanade/tachiyomi/extension/all/batoto/BatoTo.kt @@ -8,7 +8,7 @@ import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.ParsedHttpSource -import okhttp3.HttpUrl +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.OkHttpClient import okhttp3.Request import org.json.JSONArray @@ -70,7 +70,7 @@ open class BatoTo( return if (query.isNotBlank()) { GET("$baseUrl/search?word=$query&page=$page") } else { - val url = HttpUrl.parse("$baseUrl/browse")!!.newBuilder() + val url = "$baseUrl/browse".toHttpUrlOrNull()!!.newBuilder() url.addQueryParameter("page", page.toString()) url.addQueryParameter("langs", siteLang) filters.forEach { filter -> @@ -311,7 +311,7 @@ open class BatoTo( "https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.0.0/crypto-js.min.js", headers ) - ).execute().body()!!.string() + ).execute().body!!.string() } override fun imageUrlParse(document: Document): String = throw UnsupportedOperationException("Not used") diff --git a/src/all/batoto/src/eu/kanade/tachiyomi/extension/all/batoto/BatoToFactory.kt b/src/all/batoto/src/eu/kanade/tachiyomi/extension/all/batoto/BatoToFactory.kt index cc833c3f5..02054ca63 100644 --- a/src/all/batoto/src/eu/kanade/tachiyomi/extension/all/batoto/BatoToFactory.kt +++ b/src/all/batoto/src/eu/kanade/tachiyomi/extension/all/batoto/BatoToFactory.kt @@ -10,8 +10,8 @@ class BatoToFactory : SourceFactory { } private val languages = listOf( - //commented langueges do currently not exist on Bato.to but haven in the past - Pair("all",""), + // commented langueges do currently not exist on Bato.to but haven in the past + Pair("all", ""), Pair("ar", "ar"), Pair("bg", "bg"), Pair("cs", "cs"), @@ -28,14 +28,14 @@ private val languages = listOf( Pair("fil", "fil"), Pair("fr", "fr"), Pair("he", "he"), - //Pair("hi", "hi"), + // Pair("hi", "hi"), Pair("hr", "hr"), Pair("hu", "hu"), Pair("id", "id"), Pair("it", "it"), Pair("ja", "ja"), Pair("ko", "ko"), - //Pair("ku", "ku"), + // Pair("ku", "ku"), Pair("ml", "ml"), Pair("mn", "mn"), Pair("ms", "ms"), @@ -52,7 +52,7 @@ private val languages = listOf( Pair("tr", "tr"), Pair("uk", "uk"), Pair("vi", "vi"), - //Pair("xh", "xh"), + // Pair("xh", "xh"), Pair("zh", "zh"), Pair("zh-rHK", "zh_hk"), Pair("zh-rTW", "zh_tw"), diff --git a/src/all/cubari/src/eu/kanade/tachiyomi/extension/all/cubari/Cubari.kt b/src/all/cubari/src/eu/kanade/tachiyomi/extension/all/cubari/Cubari.kt index b918bd30f..2be9ac56c 100644 --- a/src/all/cubari/src/eu/kanade/tachiyomi/extension/all/cubari/Cubari.kt +++ b/src/all/cubari/src/eu/kanade/tachiyomi/extension/all/cubari/Cubari.kt @@ -1,7 +1,7 @@ package eu.kanade.tachiyomi.extension.all.cubari import android.os.Build -import eu.kanade.tachiyomi.extension.BuildConfig +import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.asObservableSuccess import eu.kanade.tachiyomi.source.model.FilterList @@ -40,14 +40,14 @@ open class Cubari(override val lang: String) : HttpSource() { override fun fetchLatestUpdates(page: Int): Observable { return client.newBuilder() .addInterceptor(RemoteStorageUtils.HomeInterceptor()) - .build()!! + .build() .newCall(latestUpdatesRequest(page)) .asObservableSuccess() .map { response -> latestUpdatesParse(response) } } override fun latestUpdatesParse(response: Response): MangasPage { - return parseMangaList(JSONArray(response.body()!!.string()), SortType.UNPINNED) + return parseMangaList(JSONArray(response.body!!.string()), SortType.UNPINNED) } override fun popularMangaRequest(page: Int): Request { @@ -57,14 +57,14 @@ open class Cubari(override val lang: String) : HttpSource() { override fun fetchPopularManga(page: Int): Observable { return client.newBuilder() .addInterceptor(RemoteStorageUtils.HomeInterceptor()) - .build()!! + .build() .newCall(popularMangaRequest(page)) .asObservableSuccess() .map { response -> popularMangaParse(response) } } override fun popularMangaParse(response: Response): MangasPage { - return parseMangaList(JSONArray(response.body()!!.string()), SortType.PINNED) + return parseMangaList(JSONArray(response.body!!.string()), SortType.PINNED) } override fun fetchMangaDetails(manga: SManga): Observable { @@ -83,7 +83,7 @@ open class Cubari(override val lang: String) : HttpSource() { } private fun mangaDetailsParse(response: Response, manga: SManga): SManga { - return parseMangaFromApi(JSONObject(response.body()!!.string()), manga) + return parseMangaFromApi(JSONObject(response.body!!.string()), manga) } override fun fetchChapterList(manga: SManga): Observable> { @@ -107,7 +107,7 @@ open class Cubari(override val lang: String) : HttpSource() { // Called after the request private fun chapterListParse(response: Response, manga: SManga): List { - val res = response.body()!!.string() + val res = response.body!!.string() return parseChapterList(res, manga) } @@ -146,7 +146,7 @@ open class Cubari(override val lang: String) : HttpSource() { } private fun directPageListParse(response: Response): List { - val res = response.body()!!.string() + val res = response.body!!.string() val pages = JSONArray(res) val pageArray = ArrayList() @@ -162,7 +162,7 @@ open class Cubari(override val lang: String) : HttpSource() { } private fun seriesJsonPageListParse(response: Response, chapter: SChapter): List { - val res = response.body()!!.string() + val res = response.body!!.string() val json = JSONObject(res) val groups = json.getJSONObject("groups") val groupIter = groups.keys() @@ -210,7 +210,7 @@ open class Cubari(override val lang: String) : HttpSource() { // Only tag for recently read on search client.newBuilder() .addInterceptor(RemoteStorageUtils.TagInterceptor()) - .build()!! + .build() .newCall(searchMangaRequest(page, trimmedQuery, filters)) .asObservableSuccess() .map { response -> @@ -238,7 +238,7 @@ open class Cubari(override val lang: String) : HttpSource() { } private fun searchMangaParse(response: Response, query: String): MangasPage { - return parseSearchList(JSONObject(response.body()!!.string()), query) + return parseSearchList(JSONObject(response.body!!.string()), query) } // ------------- Helpers and whatnot --------------- diff --git a/src/all/cubari/src/eu/kanade/tachiyomi/extension/all/cubari/RemoteStorageUtils.kt b/src/all/cubari/src/eu/kanade/tachiyomi/extension/all/cubari/RemoteStorageUtils.kt index 3e4fbd060..0184dac56 100644 --- a/src/all/cubari/src/eu/kanade/tachiyomi/extension/all/cubari/RemoteStorageUtils.kt +++ b/src/all/cubari/src/eu/kanade/tachiyomi/extension/all/cubari/RemoteStorageUtils.kt @@ -50,8 +50,8 @@ class RemoteStorageUtils { var webView: WebView? = null - val origRequestUrl = request.url().toString() - val headers = request.headers().toMultimap().mapValues { + val origRequestUrl = request.url.toString() + val headers = request.headers.toMultimap().mapValues { it.value.getOrNull(0) ?: "" }.toMutableMap() val jsInterface = JsInterface(latch) @@ -94,7 +94,7 @@ class RemoteStorageUtils { return if (transparent) { response } else { - response.newBuilder().body(ResponseBody.create(response.body()?.contentType(), jsInterface.payload)).build() + response.newBuilder().body(ResponseBody.create(response.body?.contentType(), jsInterface.payload)).build() } } } diff --git a/src/all/ehentai/src/eu/kanade/tachiyomi/extension/all/ehentai/EHentai.kt b/src/all/ehentai/src/eu/kanade/tachiyomi/extension/all/ehentai/EHentai.kt index 4ad56d9de..e0714a271 100644 --- a/src/all/ehentai/src/eu/kanade/tachiyomi/extension/all/ehentai/EHentai.kt +++ b/src/all/ehentai/src/eu/kanade/tachiyomi/extension/all/ehentai/EHentai.kt @@ -32,8 +32,6 @@ import rx.Observable import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import java.net.URLEncoder -import android.support.v7.preference.CheckBoxPreference as LegacyCheckBoxPreference -import android.support.v7.preference.PreferenceScreen as LegacyPreferenceScreen open class EHentai(override val lang: String, private val ehLang: String) : ConfigurableSource, HttpSource() { @@ -196,7 +194,7 @@ open class EHentai(override val lang: String, private val ehLang: String) : Conf @SuppressLint("DefaultLocale") override fun mangaDetailsParse(response: Response) = with(response.asJsoup()) { with(ExGalleryMetadata()) { - url = response.request().url().encodedPath() + url = response.request.url.encodedPath title = select("#gn").text().nullIfBlank()?.trim() altTitle = select("#gj").text().nullIfBlank()?.trim() @@ -514,20 +512,5 @@ open class EHentai(override val lang: String, private val ehLang: String) : Conf screen.addPreference(enforceLanguagePref) } - override fun setupPreferenceScreen(screen: LegacyPreferenceScreen) { - val enforceLanguagePref = LegacyCheckBoxPreference(screen.context).apply { - key = "${ENFORCE_LANGUAGE_PREF_KEY}_$lang" - title = ENFORCE_LANGUAGE_PREF_TITLE - summary = ENFORCE_LANGUAGE_PREF_SUMMARY - setDefaultValue(ENFORCE_LANGUAGE_PREF_DEFAULT_VALUE) - - setOnPreferenceChangeListener { _, newValue -> - val checkValue = newValue as Boolean - preferences.edit().putBoolean("${ENFORCE_LANGUAGE_PREF_KEY}_$lang", checkValue).commit() - } - } - screen.addPreference(enforceLanguagePref) - } - private fun getEnforceLanguagePref(): Boolean = preferences.getBoolean("${ENFORCE_LANGUAGE_PREF_KEY}_$lang", ENFORCE_LANGUAGE_PREF_DEFAULT_VALUE) } diff --git a/src/all/hentaihand/src/eu/kanade/tachiyomi/extension/all/hentaihand/HentaiHand.kt b/src/all/hentaihand/src/eu/kanade/tachiyomi/extension/all/hentaihand/HentaiHand.kt index 9bd165f46..fd993f62c 100644 --- a/src/all/hentaihand/src/eu/kanade/tachiyomi/extension/all/hentaihand/HentaiHand.kt +++ b/src/all/hentaihand/src/eu/kanade/tachiyomi/extension/all/hentaihand/HentaiHand.kt @@ -3,8 +3,6 @@ package eu.kanade.tachiyomi.extension.all.hentaihand import android.annotation.SuppressLint import android.app.Application import android.content.SharedPreferences -import android.support.v7.preference.EditTextPreference -import android.support.v7.preference.PreferenceScreen import android.text.InputType import android.widget.Toast import com.github.salomonbrys.kotson.fromJson @@ -26,9 +24,9 @@ import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.HttpSource -import okhttp3.HttpUrl +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.Interceptor -import okhttp3.MediaType +import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.RequestBody @@ -59,7 +57,7 @@ class HentaiHand( .build() private fun parseGenericResponse(response: Response): MangasPage { - val data = gson.fromJson(response.body()!!.string()) + val data = gson.fromJson(response.body!!.string()) return MangasPage( data.getAsJsonArray("data").map { SManga.create().apply { @@ -100,7 +98,7 @@ class HentaiHand( .asObservableSuccess() .subscribeOn(Schedulers.io()) .map { - val data = gson.fromJson(it.body()!!.string()) + val data = gson.fromJson(it.body!!.string()) // only the first tag will be used data.getAsJsonArray("data").firstOrNull()?.let { t -> t["id"].asInt } }.toBlocking().first() @@ -108,7 +106,7 @@ class HentaiHand( override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { - val url = HttpUrl.parse("$baseUrl/api/comics")!!.newBuilder() + val url = "$baseUrl/api/comics".toHttpUrlOrNull()!!.newBuilder() .addQueryParameter("page", page.toString()) .addQueryParameter("q", query) @@ -158,7 +156,7 @@ class HentaiHand( } override fun mangaDetailsParse(response: Response): SManga { - val data = gson.fromJson(response.body()!!.string()) + val data = gson.fromJson(response.body!!.string()) return SManga.create().apply { artist = tagArrayToString(data.getAsJsonArray("artists")) @@ -188,7 +186,7 @@ class HentaiHand( override fun chapterListRequest(manga: SManga): Request = mangaDetailsApiRequest(manga) override fun chapterListParse(response: Response): List { - val data = gson.fromJson(response.body()!!.string()) + val data = gson.fromJson(response.body!!.string()) return listOf( SChapter.create().apply { url = "/en/comic/${data["slug"].asString}/reader/1" @@ -207,7 +205,7 @@ class HentaiHand( } override fun pageListParse(response: Response): List { - val data = gson.fromJson(response.body()!!.string()) + val data = gson.fromJson(response.body!!.string()) return data.getAsJsonArray("images").mapIndexed { i, it -> Page(i, "/en/comic/${data["comic"]["slug"].asString}/reader/${it["page"].asInt}", it["source_url"].asString) } @@ -240,14 +238,14 @@ class HentaiHand( } val body = RequestBody.create(MEDIA_TYPE, jsonObject.toString()) val response = chain.proceed(POST("$baseUrl/api/login", headers, body)) - if (response.code() == 401) { + if (response.code == 401) { throw Exception("Failed to login, check if username and password are correct") } - if (response.body() == null) + if (response.body == null) throw Exception("Login response body is empty") try { - return JSONObject(response.body()!!.string()) + return JSONObject(response.body!!.string()) .getJSONObject("auth") .getString("access_token") } catch (e: JSONException) { @@ -296,32 +294,6 @@ class HentaiHand( } } - override fun setupPreferenceScreen(screen: PreferenceScreen) { - screen.addPreference(screen.supportEditTextPreference(USERNAME_TITLE, USERNAME_DEFAULT, username)) - screen.addPreference(screen.supportEditTextPreference(PASSWORD_TITLE, PASSWORD_DEFAULT, password)) - } - - private fun PreferenceScreen.supportEditTextPreference(title: String, default: String, value: String): EditTextPreference { - return EditTextPreference(context).apply { - key = title - this.title = title - summary = value - this.setDefaultValue(default) - dialogTitle = title - - setOnPreferenceChangeListener { _, newValue -> - try { - val res = preferences.edit().putString(title, newValue as String).commit() - Toast.makeText(context, "Restart Tachiyomi to apply new setting.", Toast.LENGTH_LONG).show() - res - } catch (e: Exception) { - e.printStackTrace() - false - } - } - } - } - private fun getPrefUsername(): String = preferences.getString(USERNAME_TITLE, USERNAME_DEFAULT)!! private fun getPrefPassword(): String = preferences.getString(PASSWORD_TITLE, PASSWORD_DEFAULT)!! @@ -387,7 +359,7 @@ class HentaiHand( companion object { @SuppressLint("SimpleDateFormat") private val DATE_FORMAT = SimpleDateFormat("yyyy-dd-MM") - private val MEDIA_TYPE = MediaType.parse("application/json; charset=utf-8") + 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" diff --git a/src/all/hitomi/src/eu/kanade/tachiyomi/extension/all/hitomi/Hitomi.kt b/src/all/hitomi/src/eu/kanade/tachiyomi/extension/all/hitomi/Hitomi.kt index e579ebf2c..c4c2b926e 100644 --- a/src/all/hitomi/src/eu/kanade/tachiyomi/extension/all/hitomi/Hitomi.kt +++ b/src/all/hitomi/src/eu/kanade/tachiyomi/extension/all/hitomi/Hitomi.kt @@ -2,8 +2,6 @@ package eu.kanade.tachiyomi.extension.all.hitomi import android.app.Application import android.content.SharedPreferences -import android.support.v7.preference.CheckBoxPreference -import android.support.v7.preference.PreferenceScreen import com.github.salomonbrys.kotson.array import com.github.salomonbrys.kotson.get import com.github.salomonbrys.kotson.string @@ -61,7 +59,7 @@ open class Hitomi(override val lang: String, private val nozomiLang: String) : H val range = response.header("Content-Range")!! val total = range.substringAfter('/').toLong() val end = range.substringBefore('/').substringAfter('-').toLong() - val body = response.body()!! + val body = response.body!! return parseNozomiPage(body.bytes()) .map { MangasPage(it, end < total - 1) @@ -276,7 +274,7 @@ open class Hitomi(override val lang: String, private val nozomiLang: String) : H private val jsonParser = JsonParser() override fun pageListParse(response: Response): List { - val str = response.body()!!.string() + val str = response.body!!.string() val json = jsonParser.parse(str.removePrefix("var galleryinfo = ")) return json["files"].array.mapIndexed { i, jsonElement -> val hash = jsonElement["hash"].string @@ -305,7 +303,7 @@ open class Hitomi(override val lang: String, private val nozomiLang: String) : H override fun imageRequest(page: Page): Request { val request = super.imageRequest(page) - val hlId = request.url().pathSegments().let { + val hlId = request.url.pathSegments.let { it[it.lastIndex - 1] } return request.newBuilder() @@ -343,35 +341,6 @@ open class Hitomi(override val lang: String, private val nozomiLang: String) : H Injekt.get().getSharedPreferences("source_$id", 0x0000) } - override fun setupPreferenceScreen(screen: PreferenceScreen) { - val webpPref = CheckBoxPreference(screen.context).apply { - key = "${WEBP_PREF_KEY}_$lang" - title = WEBP_PREF_TITLE - summary = WEBP_PREF_SUMMARY - setDefaultValue(WEBP_PREF_DEFAULT_VALUE) - - setOnPreferenceChangeListener { _, newValue -> - val checkValue = newValue as Boolean - preferences.edit().putBoolean("${WEBP_PREF_KEY}_$lang", checkValue).commit() - } - } - - val coverPref = CheckBoxPreference(screen.context).apply { - key = "${COVER_PREF_KEY}_$lang" - title = COVER_PREF_TITLE - summary = COVER_PREF_SUMMARY - setDefaultValue(COVER_PREF_DEFAULT_VALUE) - - setOnPreferenceChangeListener { _, newValue -> - val checkValue = newValue as Boolean - preferences.edit().putBoolean("${COVER_PREF_KEY}_$lang", checkValue).commit() - } - } - - screen.addPreference(webpPref) - screen.addPreference(coverPref) - } - override fun setupPreferenceScreen(screen: AndroidXPreferenceScreen) { val webpPref = AndroidXCheckBoxPreference(screen.context).apply { key = "${WEBP_PREF_KEY}_$lang" diff --git a/src/all/hitomi/src/eu/kanade/tachiyomi/extension/all/hitomi/HitomiNozomi.kt b/src/all/hitomi/src/eu/kanade/tachiyomi/extension/all/hitomi/HitomiNozomi.kt index 43a397e40..9443080bc 100644 --- a/src/all/hitomi/src/eu/kanade/tachiyomi/extension/all/hitomi/HitomiNozomi.kt +++ b/src/all/hitomi/src/eu/kanade/tachiyomi/extension/all/hitomi/HitomiNozomi.kt @@ -83,7 +83,7 @@ class HitomiNozomi( return client.newCall(rangedGet(url, offset, offset + length - 1)) .asObservable() .map { - it.body()?.bytes() ?: ByteArray(0) + it.body?.bytes() ?: ByteArray(0) } .onErrorReturn { ByteArray(0) } .map { inbuf -> @@ -192,7 +192,7 @@ class HitomiNozomi( return client.newCall(rangedGet(url, address, address + MAX_NODE_SIZE - 1)) .asObservableSuccess() .map { - it.body()?.bytes() ?: ByteArray(0) + it.body?.bytes() ?: ByteArray(0) } .onErrorReturn { ByteArray(0) } .map { nodedata -> @@ -215,7 +215,7 @@ class HitomiNozomi( ) .asObservableSuccess() .map { resp -> - val body = resp.body()!!.bytes() + val body = resp.body!!.bytes() val cursor = ByteCursor(body) (1..body.size / 4).map { cursor.nextInt() @@ -251,7 +251,7 @@ class HitomiNozomi( fun getIndexVersion(httpClient: OkHttpClient, name: String): Observable { return httpClient.newCall(GET("$LTN_BASE_URL/$name/version?_=${System.currentTimeMillis()}")) .asObservableSuccess() - .map { it.body()!!.string().toLong() } + .map { it.body!!.string().toLong() } } } } diff --git a/src/all/imhentai/src/eu/kanade/tachiyomi/extension/all/imhentai/IMHentai.kt b/src/all/imhentai/src/eu/kanade/tachiyomi/extension/all/imhentai/IMHentai.kt index 695d9a286..75ec365e2 100644 --- a/src/all/imhentai/src/eu/kanade/tachiyomi/extension/all/imhentai/IMHentai.kt +++ b/src/all/imhentai/src/eu/kanade/tachiyomi/extension/all/imhentai/IMHentai.kt @@ -11,11 +11,11 @@ import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.ParsedHttpSource import eu.kanade.tachiyomi.util.asJsoup import okhttp3.Headers -import okhttp3.HttpUrl -import okhttp3.MediaType +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull +import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.OkHttpClient import okhttp3.Request -import okhttp3.RequestBody +import okhttp3.RequestBody.Companion.toRequestBody import okhttp3.Response import org.jsoup.nodes.Document import org.jsoup.nodes.Element @@ -72,7 +72,7 @@ class IMHentai(override val lang: String, private val imhLang: String) : ParsedH private fun toBinary(boolean: Boolean) = if (boolean) "1" else "0" override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { - val url = HttpUrl.parse("$baseUrl/search")!!.newBuilder() + val url = "$baseUrl/search".toHttpUrlOrNull()!!.newBuilder() .addQueryParameter("key", query) .addQueryParameter("page", page.toString()) .addQueryParameter(getLanguageURIByName(imhLang).uri, toBinary(true)) // main language always enabled @@ -168,7 +168,7 @@ class IMHentai(override val lang: String, private val imhLang: String) : ParsedH override fun chapterListParse(response: Response): List { return listOf( SChapter.create().apply { - setUrlWithoutDomain(response.request().url().toString()) + setUrlWithoutDomain(response.request.url.toString()) name = "Chapter" chapter_number = 1f } @@ -185,7 +185,7 @@ class IMHentai(override val lang: String, private val imhLang: String) : ParsedH return client.newCall(GET("$baseUrl${chapter.url}")) .asObservableSuccess() .map { pageLoadMetaParse(it.asJsoup()) } - .map { RequestBody.create(MediaType.parse("application/x-www-form-urlencoded; charset=UTF-8"), it) } + .map { it.toRequestBody("application/x-www-form-urlencoded; charset=UTF-8".toMediaTypeOrNull()) } .concatMap { client.newCall(POST(PAEG_LOAD_URL, pageLoadHeaders, it)).asObservableSuccess() } .map { pageListParse(it) } } diff --git a/src/all/komga/src/eu/kanade/tachiyomi/extension/all/komga/Komga.kt b/src/all/komga/src/eu/kanade/tachiyomi/extension/all/komga/Komga.kt index 5ce8d73c7..d5aa41e72 100644 --- a/src/all/komga/src/eu/kanade/tachiyomi/extension/all/komga/Komga.kt +++ b/src/all/komga/src/eu/kanade/tachiyomi/extension/all/komga/Komga.kt @@ -2,14 +2,12 @@ package eu.kanade.tachiyomi.extension.all.komga import android.app.Application import android.content.SharedPreferences -import android.support.v7.preference.EditTextPreference -import android.support.v7.preference.PreferenceScreen import android.text.InputType import android.util.Log import android.widget.Toast import com.github.salomonbrys.kotson.fromJson import com.google.gson.Gson -import eu.kanade.tachiyomi.extension.BuildConfig +import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.extension.all.komga.dto.AuthorDto import eu.kanade.tachiyomi.extension.all.komga.dto.BookDto import eu.kanade.tachiyomi.extension.all.komga.dto.CollectionDto @@ -30,7 +28,7 @@ import eu.kanade.tachiyomi.source.online.HttpSource import okhttp3.Credentials import okhttp3.Dns import okhttp3.Headers -import okhttp3.HttpUrl +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.Response @@ -67,7 +65,7 @@ open class Komga(suffix: String = "") : ConfigurableSource, HttpSource() { else -> "series" } - val url = HttpUrl.parse("$baseUrl/api/v1/$type?search=$query&page=${page - 1}")!!.newBuilder() + val url = "$baseUrl/api/v1/$type?search=$query&page=${page - 1}".toHttpUrlOrNull()!!.newBuilder() filters.forEach { filter -> when (filter) { @@ -168,10 +166,10 @@ open class Komga(suffix: String = "") : ConfigurableSource, HttpSource() { override fun mangaDetailsParse(response: Response): SManga = if (response.fromReadList()) { - val readList = gson.fromJson(response.body()?.charStream()!!) + val readList = gson.fromJson(response.body?.charStream()!!) readList.toSManga() } else { - val series = gson.fromJson(response.body()?.charStream()!!) + val series = gson.fromJson(response.body?.charStream()!!) series.toSManga() } @@ -179,7 +177,7 @@ open class Komga(suffix: String = "") : ConfigurableSource, HttpSource() { GET("${manga.url}/books?unpaged=true&media_status=READY", headers) override fun chapterListParse(response: Response): List { - val page = gson.fromJson>(response.body()?.charStream()!!).content + val page = gson.fromJson>(response.body?.charStream()!!).content val r = page.map { book -> SChapter.create().apply { @@ -197,9 +195,9 @@ open class Komga(suffix: String = "") : ConfigurableSource, HttpSource() { GET("${chapter.url}/pages") override fun pageListParse(response: Response): List { - val pages = gson.fromJson>(response.body()?.charStream()!!) + val pages = gson.fromJson>(response.body?.charStream()!!) return pages.map { - val url = "${response.request().url()}/${it.number}" + + val url = "${response.request.url}/${it.number}" + if (!supportedImageTypes.contains(it.mediaType)) { "?convert=png" } else { @@ -214,11 +212,11 @@ open class Komga(suffix: String = "") : ConfigurableSource, HttpSource() { private fun processSeriesPage(response: Response): MangasPage { if (response.fromReadList()) { - with(gson.fromJson>(response.body()?.charStream()!!)) { + with(gson.fromJson>(response.body?.charStream()!!)) { return MangasPage(content.map { it.toSManga() }, !last) } } else { - with(gson.fromJson>(response.body()?.charStream()!!)) { + with(gson.fromJson>(response.body?.charStream()!!)) { return MangasPage(content.map { it.toSManga() }, !last) } } @@ -250,7 +248,7 @@ open class Komga(suffix: String = "") : ConfigurableSource, HttpSource() { status = SManga.UNKNOWN } - private fun Response.fromReadList() = request().url().toString().contains("/api/v1/readlists") + private fun Response.fromReadList() = request.url.toString().contains("/api/v1/readlists") private fun parseDate(date: String?): Long = if (date == null) @@ -355,10 +353,10 @@ open class Komga(suffix: String = "") : ConfigurableSource, HttpSource() { override val client: OkHttpClient = network.client.newBuilder() .authenticator { _, response -> - if (response.request().header("Authorization") != null) { + if (response.request.header("Authorization") != null) { null // Give up, we've already failed to authenticate. } else { - response.request().newBuilder() + response.request.newBuilder() .addHeader("Authorization", Credentials.basic(username, password)) .build() } @@ -399,33 +397,6 @@ open class Komga(suffix: String = "") : ConfigurableSource, HttpSource() { } } - override fun setupPreferenceScreen(screen: PreferenceScreen) { - screen.addPreference(screen.supportEditTextPreference(ADDRESS_TITLE, ADDRESS_DEFAULT, baseUrl)) - screen.addPreference(screen.supportEditTextPreference(USERNAME_TITLE, USERNAME_DEFAULT, username)) - screen.addPreference(screen.supportEditTextPreference(PASSWORD_TITLE, PASSWORD_DEFAULT, password)) - } - - private fun PreferenceScreen.supportEditTextPreference(title: String, default: String, value: String): EditTextPreference { - return EditTextPreference(context).apply { - key = title - this.title = title - summary = value - this.setDefaultValue(default) - dialogTitle = title - - setOnPreferenceChangeListener { _, newValue -> - try { - val res = preferences.edit().putString(title, newValue as String).commit() - Toast.makeText(context, "Restart Tachiyomi to apply new setting.", Toast.LENGTH_LONG).show() - res - } catch (e: Exception) { - e.printStackTrace() - false - } - } - } - } - private fun getPrefBaseUrl(): String = preferences.getString(ADDRESS_TITLE, ADDRESS_DEFAULT)!! private fun getPrefUsername(): String = preferences.getString(USERNAME_TITLE, USERNAME_DEFAULT)!! private fun getPrefPassword(): String = preferences.getString(PASSWORD_TITLE, PASSWORD_DEFAULT)!! @@ -440,7 +411,7 @@ open class Komga(suffix: String = "") : ConfigurableSource, HttpSource() { .subscribe( { response -> libraries = try { - gson.fromJson(response.body()?.charStream()!!) + gson.fromJson(response.body?.charStream()!!) } catch (e: Exception) { emptyList() } @@ -458,7 +429,7 @@ open class Komga(suffix: String = "") : ConfigurableSource, HttpSource() { .subscribe( { response -> collections = try { - gson.fromJson>(response.body()?.charStream()!!).content + gson.fromJson>(response.body?.charStream()!!).content } catch (e: Exception) { emptyList() } @@ -476,7 +447,7 @@ open class Komga(suffix: String = "") : ConfigurableSource, HttpSource() { .subscribe( { response -> genres = try { - gson.fromJson(response.body()?.charStream()!!) + gson.fromJson(response.body?.charStream()!!) } catch (e: Exception) { emptySet() } @@ -494,7 +465,7 @@ open class Komga(suffix: String = "") : ConfigurableSource, HttpSource() { .subscribe( { response -> tags = try { - gson.fromJson(response.body()?.charStream()!!) + gson.fromJson(response.body?.charStream()!!) } catch (e: Exception) { emptySet() } @@ -512,7 +483,7 @@ open class Komga(suffix: String = "") : ConfigurableSource, HttpSource() { .subscribe( { response -> publishers = try { - gson.fromJson(response.body()?.charStream()!!) + gson.fromJson(response.body?.charStream()!!) } catch (e: Exception) { emptySet() } @@ -530,7 +501,7 @@ open class Komga(suffix: String = "") : ConfigurableSource, HttpSource() { .subscribe( { response -> authors = try { - val list: List = gson.fromJson(response.body()?.charStream()!!) + val list: List = gson.fromJson(response.body?.charStream()!!) list.groupBy { it.role } } catch (e: Exception) { emptyMap() diff --git a/src/all/lanraragi/build.gradle b/src/all/lanraragi/build.gradle index 9201f365c..ba19fa839 100644 --- a/src/all/lanraragi/build.gradle +++ b/src/all/lanraragi/build.gradle @@ -11,7 +11,7 @@ ext { dependencies { implementation 'io.reactivex:rxandroid:1.2.1' - implementation 'io.reactivex:rxjava:1.3.6' + implementation 'io.reactivex:rxjava:1.3.8' } apply from: "$rootDir/common.gradle" diff --git a/src/all/lanraragi/src/eu/kanade/tachiyomi/extension/all/lanraragi/LANraragi.kt b/src/all/lanraragi/src/eu/kanade/tachiyomi/extension/all/lanraragi/LANraragi.kt index ab824428b..df22742b3 100644 --- a/src/all/lanraragi/src/eu/kanade/tachiyomi/extension/all/lanraragi/LANraragi.kt +++ b/src/all/lanraragi/src/eu/kanade/tachiyomi/extension/all/lanraragi/LANraragi.kt @@ -3,9 +3,6 @@ package eu.kanade.tachiyomi.extension.all.lanraragi import android.app.Application import android.content.SharedPreferences import android.net.Uri -import android.support.v7.preference.CheckBoxPreference -import android.support.v7.preference.EditTextPreference -import android.support.v7.preference.PreferenceScreen import android.util.Base64 import com.github.salomonbrys.kotson.fromJson import com.google.gson.Gson @@ -65,7 +62,7 @@ open class LANraragi : ConfigurableSource, HttpSource() { return client.newCall(GET(uri.toString(), headers)) .asObservable().doOnNext { - if (!it.isSuccessful && it.code() == 404) error("Log in with WebView then try again.") + if (!it.isSuccessful && it.code == 404) error("Log in with WebView then try again.") } .map { mangaDetailsParse(it).apply { initialized = true } } } @@ -78,7 +75,7 @@ open class LANraragi : ConfigurableSource, HttpSource() { } override fun mangaDetailsParse(response: Response): SManga { - val archive = gson.fromJson(response.body()!!.string()) + val archive = gson.fromJson(response.body!!.string()) return archiveToSManga(archive) } @@ -91,7 +88,7 @@ open class LANraragi : ConfigurableSource, HttpSource() { } override fun chapterListParse(response: Response): List { - val archive = gson.fromJson(response.body()!!.string()) + val archive = gson.fromJson(response.body!!.string()) val uri = getApiUriBuilder("/api/archives/${archive.arcid}/extract") // Replicate old behavior and unset "isnew" for the archive. @@ -124,7 +121,7 @@ open class LANraragi : ConfigurableSource, HttpSource() { } override fun pageListParse(response: Response): List { - val archivePage = gson.fromJson(response.body()!!.string()) + val archivePage = gson.fromJson(response.body!!.string()) return archivePage.pages.mapIndexed { index, url -> val uri = Uri.parse("${baseUrl}${url.trimStart('.')}") @@ -197,7 +194,7 @@ open class LANraragi : ConfigurableSource, HttpSource() { } override fun searchMangaParse(response: Response): MangasPage { - val jsonResult = gson.fromJson(response.body()!!.string()) + val jsonResult = gson.fromJson(response.body!!.string()) val currentStart = getStart(response) val archives = arrayListOf() @@ -231,7 +228,7 @@ open class LANraragi : ConfigurableSource, HttpSource() { return ( totalRecords > 0 && getStart(response) == 0 && - response.request().url().querySize() == 1 // ?start= + response.request.url.querySize == 1 // ?start= ) } @@ -276,84 +273,6 @@ open class LANraragi : ConfigurableSource, HttpSource() { Injekt.get().getSharedPreferences("source_$id", 0x0000) } - override fun setupPreferenceScreen(screen: PreferenceScreen) { - val hostnamePref = EditTextPreference(screen.context).apply { - key = "Hostname" - title = "Hostname" - text = baseUrl - summary = baseUrl - dialogTitle = "Hostname" - - setOnPreferenceChangeListener { _, newValue -> - var hostname = newValue as String - if (!hostname.startsWith("http://") && !hostname.startsWith("https://")) { - hostname = "http://$hostname" - } - - this.apply { - text = hostname - summary = hostname - } - - preferences.edit().putString("hostname", hostname).commit() - } - } - - val apiKeyPref = EditTextPreference(screen.context).apply { - key = "API Key" - title = "API Key" - text = apiKey - summary = "Required if No-Fun Mode is enabled." - dialogTitle = "API Key" - - setOnPreferenceChangeListener { _, newValue -> - val apiKey = newValue as String - - this.apply { - text = apiKey - summary = "Required if No-Fun Mode is enabled." - } - - preferences.edit().putString("apiKey", newValue).commit() - } - } - - val latestNewOnlyPref = CheckBoxPreference(screen.context).apply { - key = "latestNewOnly" - title = "Latest - New Only" - setDefaultValue(true) - - setOnPreferenceChangeListener { _, newValue -> - val checkValue = newValue as Boolean - preferences.edit().putBoolean("latestNewOnly", checkValue).commit() - } - } - - val latestNamespacePref = EditTextPreference(screen.context).apply { - key = "latestNamespacePref" - title = "Latest - Sort by Namespace" - text = latestNamespacePref - summary = "Sort by the given namespace for Latest, such as date_added." - dialogTitle = "Latest - Sort by Namespace" - setDefaultValue(DEFAULT_SORT_BY_NS) - - setOnPreferenceChangeListener { _, newValue -> - val latestNamespacePref = newValue as String - - this.apply { - text = latestNamespacePref - } - - preferences.edit().putString("latestNamespacePref", newValue).commit() - } - } - - screen.addPreference(hostnamePref) - screen.addPreference(apiKeyPref) - screen.addPreference(latestNewOnlyPref) - screen.addPreference(latestNamespacePref) - } - override fun setupPreferenceScreen(screen: androidx.preference.PreferenceScreen) { val hostnamePref = androidx.preference.EditTextPreference(screen.context).apply { key = "Hostname" @@ -457,7 +376,7 @@ open class LANraragi : ConfigurableSource, HttpSource() { .subscribe( { categories = try { - gson.fromJson(it.body()?.charStream()!!) + gson.fromJson(it.body?.charStream()!!) } catch (e: Exception) { emptyList() } @@ -505,15 +424,15 @@ open class LANraragi : ConfigurableSource, HttpSource() { } private fun getTopResponse(response: Response): Response { - return if (response.priorResponse() == null) response else getTopResponse(response.priorResponse()!!) + return if (response.priorResponse == null) response else getTopResponse(response.priorResponse!!) } private fun getId(response: Response): String { - return getTopResponse(response).request().url().queryParameter("id").toString() + return getTopResponse(response).request.url.queryParameter("id").toString() } private fun getStart(response: Response): Int { - return getTopResponse(response).request().url().queryParameter("start")!!.toInt() + return getTopResponse(response).request.url.queryParameter("start")!!.toInt() } private fun getReaderId(url: String): String { diff --git a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDex.kt b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDex.kt index 50ede068b..23cd5c2ad 100644 --- a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDex.kt +++ b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDex.kt @@ -2,8 +2,6 @@ package eu.kanade.tachiyomi.extension.all.mangadex import android.app.Application import android.content.SharedPreferences -import android.support.v7.preference.ListPreference -import android.support.v7.preference.PreferenceScreen import android.util.Log import com.github.salomonbrys.kotson.array import com.github.salomonbrys.kotson.bool @@ -33,7 +31,7 @@ import eu.kanade.tachiyomi.source.online.ParsedHttpSource import eu.kanade.tachiyomi.util.asJsoup import okhttp3.CacheControl import okhttp3.Headers -import okhttp3.HttpUrl +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.Interceptor import okhttp3.OkHttpClient import okhttp3.Request @@ -230,7 +228,7 @@ abstract class MangaDex( val genresToExclude = mutableListOf() // Do traditional search - val url = HttpUrl.parse("$baseUrl/?page=search")!!.newBuilder() + val url = "$baseUrl/?page=search".toHttpUrlOrNull()!!.newBuilder() .addQueryParameter("p", page.toString()) .addQueryParameter("title", query.replace(WHITESPACE_REGEX, " ")) @@ -346,7 +344,7 @@ abstract class MangaDex( } override fun searchMangaParse(response: Response): MangasPage { - return if (response.request().url().toString().contains("/groups/")) { + return if (response.request.url.toString().contains("/groups/")) { response.asJsoup() .select(".table > tbody:nth-child(2) > tr:nth-child(1) > td:nth-child(2) > a") .firstOrNull()?.attr("abs:href") @@ -428,7 +426,7 @@ abstract class MangaDex( override fun mangaDetailsParse(response: Response): SManga { val manga = SManga.create() - val jsonData = response.body()!!.string() + val jsonData = response.body!!.string() val json = JsonParser().parse(jsonData).asJsonObject["data"] val mangaJson = json["manga"].asJsonObject val chapterJson = json["chapters"].asJsonArray @@ -519,7 +517,7 @@ abstract class MangaDex( override fun chapterListParse(response: Response): List { val now = Date().time - val jsonData = response.body()!!.string() + val jsonData = response.body!!.string() val json = JsonParser().parse(jsonData).asJsonObject["data"] val mangaJson = json["manga"].asJsonObject @@ -615,10 +613,10 @@ abstract class MangaDex( .asObservable().doOnNext { response -> if (!response.isSuccessful) { response.close() - if (response.code() == 451) { + if (response.code == 451) { error("Error 451: Log in to view manga; contact MangaDex if error persists.") } else { - throw Exception("HTTP error ${response.code()}") + throw Exception("HTTP error ${response.code}") } } } @@ -645,7 +643,7 @@ abstract class MangaDex( override fun pageListParse(document: Document) = throw Exception("Not used") override fun pageListParse(response: Response): List { - val jsonData = response.body()!!.string() + val jsonData = response.body!!.string() val json = JsonParser().parse(jsonData).asJsonObject["data"] val hash = json["hash"].string @@ -653,7 +651,7 @@ abstract class MangaDex( return json["pages"].asJsonArray.mapIndexed { idx, it -> val url = "$hash/${it.asString}" - val mdAtHomeMetadataUrl = "$server,${response.request().url()},${Date().time}" + val mdAtHomeMetadataUrl = "$server,${response.request.url},${Date().time}" Page(idx, mdAtHomeMetadataUrl, url) } } @@ -682,7 +680,7 @@ abstract class MangaDex( } val jsonData = client.newCall(GET(tokenRequestUrl, headers, cacheControl)).execute() - .body()!!.string() + .body!!.string() tokenedServer = JsonParser().parse(jsonData).asJsonObject["data"]["server"].string } @@ -766,69 +764,6 @@ abstract class MangaDex( screen.addPreference(dataSaverPref) } - override fun setupPreferenceScreen(screen: PreferenceScreen) { - val r18Pref = ListPreference(screen.context).apply { - key = SHOW_R18_PREF_Title - title = SHOW_R18_PREF_Title - - title = SHOW_R18_PREF_Title - entries = arrayOf("Show No R18+", "Show All", "Show Only R18+") - entryValues = arrayOf("0", "1", "2") - summary = "%s" - - setOnPreferenceChangeListener { _, newValue -> - val selected = newValue as String - val index = this.findIndexOfValue(selected) - preferences.edit().putInt(SHOW_R18_PREF, index).commit() - } - } - val thumbsPref = ListPreference(screen.context).apply { - key = SHOW_THUMBNAIL_PREF_Title - title = SHOW_THUMBNAIL_PREF_Title - entries = arrayOf("Show high quality", "Show low quality") - entryValues = arrayOf("0", "1") - summary = "%s" - - setOnPreferenceChangeListener { _, newValue -> - val selected = newValue as String - val index = this.findIndexOfValue(selected) - preferences.edit().putInt(SHOW_THUMBNAIL_PREF, index).commit() - } - } - val serverPref = ListPreference(screen.context).apply { - key = SERVER_PREF_Title - title = SERVER_PREF_Title - entries = SERVER_PREF_ENTRIES - entryValues = SERVER_PREF_ENTRY_VALUES - summary = "%s" - - setOnPreferenceChangeListener { _, newValue -> - val selected = newValue as String - val index = this.findIndexOfValue(selected) - val entry = entryValues[index] as String - preferences.edit().putString(SERVER_PREF, entry).commit() - } - } - val dataSaverPref = ListPreference(screen.context).apply { - key = DATA_SAVER_PREF_Title - title = DATA_SAVER_PREF_Title - entries = arrayOf("Disable", "Enable") - entryValues = arrayOf("0", "1") - summary = "%s" - - setOnPreferenceChangeListener { _, newValue -> - val selected = newValue as String - val index = this.findIndexOfValue(selected) - preferences.edit().putInt(DATA_SAVER_PREF, index).commit() - } - } - - screen.addPreference(r18Pref) - screen.addPreference(thumbsPref) - screen.addPreference(serverPref) - screen.addPreference(dataSaverPref) - } - private fun getShowR18(): Int = preferences.getInt(SHOW_R18_PREF, 0) private fun getShowThumbnail(): Int = preferences.getInt(SHOW_THUMBNAIL_PREF, 0) private fun getServer(): String { @@ -1068,11 +1003,11 @@ class CoverInterceptor : Interceptor { val originalRequest = chain.request() return chain.proceed(chain.request()).let { response -> - if (response.code() == 404 && originalRequest.url().toString().contains(coverRegex)) { + if (response.code == 404 && originalRequest.url.toString().contains(coverRegex)) { response.close() chain.proceed( originalRequest.newBuilder().url( - originalRequest.url().toString().substringBeforeLast(".") + ".thumb.jpg" + originalRequest.url.toString().substringBeforeLast(".") + ".thumb.jpg" ).build() ) } else { @@ -1087,7 +1022,7 @@ class MdRateLimitInterceptor : Interceptor { private val baseInterceptor = RateLimitInterceptor(2) override fun intercept(chain: Interceptor.Chain): Response = - if (chain.request().url().toString().contains(coverRegex)) + if (chain.request().url.toString().contains(coverRegex)) chain.proceed(chain.request()) else baseInterceptor.intercept(chain) @@ -1105,7 +1040,7 @@ class MdAtHomeReportInterceptor( val originalRequest = chain.request() return chain.proceed(chain.request()).let { response -> - val url = originalRequest.url().toString() + val url = originalRequest.url.toString() if (url.contains(mdAtHomeUrlRegex)) { val jsonString = gson.toJson( mapOf( diff --git a/src/all/mangaplus/src/eu/kanade/tachiyomi/extension/all/mangaplus/MangaPlus.kt b/src/all/mangaplus/src/eu/kanade/tachiyomi/extension/all/mangaplus/MangaPlus.kt index 5ecbe83bd..a84f35db0 100644 --- a/src/all/mangaplus/src/eu/kanade/tachiyomi/extension/all/mangaplus/MangaPlus.kt +++ b/src/all/mangaplus/src/eu/kanade/tachiyomi/extension/all/mangaplus/MangaPlus.kt @@ -3,9 +3,6 @@ package eu.kanade.tachiyomi.extension.all.mangaplus import android.app.Application import android.content.SharedPreferences import android.os.Build -import android.support.v7.preference.CheckBoxPreference -import android.support.v7.preference.ListPreference -import android.support.v7.preference.PreferenceScreen import com.google.gson.Gson import com.squareup.duktape.Duktape import eu.kanade.tachiyomi.network.GET @@ -19,9 +16,9 @@ import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.HttpSource import kotlinx.serialization.protobuf.ProtoBuf import okhttp3.Headers -import okhttp3.HttpUrl +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.Interceptor -import okhttp3.MediaType +import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.Response @@ -59,7 +56,7 @@ abstract class MangaPlus( private val protobufJs: String by lazy { val request = GET(PROTOBUFJS_CDN, headers) - client.newCall(request).execute().body()!!.string() + client.newCall(request).execute().body!!.string() } private val gson: Gson by lazy { Gson() } @@ -274,7 +271,7 @@ abstract class MangaPlus( .set("Referer", "$baseUrl/viewer/$chapterId") .build() - val url = HttpUrl.parse("$API_URL/manga_viewer")!!.newBuilder() + val url = "$API_URL/manga_viewer".toHttpUrlOrNull()!!.newBuilder() .addQueryParameter("chapter_id", chapterId) .addQueryParameter("split", splitImages) .addQueryParameter("img_quality", imageResolution) @@ -289,7 +286,7 @@ abstract class MangaPlus( if (result.success == null) throw Exception(result.error!!.langPopup.body) - val referer = response.request().header("Referer")!! + val referer = response.request.header("Referer")!! return result.success.mangaViewer!!.pages .mapNotNull { it.page } @@ -344,48 +341,16 @@ abstract class MangaPlus( screen.addPreference(splitPref) } - override fun setupPreferenceScreen(screen: PreferenceScreen) { - val resolutionPref = ListPreference(screen.context).apply { - key = "${RESOLUTION_PREF_KEY}_$lang" - title = RESOLUTION_PREF_TITLE - entries = RESOLUTION_PREF_ENTRIES - entryValues = RESOLUTION_PREF_ENTRY_VALUES - setDefaultValue(RESOLUTION_PREF_DEFAULT_VALUE) - summary = "%s" - - setOnPreferenceChangeListener { _, newValue -> - val selected = newValue as String - val index = findIndexOfValue(selected) - val entry = entryValues[index] as String - preferences.edit().putString("${RESOLUTION_PREF_KEY}_$lang", entry).commit() - } - } - val splitPref = CheckBoxPreference(screen.context).apply { - key = "${SPLIT_PREF_KEY}_$lang" - title = SPLIT_PREF_TITLE - summary = SPLIT_PREF_SUMMARY - setDefaultValue(SPLIT_PREF_DEFAULT_VALUE) - - setOnPreferenceChangeListener { _, newValue -> - val checkValue = newValue as Boolean - preferences.edit().putBoolean("${SPLIT_PREF_KEY}_$lang", checkValue).commit() - } - } - - screen.addPreference(resolutionPref) - screen.addPreference(splitPref) - } - private fun imageIntercept(chain: Interceptor.Chain): Response { var request = chain.request() - if (request.url().queryParameter("encryptionKey") == null) + if (request.url.queryParameter("encryptionKey") == null) return chain.proceed(request) - val encryptionKey = request.url().queryParameter("encryptionKey")!! + val encryptionKey = request.url.queryParameter("encryptionKey")!! // Change the url and remove the encryptionKey to avoid detection. - val newUrl = request.url().newBuilder() + val newUrl = request.url.newBuilder() .removeAllQueryParameters("encryptionKey") .build() request = request.newBuilder() @@ -395,8 +360,8 @@ abstract class MangaPlus( val response = chain.proceed(request) val contentType = response.header("Content-Type", "image/jpeg")!! - val image = decodeImage(encryptionKey, response.body()!!.bytes()) - val body = ResponseBody.create(MediaType.parse(contentType), image) + val image = decodeImage(encryptionKey, response.body!!.bytes()) + val body = ResponseBody.create(contentType.toMediaTypeOrNull(), image) return response.newBuilder() .body(body) @@ -427,17 +392,17 @@ abstract class MangaPlus( val response = chain.proceed(request) // Check if it is 404 to maintain compatibility when the extension used Weserv. - val isBadCode = (response.code() == 401 || response.code() == 404) + val isBadCode = (response.code == 401 || response.code == 404) - if (isBadCode && request.url().toString().contains(TITLE_THUMBNAIL_PATH)) { - val titleId = request.url().toString() + if (isBadCode && request.url.toString().contains(TITLE_THUMBNAIL_PATH)) { + val titleId = request.url.toString() .substringBefore("/$TITLE_THUMBNAIL_PATH") .substringAfterLast("/") .toInt() val title = titleList?.find { it.titleId == titleId } ?: return response response.close() - val thumbnailRequest = GET(title.portraitImageUrl, request.headers()) + val thumbnailRequest = GET(title.portraitImageUrl, request.headers) return chain.proceed(thumbnailRequest) } @@ -457,13 +422,13 @@ abstract class MangaPlus( private fun Response.asProto(): MangaPlusResponse { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) - return ProtoBuf.decodeFromByteArray(MangaPlusSerializer, body()!!.bytes()) + return ProtoBuf.decodeFromByteArray(MangaPlusSerializer, body!!.bytes()) // The kotlinx.serialization library eventually always have some issues with // devices with Android version below Nougat. So, if the device is running Marshmallow // or lower, the deserialization is done using ProtobufJS + Duktape + Gson. - val bytes = body()!!.bytes() + val bytes = body!!.bytes() val messageBytes = "var BYTE_ARR = new Uint8Array([${bytes.joinToString()}]);" val res = Duktape.create().use { diff --git a/src/all/mangatoon/src/eu/kanade/tachiyomi/extension/all/mangatoon/MangaToon.kt b/src/all/mangatoon/src/eu/kanade/tachiyomi/extension/all/mangatoon/MangaToon.kt index 873fdfe8e..4aba053a7 100644 --- a/src/all/mangatoon/src/eu/kanade/tachiyomi/extension/all/mangatoon/MangaToon.kt +++ b/src/all/mangatoon/src/eu/kanade/tachiyomi/extension/all/mangatoon/MangaToon.kt @@ -7,7 +7,7 @@ import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.ParsedHttpSource import eu.kanade.tachiyomi.util.asJsoup -import okhttp3.HttpUrl +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.Request import okhttp3.Response import org.jsoup.nodes.Document @@ -42,7 +42,7 @@ open class MangaToon( return GET("$baseUrl/$urllang/genre/new?page=$page0", headers) } override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { - val url = HttpUrl.parse("$baseUrl/$urllang/search?word=$query")?.newBuilder() + val url = "$baseUrl/$urllang/search?word=$query".toHttpUrlOrNull()?.newBuilder() return GET(url.toString(), headers) } diff --git a/src/all/mango/src/eu/kanade/tachiyomi/extension/all/mango/Mango.kt b/src/all/mango/src/eu/kanade/tachiyomi/extension/all/mango/Mango.kt index 75cf52e32..a1081ffaa 100644 --- a/src/all/mango/src/eu/kanade/tachiyomi/extension/all/mango/Mango.kt +++ b/src/all/mango/src/eu/kanade/tachiyomi/extension/all/mango/Mango.kt @@ -2,8 +2,6 @@ package eu.kanade.tachiyomi.extension.all.mango import android.app.Application import android.content.SharedPreferences -import android.support.v7.preference.EditTextPreference -import android.support.v7.preference.PreferenceScreen import android.text.InputType import android.widget.Toast import com.github.salomonbrys.kotson.fromJson @@ -11,7 +9,7 @@ import com.github.salomonbrys.kotson.get import com.google.gson.Gson import com.google.gson.JsonObject import com.google.gson.JsonSyntaxException -import eu.kanade.tachiyomi.extension.BuildConfig +import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.POST import eu.kanade.tachiyomi.network.asObservableSuccess @@ -44,7 +42,7 @@ class Mango : ConfigurableSource, HttpSource() { // Our popular manga are just our library of manga override fun popularMangaParse(response: Response): MangasPage { val result = try { - gson.fromJson(response.body()!!.string()) + gson.fromJson(response.body!!.string()) } catch (e: JsonSyntaxException) { apiCookies = "" throw Exception("Login Likely Failed. Try Refreshing.") @@ -120,7 +118,7 @@ class Mango : ConfigurableSource, HttpSource() { // This will just return the same thing as the main library endpoint override fun mangaDetailsParse(response: Response): SManga { val result = try { - gson.fromJson(response.body()!!.string()) + gson.fromJson(response.body!!.string()) } catch (e: JsonSyntaxException) { apiCookies = "" throw Exception("Login Likely Failed. Try Refreshing.") @@ -138,7 +136,7 @@ class Mango : ConfigurableSource, HttpSource() { // The chapter url will contain how many pages the chapter contains for our page list endpoint override fun chapterListParse(response: Response): List { val result = try { - gson.fromJson(response.body()!!.string()) + gson.fromJson(response.body!!.string()) } catch (e: JsonSyntaxException) { apiCookies = "" throw Exception("Login Likely Failed. Try Refreshing.") @@ -235,7 +233,7 @@ class Mango : ConfigurableSource, HttpSource() { .build() val loginRequest = POST("$baseUrl/login", formHeaders, formBody) val response = chain.proceed(loginRequest) - if (response.code() != 200 || response.header("Set-Cookie") == null) { + if (response.code != 200 || response.header("Set-Cookie") == null) { throw Exception("Login Failed. Check Address and Credentials") } // Save the cookies from the response @@ -276,33 +274,6 @@ class Mango : ConfigurableSource, HttpSource() { } } - override fun setupPreferenceScreen(screen: PreferenceScreen) { - screen.addPreference(screen.supportEditTextPreference(ADDRESS_TITLE, ADDRESS_DEFAULT, baseUrl)) - screen.addPreference(screen.supportEditTextPreference(USERNAME_TITLE, USERNAME_DEFAULT, username)) - screen.addPreference(screen.supportEditTextPreference(PASSWORD_TITLE, PASSWORD_DEFAULT, password)) - } - - private fun PreferenceScreen.supportEditTextPreference(title: String, default: String, value: String): EditTextPreference { - return EditTextPreference(context).apply { - key = title - this.title = title - summary = value - this.setDefaultValue(default) - dialogTitle = title - setOnPreferenceChangeListener { _, newValue -> - try { - val res = preferences.edit().putString(title, newValue as String).commit() - Toast.makeText(context, "Restart Tachiyomi to apply new setting.", Toast.LENGTH_LONG).show() - apiCookies = "" - res - } catch (e: Exception) { - e.printStackTrace() - false - } - } - } - } - // We strip the last slash since we will append it above private fun getPrefBaseUrl(): String { var path = preferences.getString(ADDRESS_TITLE, ADDRESS_DEFAULT)!! diff --git a/src/all/mmrcms/src/eu/kanade/tachiyomi/extension/all/mmrcms/Generator.kt b/src/all/mmrcms/src/eu/kanade/tachiyomi/extension/all/mmrcms/Generator.kt index 2af17d67b..d8fb575ec 100644 --- a/src/all/mmrcms/src/eu/kanade/tachiyomi/extension/all/mmrcms/Generator.kt +++ b/src/all/mmrcms/src/eu/kanade/tachiyomi/extension/all/mmrcms/Generator.kt @@ -17,7 +17,6 @@ import java.util.concurrent.TimeUnit import javax.net.ssl.SSLContext import javax.net.ssl.TrustManager import javax.net.ssl.X509TrustManager -import kotlin.jvm.Throws /** * This class generates the sources for MMRCMS. @@ -123,21 +122,21 @@ class Generator { val request = Request.Builder().url(url) getOkHttpClient().newCall(request.build()).execute().let { response -> // Bypass Cloudflare ("Please wait 5 seconds" page) - if (response.code() == 503 && response.header("Server") in serverCheck) { + if (response.code == 503 && response.header("Server") in serverCheck) { var cookie = "${response.header("Set-Cookie")!!.substringBefore(";")}; " - Jsoup.parse(response.body()!!.string()).let { document -> + Jsoup.parse(response.body!!.string()).let { document -> val path = document.select("[id=\"challenge-form\"]").attr("action") val chk = document.select("[name=\"s\"]").attr("value") getOkHttpClient().newCall(Request.Builder().url("$url/$path?s=$chk").build()).execute().let { solved -> cookie += solved.header("Set-Cookie")!!.substringBefore(";") request.addHeader("Cookie", cookie).build().let { - return Jsoup.parse(getOkHttpClient().newCall(it).execute().body()?.string()) + return Jsoup.parse(getOkHttpClient().newCall(it).execute().body?.string()) } } } } - if (response.code() == 200) { - return Jsoup.parse(response.body()?.string()) + if (response.code == 200) { + return Jsoup.parse(response.body?.string()) } } } catch (e: Exception) { diff --git a/src/all/mmrcms/src/eu/kanade/tachiyomi/extension/all/mmrcms/MyMangaReaderCMSSource.kt b/src/all/mmrcms/src/eu/kanade/tachiyomi/extension/all/mmrcms/MyMangaReaderCMSSource.kt index 644af8f64..a214a09a4 100644 --- a/src/all/mmrcms/src/eu/kanade/tachiyomi/extension/all/mmrcms/MyMangaReaderCMSSource.kt +++ b/src/all/mmrcms/src/eu/kanade/tachiyomi/extension/all/mmrcms/MyMangaReaderCMSSource.kt @@ -109,9 +109,9 @@ open class MyMangaReaderCMSSource( override fun popularMangaParse(response: Response) = internalMangaParse(response) override fun searchMangaParse(response: Response): MangasPage { - return if (listOf("query", "q").any { it in response.request().url().queryParameterNames() }) { + return if (listOf("query", "q").any { it in response.request.url.queryParameterNames }) { // If a search query was specified, use search instead! - val jsonArray = jsonParser.parse(response.body()!!.string()).let { + val jsonArray = jsonParser.parse(response.body!!.string()).let { if (name == "Mangas.pw") it.array else it["suggestions"].array } MangasPage( diff --git a/src/all/myreadingmanga/src/eu/kanade/tachiyomi/extension/all/myreadingmanga/MyReadingManga.kt b/src/all/myreadingmanga/src/eu/kanade/tachiyomi/extension/all/myreadingmanga/MyReadingManga.kt index 2fc471020..ff3ef8510 100644 --- a/src/all/myreadingmanga/src/eu/kanade/tachiyomi/extension/all/myreadingmanga/MyReadingManga.kt +++ b/src/all/myreadingmanga/src/eu/kanade/tachiyomi/extension/all/myreadingmanga/MyReadingManga.kt @@ -231,7 +231,7 @@ open class MyReadingManga(override val lang: String, private val siteLang: Strin // Grabs page containing filters and puts it into cache private fun filterAssist(url: String): String { val response = client.newCall(GET(url, headers)).execute() - return response.body()!!.string() + return response.body!!.string() } // Returns page from cache to reduce calls to website diff --git a/src/all/nhentai/src/eu/kanade/tachiyomi/extension/all/nhentai/NHentai.kt b/src/all/nhentai/src/eu/kanade/tachiyomi/extension/all/nhentai/NHentai.kt index 6c025e51d..7fb298a5f 100644 --- a/src/all/nhentai/src/eu/kanade/tachiyomi/extension/all/nhentai/NHentai.kt +++ b/src/all/nhentai/src/eu/kanade/tachiyomi/extension/all/nhentai/NHentai.kt @@ -2,8 +2,6 @@ package eu.kanade.tachiyomi.extension.all.nhentai import android.app.Application import android.content.SharedPreferences -import android.support.v7.preference.ListPreference -import android.support.v7.preference.PreferenceScreen import eu.kanade.tachiyomi.extension.all.nhentai.NHUtils.getArtists import eu.kanade.tachiyomi.extension.all.nhentai.NHUtils.getGroups import eu.kanade.tachiyomi.extension.all.nhentai.NHUtils.getNumPages @@ -22,7 +20,7 @@ import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.ParsedHttpSource import eu.kanade.tachiyomi.util.asJsoup -import okhttp3.HttpUrl +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.Response @@ -83,29 +81,6 @@ open class NHentai( screen.addPreference(serverPref) } - override fun setupPreferenceScreen(screen: PreferenceScreen) { - val serverPref = ListPreference(screen.context).apply { - key = TITLE_PREF - title = TITLE_PREF - entries = arrayOf("Full Title", "Short Title") - entryValues = arrayOf("full", "short") - summary = "%s" - - setOnPreferenceChangeListener { _, newValue -> - displayFullTitle = when (newValue) { - "full" -> true - else -> false - } - true - } - } - - if (!preferences.contains(TITLE_PREF)) - preferences.edit().putString(TITLE_PREF, "full").apply() - - screen.addPreference(serverPref) - } - override fun latestUpdatesRequest(page: Int) = GET(if (nhLang.isBlank()) "$baseUrl/?page=$page" else "$baseUrl/language/$nhLang/?page=$page", headers) override fun latestUpdatesSelector() = "#content .gallery" @@ -161,13 +136,13 @@ open class NHentai( val isOkayToSort = filterList.findInstance()?.state?.isBlank() ?: true if (favoriteFilter?.state == true) { - val url = HttpUrl.parse("$baseUrl/favorites")!!.newBuilder() + val url = "$baseUrl/favorites".toHttpUrlOrNull()!!.newBuilder() .addQueryParameter("q", "$query $advQuery") .addQueryParameter("page", page.toString()) return GET(url.toString(), headers) } else { - val url = HttpUrl.parse("$baseUrl/search")!!.newBuilder() + val url = "$baseUrl/search".toHttpUrlOrNull()!!.newBuilder() .addQueryParameter("q", "$query $nhLangSearch$advQuery") .addQueryParameter("page", page.toString()) @@ -211,7 +186,7 @@ open class NHentai( } override fun searchMangaParse(response: Response): MangasPage { - if (response.request().url().toString().contains("/login/")) { + if (response.request.url.toString().contains("/login/")) { val document = response.asJsoup() if (document.select(".fa-sign-in").isNotEmpty()) { throw Exception("Log in via WebView to view favorites") @@ -256,7 +231,7 @@ open class NHentai( name = "Chapter" scanlator = getGroups(document) date_upload = getTime(document) - setUrlWithoutDomain(response.request().url().encodedPath()) + setUrlWithoutDomain(response.request.url.encodedPath) } ) } diff --git a/src/all/ninehentai/src/eu/kanade/tachiyomi/extension/all/ninehentai/NineHentai.kt b/src/all/ninehentai/src/eu/kanade/tachiyomi/extension/all/ninehentai/NineHentai.kt index 050f9ffc2..d43079d52 100644 --- a/src/all/ninehentai/src/eu/kanade/tachiyomi/extension/all/ninehentai/NineHentai.kt +++ b/src/all/ninehentai/src/eu/kanade/tachiyomi/extension/all/ninehentai/NineHentai.kt @@ -19,7 +19,7 @@ import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.util.asJsoup -import okhttp3.MediaType +import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.RequestBody @@ -75,7 +75,7 @@ class NineHentai : HttpSource() { } private fun getMangaList(response: Response, page: Int): MangasPage { - val jsonData = response.body()!!.string() + val jsonData = response.body!!.string() val jsonObject = JsonParser().parse(jsonData).asJsonObject val totalPages = jsonObject["total_count"].int val results = jsonObject["results"].array @@ -150,7 +150,7 @@ class NineHentai : HttpSource() { } override fun pageListParse(response: Response): List { - val jsonData = response.body()!!.string() + val jsonData = response.body!!.string() val jsonObject = JsonParser().parse(jsonData).asJsonObject val jsonArray = jsonObject.getAsJsonObject("results") var imageUrl: String @@ -168,7 +168,7 @@ class NineHentai : HttpSource() { "$imageUrl/preview/${totalPages}t.jpg", headersBuilder().build() ) - ).execute().code().let { code -> + ).execute().code.let { code -> if (code == 404) totalPages-- } @@ -214,7 +214,7 @@ class NineHentai : HttpSource() { override fun chapterListParse(response: Response): List = throw Exception("Not Used") companion object { - private val MEDIA_TYPE = MediaType.parse("application/json; charset=utf-8") + private val MEDIA_TYPE = "application/json; charset=utf-8".toMediaTypeOrNull() private const val SEARCH_URL = "/api/getBook" private const val MANGA_URL = "/api/getBookByID" } diff --git a/src/all/ninemanga/src/eu/kanade/tachiyomi/extension/all/ninemanga/NineManga.kt b/src/all/ninemanga/src/eu/kanade/tachiyomi/extension/all/ninemanga/NineManga.kt index 98ac0203f..5d37c3686 100644 --- a/src/all/ninemanga/src/eu/kanade/tachiyomi/extension/all/ninemanga/NineManga.kt +++ b/src/all/ninemanga/src/eu/kanade/tachiyomi/extension/all/ninemanga/NineManga.kt @@ -8,7 +8,7 @@ import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.ParsedHttpSource import okhttp3.Headers -import okhttp3.HttpUrl +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.Request import org.jsoup.nodes.Document import org.jsoup.nodes.Element @@ -113,7 +113,7 @@ open class NineManga(override val name: String, override val baseUrl: String, ov override fun imageUrlParse(document: Document) = document.select("div.pic_box img.manga_pic").first().attr("src").orEmpty() override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { - val url = HttpUrl.parse("$baseUrl/search/")!!.newBuilder() + val url = "$baseUrl/search/".toHttpUrlOrNull()!!.newBuilder() url.addQueryParameter("wd", query) url.addQueryParameter("page", page.toString()) diff --git a/src/all/simplyhentai/src/eu/kanade/tachiyomi/extension/all/simplyhentai/SimplyHentai.kt b/src/all/simplyhentai/src/eu/kanade/tachiyomi/extension/all/simplyhentai/SimplyHentai.kt index 32284f862..f7c6daefc 100644 --- a/src/all/simplyhentai/src/eu/kanade/tachiyomi/extension/all/simplyhentai/SimplyHentai.kt +++ b/src/all/simplyhentai/src/eu/kanade/tachiyomi/extension/all/simplyhentai/SimplyHentai.kt @@ -15,7 +15,7 @@ import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.ParsedHttpSource import eu.kanade.tachiyomi.util.asJsoup -import okhttp3.HttpUrl +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.Response @@ -75,7 +75,7 @@ abstract class SimplyHentai( // Search override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { - val url = HttpUrl.parse("$baseUrl/search")!!.newBuilder() + val url = "$baseUrl/search".toHttpUrlOrNull()!!.newBuilder() .addQueryParameter("query", query) .addQueryParameter("language_ids[$searchLang]", searchLang) .addQueryParameter("page", page.toString()) @@ -135,7 +135,7 @@ abstract class SimplyHentai( return listOf( SChapter.create().apply { name = "Chapter" - url = response.request().url().toString().removeSuffix("/").substringAfterLast("/") + url = response.request.url.toString().removeSuffix("/").substringAfterLast("/") chapter_number = 1f date_upload = response.asJsoup().select(".stat-container div:contains(Uploaded) div.bold")?.text().let { @@ -158,7 +158,7 @@ abstract class SimplyHentai( override fun pageListParse(response: Response): List { val pages = mutableListOf() - gson.fromJson(response.body()!!.string()).forEach { _, jsonElement -> + gson.fromJson(response.body!!.string()).forEach { _, jsonElement -> pages.add(Page(pages.size, "", jsonElement["sizes"]["full"].string)) } diff --git a/src/ar/andromedascans/src/eu/kanade/tachiyomi/extension/ar/andromedascans/AndromedaScans.kt b/src/ar/andromedascans/src/eu/kanade/tachiyomi/extension/ar/andromedascans/AndromedaScans.kt index d14ad740c..8544fe439 100644 --- a/src/ar/andromedascans/src/eu/kanade/tachiyomi/extension/ar/andromedascans/AndromedaScans.kt +++ b/src/ar/andromedascans/src/eu/kanade/tachiyomi/extension/ar/andromedascans/AndromedaScans.kt @@ -7,9 +7,9 @@ import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.ParsedHttpSource -import okhttp3.MediaType +import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.Request -import okhttp3.RequestBody +import okhttp3.RequestBody.Companion.toRequestBody import org.jsoup.nodes.Document import org.jsoup.nodes.Element import java.text.SimpleDateFormat @@ -46,7 +46,7 @@ class AndromedaScans : ParsedHttpSource() { override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { val type = "application/x-www-form-urlencoded; charset=UTF-8" - val body = RequestBody.create(MediaType.parse(type), "action=data_fetch&keyword=$query") + val body = "action=data_fetch&keyword=$query".toRequestBody(type.toMediaTypeOrNull()) return POST("$baseUrl/wp-admin/admin-ajax.php", headers, body) } diff --git a/src/ar/gmanga/src/eu/kanade/tachiyomi/extension/ar/gmanga/Gmanga.kt b/src/ar/gmanga/src/eu/kanade/tachiyomi/extension/ar/gmanga/Gmanga.kt index 020b97c59..51e726993 100644 --- a/src/ar/gmanga/src/eu/kanade/tachiyomi/extension/ar/gmanga/Gmanga.kt +++ b/src/ar/gmanga/src/eu/kanade/tachiyomi/extension/ar/gmanga/Gmanga.kt @@ -1,6 +1,6 @@ package eu.kanade.tachiyomi.extension.ar.gmanga -import android.support.v7.preference.PreferenceScreen +import androidx.preference.PreferenceScreen import com.github.salomonbrys.kotson.fromJson import com.github.salomonbrys.kotson.get import com.github.salomonbrys.kotson.nullString @@ -21,7 +21,7 @@ import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.util.asJsoup import okhttp3.Headers -import okhttp3.MediaType +import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.RequestBody @@ -55,8 +55,6 @@ class Gmanga : ConfigurableSource, HttpSource() { override fun setupPreferenceScreen(screen: PreferenceScreen) = preferences.setupPreferenceScreen(screen) - override fun setupPreferenceScreen(screen: androidx.preference.PreferenceScreen) = preferences.setupPreferenceScreen(screen) - override fun chapterListRequest(manga: SManga): Request { val mangaId = manga.url.substringAfterLast("/") return GET("$baseUrl/api/mangas/$mangaId/releases", headers) @@ -128,7 +126,7 @@ class Gmanga : ConfigurableSource, HttpSource() { } override fun pageListParse(response: Response): List { - val url = response.request().url().toString() + val url = response.request.url.toString() val data = gson.fromJson(response.asJsoup().select(".js-react-on-rails-component").html()) val releaseData = data["readerDataAction"]["readerData"]["release"].asJsonObject @@ -163,7 +161,7 @@ class Gmanga : ConfigurableSource, HttpSource() { } private fun decryptResponse(response: Response): JsonObject { - val encryptedData = gson.fromJson(response.body()!!.string())["data"].asString + val encryptedData = gson.fromJson(response.body!!.string())["data"].asString val decryptedData = decrypt(encryptedData) return gson.fromJson(decryptedData) } @@ -179,6 +177,6 @@ class Gmanga : ConfigurableSource, HttpSource() { companion object { private const val USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36" - private val MEDIA_TYPE = MediaType.parse("application/json; charset=utf-8") + private val MEDIA_TYPE = "application/json; charset=utf-8".toMediaTypeOrNull() } } diff --git a/src/ar/gmanga/src/eu/kanade/tachiyomi/extension/ar/gmanga/GmangaPreferences.kt b/src/ar/gmanga/src/eu/kanade/tachiyomi/extension/ar/gmanga/GmangaPreferences.kt index 76af1c357..15269611f 100644 --- a/src/ar/gmanga/src/eu/kanade/tachiyomi/extension/ar/gmanga/GmangaPreferences.kt +++ b/src/ar/gmanga/src/eu/kanade/tachiyomi/extension/ar/gmanga/GmangaPreferences.kt @@ -2,8 +2,8 @@ package eu.kanade.tachiyomi.extension.ar.gmanga import android.app.Application import android.content.SharedPreferences -import android.support.v7.preference.ListPreference -import android.support.v7.preference.PreferenceScreen +import androidx.preference.ListPreference +import androidx.preference.PreferenceScreen import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -14,7 +14,6 @@ class GmangaPreferences(id: Long) { } fun setupPreferenceScreen(screen: PreferenceScreen) { - STRING_PREFERENCES.forEach { val preference = ListPreference(screen.context).apply { key = it.key @@ -31,24 +30,6 @@ class GmangaPreferences(id: Long) { } } - fun setupPreferenceScreen(screen: androidx.preference.PreferenceScreen) { - - STRING_PREFERENCES.forEach { - val preference = androidx.preference.ListPreference(screen.context).apply { - key = it.key - title = it.title - entries = it.entries() - entryValues = it.entryValues() - summary = "%s" - } - - if (!preferences.contains(it.key)) - preferences.edit().putString(it.key, it.default().key).apply() - - screen.addPreference(preference) - } - } - fun getString(pref: StringPreference): String { return preferences.getString(pref.key, pref.default().key)!! } diff --git a/src/ar/mangaae/src/eu/kanade/tachiyomi/extension/ar/mangaae/MangaAe.kt b/src/ar/mangaae/src/eu/kanade/tachiyomi/extension/ar/mangaae/MangaAe.kt index a2134a2c5..264a67e39 100644 --- a/src/ar/mangaae/src/eu/kanade/tachiyomi/extension/ar/mangaae/MangaAe.kt +++ b/src/ar/mangaae/src/eu/kanade/tachiyomi/extension/ar/mangaae/MangaAe.kt @@ -9,7 +9,7 @@ import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.ParsedHttpSource import okhttp3.Headers -import okhttp3.HttpUrl +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.OkHttpClient import okhttp3.Request import org.jsoup.nodes.Document @@ -90,7 +90,7 @@ class MangaAe : ParsedHttpSource() { } } url += "|arrange:minus" - return GET(HttpUrl.parse(url)!!.newBuilder().build().toString(), headers) + return GET(url.toHttpUrlOrNull()!!.newBuilder().build().toString(), headers) } override fun searchMangaSelector(): String = popularMangaSelector() diff --git a/src/ca/fansubscat/src/eu/kanade/tachiyomi/extension/ca/fansubscat/FansubsCat.kt b/src/ca/fansubscat/src/eu/kanade/tachiyomi/extension/ca/fansubscat/FansubsCat.kt index 2f9d34e86..7cec89e66 100644 --- a/src/ca/fansubscat/src/eu/kanade/tachiyomi/extension/ca/fansubscat/FansubsCat.kt +++ b/src/ca/fansubscat/src/eu/kanade/tachiyomi/extension/ca/fansubscat/FansubsCat.kt @@ -8,7 +8,7 @@ import com.github.salomonbrys.kotson.nullString import com.github.salomonbrys.kotson.string import com.google.gson.Gson import com.google.gson.JsonObject -import eu.kanade.tachiyomi.extension.BuildConfig +import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.asObservableSuccess import eu.kanade.tachiyomi.source.model.FilterList @@ -18,7 +18,7 @@ import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.HttpSource import okhttp3.Headers -import okhttp3.HttpUrl +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.Response @@ -44,7 +44,7 @@ class FansubsCat : HttpSource() { private val apiBaseUrl = "https://api.fansubs.cat" private fun parseMangaFromJson(response: Response): MangasPage { - val jsonObject = gson.fromJson(response.body()!!.string()) + val jsonObject = gson.fromJson(response.body!!.string()) val mangas = jsonObject["result"].asJsonArray.map { json -> SManga.create().apply { @@ -62,7 +62,7 @@ class FansubsCat : HttpSource() { } private fun parseChapterListFromJson(response: Response): List { - val jsonObject = gson.fromJson(response.body()!!.string()) + val jsonObject = gson.fromJson(response.body!!.string()) return jsonObject["result"].asJsonArray.map { json -> SChapter.create().apply { @@ -76,7 +76,7 @@ class FansubsCat : HttpSource() { } private fun parsePageListFromJson(response: Response): List { - val jsonObject = gson.fromJson(response.body()!!.string()) + val jsonObject = gson.fromJson(response.body!!.string()) return jsonObject["result"].asJsonArray.mapIndexed { i, it -> Page(i, it["url"].asString, it["url"].asString) @@ -102,7 +102,7 @@ class FansubsCat : HttpSource() { // Search override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { - val url = HttpUrl.parse("$apiBaseUrl/manga/search/$page")!!.newBuilder() + val url = "$apiBaseUrl/manga/search/$page".toHttpUrlOrNull()!!.newBuilder() .addQueryParameter("query", query) return GET(url.toString(), headers) } @@ -124,7 +124,7 @@ class FansubsCat : HttpSource() { } override fun mangaDetailsParse(response: Response): SManga { - val jsonObject = gson.fromJson(response.body()!!.string()) + val jsonObject = gson.fromJson(response.body!!.string()) return SManga.create().apply { url = jsonObject["result"]["slug"].string diff --git a/src/de/mangatube/src/eu/kanade/tachiyomi/extension/de/mangatube/MangaTube.kt b/src/de/mangatube/src/eu/kanade/tachiyomi/extension/de/mangatube/MangaTube.kt index 7d6b72314..0b506b185 100644 --- a/src/de/mangatube/src/eu/kanade/tachiyomi/extension/de/mangatube/MangaTube.kt +++ b/src/de/mangatube/src/eu/kanade/tachiyomi/extension/de/mangatube/MangaTube.kt @@ -66,7 +66,7 @@ class MangaTube : ParsedHttpSource() { // for future reference: if adding filters, advanced search might use a different key private fun parseMangaFromJson(response: Response, hasNextPage: Boolean): MangasPage { var titleKey = "manga_title" - val mangas = gson.fromJson(response.body()!!.string()) + val mangas = gson.fromJson(response.body!!.string()) .let { it["success"] ?: it["suggestions"].also { titleKey = "value" } } .asJsonArray .map { json -> diff --git a/src/en/comicastle/src/eu/kanade/tachiyomi/extension/en/comicastle/Comicastle.kt b/src/en/comicastle/src/eu/kanade/tachiyomi/extension/en/comicastle/Comicastle.kt index 15cea7eaa..4c43948b7 100644 --- a/src/en/comicastle/src/eu/kanade/tachiyomi/extension/en/comicastle/Comicastle.kt +++ b/src/en/comicastle/src/eu/kanade/tachiyomi/extension/en/comicastle/Comicastle.kt @@ -8,11 +8,12 @@ import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.ParsedHttpSource -import okhttp3.HttpUrl -import okhttp3.MediaType +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull +import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.RequestBody +import okhttp3.RequestBody.Companion.toRequestBody import okhttp3.Response import org.jsoup.nodes.Document import org.jsoup.nodes.Element @@ -69,7 +70,7 @@ class Comicastle : ParsedHttpSource() { // Search override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { - val url = HttpUrl.parse("$baseUrl/library/search")!!.newBuilder() + val url = "$baseUrl/library/search".toHttpUrlOrNull()!!.newBuilder() var rBody: RequestBody? = null (filters.let { if (it.isEmpty()) getFilterList() else filters }) @@ -160,4 +161,5 @@ class Comicastle : ParsedHttpSource() { private fun getPublisherList() = arrayOf("