From efd36388b0f18a018c3bea2c089265c4be8905db Mon Sep 17 00:00:00 2001 From: len Date: Fri, 27 May 2016 16:52:44 +0200 Subject: [PATCH] Fix network unsubscription crashes, refactor network methods --- app/build.gradle | 9 +-- .../tachiyomi/data/glide/AppGlideModule.kt | 2 +- .../data/mangasync/services/MyAnimeList.kt | 15 ++-- .../data/network/CloudflareInterceptor.kt | 4 +- .../tachiyomi/data/network/NetworkHelper.kt | 68 ++++--------------- .../data/network/OkHttpExtensions.kt | 41 +++++++++++ .../data/network/PersistentCookieStore.kt | 2 +- .../data/network/{Req.kt => Requests.kt} | 6 +- .../data/source/online/OnlineSource.kt | 27 ++++---- .../data/source/online/YamlOnlineSource.kt | 14 ++-- .../data/source/online/english/Batoto.kt | 25 +++---- .../data/source/online/english/Kissmanga.kt | 10 +-- .../source/online/english/Readmangatoday.kt | 4 +- .../data/updater/UpdateDownloader.kt | 7 +- 14 files changed, 113 insertions(+), 121 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/data/network/OkHttpExtensions.kt rename app/src/main/java/eu/kanade/tachiyomi/data/network/{Req.kt => Requests.kt} (92%) diff --git a/app/build.gradle b/app/build.gradle index de1b97230..1c04ab86a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -91,7 +91,6 @@ kapt { dependencies { final SUPPORT_LIBRARY_VERSION = '23.4.0' final DAGGER_VERSION = '2.4' - final OKHTTP_VERSION = '3.2.0' final RETROFIT_VERSION = '2.0.2' final NUCLEUS_VERSION = '3.0.0' final STORIO_VERSION = '1.8.0' @@ -118,7 +117,7 @@ dependencies { compile 'com.f2prateek.rx.preferences:rx-preferences:1.0.1' // Network client - compile "com.squareup.okhttp3:okhttp:$OKHTTP_VERSION" + compile "com.squareup.okhttp3:okhttp:3.3.0" // REST compile "com.squareup.retrofit2:retrofit:$RETROFIT_VERSION" @@ -141,7 +140,7 @@ dependencies { compile 'com.jakewharton:disklrucache:2.0.2' // Parse HTML - compile 'org.jsoup:jsoup:1.9.1' + compile 'org.jsoup:jsoup:1.9.2' // Changelog compile 'com.github.gabrielemariotti.changeloglib:changelog:2.1.0' @@ -176,9 +175,7 @@ dependencies { compile 'eu.davidea:flexible-adapter:4.2.0' compile 'com.nononsenseapps:filepicker:2.5.2' compile 'com.github.amulyakhare:TextDrawable:558677e' - compile('com.github.afollestad.material-dialogs:core:0.8.5.5@aar') { - transitive = true - } + compile 'com.afollestad.material-dialogs:core:0.8.5.9' // Tests testCompile 'junit:junit:4.12' diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/glide/AppGlideModule.kt b/app/src/main/java/eu/kanade/tachiyomi/data/glide/AppGlideModule.kt index 9ad04315f..aadc83f5e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/glide/AppGlideModule.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/glide/AppGlideModule.kt @@ -28,7 +28,7 @@ class AppGlideModule : GlideModule { override fun registerComponents(context: Context, glide: Glide) { App.get(context).component.inject(this) glide.register(GlideUrl::class.java, InputStream::class.java, - OkHttpUrlLoader.Factory(networkHelper.defaultClient)) + OkHttpUrlLoader.Factory(networkHelper.client)) glide.register(Manga::class.java, InputStream::class.java, MangaModelLoader.Factory()) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/mangasync/services/MyAnimeList.kt b/app/src/main/java/eu/kanade/tachiyomi/data/mangasync/services/MyAnimeList.kt index bd45b3ca3..f07dd8953 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/mangasync/services/MyAnimeList.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/mangasync/services/MyAnimeList.kt @@ -6,8 +6,8 @@ import android.util.Xml import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.MangaSync import eu.kanade.tachiyomi.data.mangasync.base.MangaSyncService -import eu.kanade.tachiyomi.data.network.get -import eu.kanade.tachiyomi.data.network.post +import eu.kanade.tachiyomi.data.network.GET +import eu.kanade.tachiyomi.data.network.POST import eu.kanade.tachiyomi.util.selectInt import eu.kanade.tachiyomi.util.selectText import okhttp3.* @@ -65,7 +65,8 @@ class MyAnimeList(private val context: Context, id: Int) : MangaSyncService(cont override fun login(username: String, password: String): Observable { createHeaders(username, password) - return networkService.request(get(getLoginUrl(), headers)) + return networkService.request(GET(getLoginUrl(), headers)) + .doOnNext { it.close() } .map { it.code() == 200 } } @@ -77,7 +78,7 @@ class MyAnimeList(private val context: Context, id: Int) : MangaSyncService(cont } fun search(query: String): Observable> { - return networkService.request(get(getSearchUrl(query), headers)) + return networkService.request(GET(getSearchUrl(query), headers)) .map { Jsoup.parse(it.body().string()) } .flatMap { Observable.from(it.select("entry")) } .filter { it.select("type").text() != "Novel" } @@ -102,7 +103,7 @@ class MyAnimeList(private val context: Context, id: Int) : MangaSyncService(cont // MAL doesn't support score with decimals fun getList(): Observable> { - return networkService.request(get(getListUrl(username), headers), networkService.forceCacheClient) + return networkService.request(GET(getListUrl(username), headers), networkService.forceCacheClient) .map { Jsoup.parse(it.body().string()) } .flatMap { Observable.from(it.select("manga")) } .map { @@ -130,7 +131,7 @@ class MyAnimeList(private val context: Context, id: Int) : MangaSyncService(cont if (manga.total_chapters != 0 && manga.last_chapter_read == manga.total_chapters) { manga.status = COMPLETED } - networkService.request(post(getUpdateUrl(manga), headers, getMangaPostPayload(manga))) + networkService.request(POST(getUpdateUrl(manga), headers, getMangaPostPayload(manga))) } } @@ -144,7 +145,7 @@ class MyAnimeList(private val context: Context, id: Int) : MangaSyncService(cont override fun add(manga: MangaSync): Observable { return Observable.defer { - networkService.request(post(getAddUrl(manga), headers, getMangaPostPayload(manga))) + networkService.request(POST(getAddUrl(manga), headers, getMangaPostPayload(manga))) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/network/CloudflareInterceptor.kt b/app/src/main/java/eu/kanade/tachiyomi/data/network/CloudflareInterceptor.kt index 2fb74ef9d..0ff0ea567 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/network/CloudflareInterceptor.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/network/CloudflareInterceptor.kt @@ -22,7 +22,7 @@ class CloudflareInterceptor(private val cookies: PersistentCookieStore) : Interc // Check if we already solved a challenge if (response.code() != 502 && - cookies.get(response.request().url()).find { it.name() == "cf_clearance" } != null) { + cookies.get(response.request().url()).any { it.name() == "cf_clearance" }) { return response } @@ -72,7 +72,7 @@ class CloudflareInterceptor(private val cookies: PersistentCookieStore) : Interc .toString() val referer = originalRequest.url().toString() - return get(url, originalRequest.headers().newBuilder().add("Referer", referer).build()) + return GET(url, originalRequest.headers().newBuilder().add("Referer", referer).build()) } finally { duktape.close() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/network/NetworkHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/network/NetworkHelper.kt index 9f588d8aa..0d6375f4f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/network/NetworkHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/network/NetworkHelper.kt @@ -1,12 +1,12 @@ package eu.kanade.tachiyomi.data.network import android.content.Context -import okhttp3.* +import okhttp3.Cache +import okhttp3.OkHttpClient +import okhttp3.Request +import okhttp3.Response import rx.Observable -import rx.subscriptions.Subscriptions -import timber.log.Timber import java.io.File -import java.io.IOException class NetworkHelper(context: Context) { @@ -16,74 +16,30 @@ class NetworkHelper(context: Context) { private val cookieManager = PersistentCookieJar(context) - val defaultClient = OkHttpClient.Builder() + val client = OkHttpClient.Builder() .cookieJar(cookieManager) .cache(Cache(cacheDir, cacheSize)) .build() - val forceCacheClient = defaultClient.newBuilder() - .addNetworkInterceptor({ chain -> + val forceCacheClient = client.newBuilder() + .addNetworkInterceptor { chain -> val originalResponse = chain.proceed(chain.request()) originalResponse.newBuilder() .removeHeader("Pragma") - .header("Cache-Control", "max-age=" + 600) + .header("Cache-Control", "max-age=600") .build() - }) + } .build() - val cloudflareClient = defaultClient.newBuilder() + val cloudflareClient = client.newBuilder() .addInterceptor(CloudflareInterceptor(cookies)) .build() val cookies: PersistentCookieStore get() = cookieManager.store - fun request(request: Request, client: OkHttpClient = defaultClient): Observable { - return Observable.create { subscriber -> - val call = client.newCall(request) - subscriber.add(Subscriptions.create { - call.cancel() - Timber.i("Cancel call on thread ${Thread.currentThread().id}") - }) - - call.enqueue(object : Callback { - override fun onResponse(call: Call, response: Response) { - if (!subscriber.isUnsubscribed) { - subscriber.add(Subscriptions.create { - response.body().close() - Timber.i("Close body on thread ${Thread.currentThread().id}") - }) - subscriber.onNext(response) - Timber.i("Emit response on thread ${Thread.currentThread().id}") - subscriber.onCompleted() - } - } - - override fun onFailure(call: Call, error: IOException) { - if (!subscriber.isUnsubscribed) { - subscriber.onError(error) - } - } - }) - } - } - - fun requestBodyProgress(request: Request, listener: ProgressListener): Observable { - return Observable.fromCallable { requestBodyProgressBlocking(request, listener) } - } - - fun requestBodyProgressBlocking(request: Request, listener: ProgressListener): Response { - val progressClient = defaultClient.newBuilder() - .cache(null) - .addNetworkInterceptor { chain -> - val originalResponse = chain.proceed(chain.request()) - originalResponse.newBuilder() - .body(ProgressResponseBody(originalResponse.body(), listener)) - .build() - } - .build() - - return progressClient.newCall(request).execute() + fun request(request: Request, client: OkHttpClient = this.client): Observable { + return client.newCall(request).asObservable() } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/network/OkHttpExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/data/network/OkHttpExtensions.kt new file mode 100644 index 000000000..32b39d912 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/data/network/OkHttpExtensions.kt @@ -0,0 +1,41 @@ +package eu.kanade.tachiyomi.data.network + +import okhttp3.Call +import okhttp3.OkHttpClient +import okhttp3.Request +import okhttp3.Response +import rx.Observable +import rx.subscriptions.Subscriptions +import java.io.IOException + +fun Call.asObservable(): Observable { + return Observable.create { subscriber -> + subscriber.add(Subscriptions.create { cancel() }) + + try { + val response = execute() + if (!subscriber.isUnsubscribed) { + subscriber.onNext(response) + subscriber.onCompleted() + } + } catch (error: IOException) { + if (!subscriber.isUnsubscribed) { + subscriber.onError(error) + } + } + } +} + +fun OkHttpClient.newCallWithProgress(request: Request, listener: ProgressListener): Call { + val progressClient = newBuilder() + .cache(null) + .addNetworkInterceptor { chain -> + val originalResponse = chain.proceed(chain.request()) + originalResponse.newBuilder() + .body(ProgressResponseBody(originalResponse.body(), listener)) + .build() + } + .build() + + return progressClient.newCall(request) +} \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/network/PersistentCookieStore.kt b/app/src/main/java/eu/kanade/tachiyomi/data/network/PersistentCookieStore.kt index 498e56f96..73690e7ff 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/network/PersistentCookieStore.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/network/PersistentCookieStore.kt @@ -70,6 +70,6 @@ class PersistentCookieStore(context: Context) { return cookieMap[url].orEmpty().filter { !it.hasExpired() } } - fun Cookie.hasExpired() = System.currentTimeMillis() >= expiresAt() + private fun Cookie.hasExpired() = System.currentTimeMillis() >= expiresAt() } \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/network/Req.kt b/app/src/main/java/eu/kanade/tachiyomi/data/network/Requests.kt similarity index 92% rename from app/src/main/java/eu/kanade/tachiyomi/data/network/Req.kt rename to app/src/main/java/eu/kanade/tachiyomi/data/network/Requests.kt index 65dfac225..ec53e21a3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/network/Req.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/network/Requests.kt @@ -7,8 +7,7 @@ private val DEFAULT_CACHE_CONTROL = CacheControl.Builder().maxAge(10, MINUTES).b private val DEFAULT_HEADERS = Headers.Builder().build() private val DEFAULT_BODY: RequestBody = FormBody.Builder().build() -@JvmOverloads -fun get(url: String, +fun GET(url: String, headers: Headers = DEFAULT_HEADERS, cache: CacheControl = DEFAULT_CACHE_CONTROL): Request { @@ -19,8 +18,7 @@ fun get(url: String, .build() } -@JvmOverloads -fun post(url: String, +fun POST(url: String, headers: Headers = DEFAULT_HEADERS, body: RequestBody = DEFAULT_BODY, cache: CacheControl = DEFAULT_CACHE_CONTROL): Request { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/OnlineSource.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/OnlineSource.kt index ff50a8a72..e7bc35de4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/OnlineSource.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/OnlineSource.kt @@ -5,8 +5,10 @@ import eu.kanade.tachiyomi.App import eu.kanade.tachiyomi.data.cache.ChapterCache import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga +import eu.kanade.tachiyomi.data.network.GET import eu.kanade.tachiyomi.data.network.NetworkHelper -import eu.kanade.tachiyomi.data.network.get +import eu.kanade.tachiyomi.data.network.asObservable +import eu.kanade.tachiyomi.data.network.newCallWithProgress import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.source.Language import eu.kanade.tachiyomi.data.source.Source @@ -57,7 +59,7 @@ abstract class OnlineSource(context: Context) : Source { * Default network client for doing requests. */ open val client: OkHttpClient - get() = network.defaultClient + get() = network.client init { // Inject dependencies. @@ -114,7 +116,7 @@ abstract class OnlineSource(context: Context) : Source { if (page.page == 1) { page.url = popularMangaInitialUrl() } - return get(page.url, headers) + return GET(page.url, headers) } /** @@ -159,7 +161,7 @@ abstract class OnlineSource(context: Context) : Source { if (page.page == 1) { page.url = searchMangaInitialUrl(query) } - return get(page.url, headers) + return GET(page.url, headers) } /** @@ -201,7 +203,7 @@ abstract class OnlineSource(context: Context) : Source { * @param manga the manga to be updated. */ open protected fun mangaDetailsRequest(manga: Manga): Request { - return get(baseUrl + manga.url, headers) + return GET(baseUrl + manga.url, headers) } /** @@ -236,7 +238,7 @@ abstract class OnlineSource(context: Context) : Source { * @param manga the manga to look for chapters. */ open protected fun chapterListRequest(manga: Manga): Request { - return get(baseUrl + manga.url, headers) + return GET(baseUrl + manga.url, headers) } /** @@ -281,7 +283,7 @@ abstract class OnlineSource(context: Context) : Source { * @param chapter the chapter whose page list has to be fetched */ open protected fun pageListRequest(chapter: Chapter): Request { - return get(baseUrl + chapter.url, headers) + return GET(baseUrl + chapter.url, headers) } /** @@ -321,7 +323,7 @@ abstract class OnlineSource(context: Context) : Source { * @param page the chapter whose page list has to be fetched */ open protected fun imageUrlRequest(page: Page): Request { - return get(page.url, headers) + return GET(page.url, headers) } /** @@ -347,11 +349,12 @@ abstract class OnlineSource(context: Context) : Source { * * @param page the page whose source image has to be downloaded. */ - fun imageResponse(page: Page): Observable = network - .requestBodyProgress(imageRequest(page), page) + fun imageResponse(page: Page): Observable = client + .newCallWithProgress(imageRequest(page), page) + .asObservable() .doOnNext { if (!it.isSuccessful) { - it.body().close() + it.close() throw RuntimeException("Not a valid response") } } @@ -363,7 +366,7 @@ abstract class OnlineSource(context: Context) : Source { * @param page the chapter whose page list has to be fetched */ open protected fun imageRequest(page: Page): Request { - return get(page.imageUrl, headers) + return GET(page.imageUrl, headers) } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/YamlOnlineSource.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/YamlOnlineSource.kt index 2acf7d22f..c8257db51 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/YamlOnlineSource.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/YamlOnlineSource.kt @@ -3,8 +3,8 @@ package eu.kanade.tachiyomi.data.source.online import android.content.Context import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga -import eu.kanade.tachiyomi.data.network.get -import eu.kanade.tachiyomi.data.network.post +import eu.kanade.tachiyomi.data.network.GET +import eu.kanade.tachiyomi.data.network.POST import eu.kanade.tachiyomi.data.source.getLanguages import eu.kanade.tachiyomi.data.source.model.MangasPage import eu.kanade.tachiyomi.data.source.model.Page @@ -32,7 +32,7 @@ class YamlOnlineSource(context: Context, mappings: Map<*, *>) : OnlineSource(con override val client = when(map.client) { "cloudflare" -> network.cloudflareClient - else -> network.defaultClient + else -> network.client } override val id = map.id.let { @@ -44,8 +44,8 @@ class YamlOnlineSource(context: Context, mappings: Map<*, *>) : OnlineSource(con page.url = popularMangaInitialUrl() } return when (map.popular.method?.toLowerCase()) { - "post" -> post(page.url, headers, map.popular.createForm()) - else -> get(page.url, headers) + "post" -> POST(page.url, headers, map.popular.createForm()) + else -> GET(page.url, headers) } } @@ -74,8 +74,8 @@ class YamlOnlineSource(context: Context, mappings: Map<*, *>) : OnlineSource(con page.url = searchMangaInitialUrl(query) } return when (map.search.method?.toLowerCase()) { - "post" -> post(page.url, headers, map.search.createForm()) - else -> get(page.url, headers) + "post" -> POST(page.url, headers, map.search.createForm()) + else -> GET(page.url, headers) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Batoto.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Batoto.kt index e12d5ff7d..0615db32c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Batoto.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Batoto.kt @@ -5,8 +5,8 @@ import android.net.Uri import android.text.Html import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga -import eu.kanade.tachiyomi.data.network.get -import eu.kanade.tachiyomi.data.network.post +import eu.kanade.tachiyomi.data.network.GET +import eu.kanade.tachiyomi.data.network.POST import eu.kanade.tachiyomi.data.source.EN import eu.kanade.tachiyomi.data.source.Language import eu.kanade.tachiyomi.data.source.model.MangasPage @@ -20,7 +20,6 @@ import org.jsoup.nodes.Document import org.jsoup.nodes.Element import rx.Observable import java.net.URI -import java.net.URISyntaxException import java.text.ParseException import java.text.SimpleDateFormat import java.util.* @@ -58,12 +57,12 @@ class Batoto(context: Context, override val id: Int) : ParsedOnlineSource(contex override fun mangaDetailsRequest(manga: Manga): Request { val mangaId = manga.url.substringAfterLast("r") - return get("$baseUrl/comic_pop?id=$mangaId", headers) + return GET("$baseUrl/comic_pop?id=$mangaId", headers) } override fun pageListRequest(chapter: Chapter): Request { val id = chapter.url.substringAfterLast("#") - return get("$baseUrl/areader?id=$id&p=1", headers) + return GET("$baseUrl/areader?id=$id&p=1", headers) } override fun imageUrlRequest(page: Page): Request { @@ -71,7 +70,7 @@ class Batoto(context: Context, override val id: Int) : ParsedOnlineSource(contex val start = pageUrl.indexOf("#") + 1 val end = pageUrl.indexOf("_", start) val id = pageUrl.substring(start, end) - return get("$baseUrl/areader?id=$id&p=${pageUrl.substring(end+1)}", headers) + return GET("$baseUrl/areader?id=$id&p=${pageUrl.substring(end+1)}", headers) } override fun popularMangaParse(response: Response, page: MangasPage) { @@ -216,9 +215,8 @@ class Batoto(context: Context, override val id: Int) : ParsedOnlineSource(contex } override fun login(username: String, password: String) = - network.request(get("$baseUrl/forums/index.php?app=core&module=global§ion=login", headers)) - .map { it.body().string() } - .flatMap { doLogin(it, username, password) } + network.request(GET("$baseUrl/forums/index.php?app=core&module=global§ion=login", headers)) + .flatMap { doLogin(it.body().string(), username, password) } .map { isAuthenticationSuccessful(it) } private fun doLogin(response: String, username: String, password: String): Observable { @@ -235,7 +233,7 @@ class Batoto(context: Context, override val id: Int) : ParsedOnlineSource(contex add("rememberMe", "1") }.build() - return network.request(post(url, headers, payload)) + return network.request(POST(url, headers, payload)) } override fun isLoginRequired() = true @@ -244,12 +242,7 @@ class Batoto(context: Context, override val id: Int) : ParsedOnlineSource(contex response.priorResponse() != null && response.priorResponse().code() == 302 override fun isLogged(): Boolean { - try { - return network.cookies.get(URI(baseUrl)).find { it.name() == "pass_hash" } != null - } catch (e: URISyntaxException) { - // Ignore - } - return false + return network.cookies.get(URI(baseUrl)).any { it.name() == "pass_hash" } } override fun fetchChapterList(manga: Manga): Observable> { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Kissmanga.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Kissmanga.kt index 0003e8556..5a45feec8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Kissmanga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Kissmanga.kt @@ -3,8 +3,8 @@ package eu.kanade.tachiyomi.data.source.online.english import android.content.Context import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga -import eu.kanade.tachiyomi.data.network.get -import eu.kanade.tachiyomi.data.network.post +import eu.kanade.tachiyomi.data.network.GET +import eu.kanade.tachiyomi.data.network.POST import eu.kanade.tachiyomi.data.source.EN import eu.kanade.tachiyomi.data.source.Language import eu.kanade.tachiyomi.data.source.model.MangasPage @@ -54,7 +54,7 @@ class Kissmanga(context: Context, override val id: Int) : ParsedOnlineSource(con add("genres", "") }.build() - return post(page.url, headers, form) + return POST(page.url, headers, form) } override fun searchMangaInitialUrl(query: String) = "$baseUrl/AdvanceSearch" @@ -95,7 +95,7 @@ class Kissmanga(context: Context, override val id: Int) : ParsedOnlineSource(con } ?: 0 } - override fun pageListRequest(chapter: Chapter) = post(baseUrl + chapter.url, headers) + override fun pageListRequest(chapter: Chapter) = POST(baseUrl + chapter.url, headers) override fun pageListParse(response: Response, pages: MutableList) { //language=RegExp @@ -111,7 +111,7 @@ class Kissmanga(context: Context, override val id: Int) : ParsedOnlineSource(con // Not used override fun pageListParse(document: Document, pages: MutableList) {} - override fun imageUrlRequest(page: Page) = get(page.url) + override fun imageUrlRequest(page: Page) = GET(page.url) override fun imageUrlParse(document: Document) = "" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Readmangatoday.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Readmangatoday.kt index 95d02492c..beabf4038 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Readmangatoday.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Readmangatoday.kt @@ -3,7 +3,7 @@ package eu.kanade.tachiyomi.data.source.online.english import android.content.Context import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga -import eu.kanade.tachiyomi.data.network.post +import eu.kanade.tachiyomi.data.network.POST import eu.kanade.tachiyomi.data.source.EN import eu.kanade.tachiyomi.data.source.Language import eu.kanade.tachiyomi.data.source.model.MangasPage @@ -47,7 +47,7 @@ class Readmangatoday(context: Context, override val id: Int) : ParsedOnlineSourc var builder = okhttp3.FormBody.Builder() builder.add("query", query) - return post(page.url, headers, builder.build()) + return POST(page.url, headers, builder.build()) } override fun searchMangaSelector() = "div.content-list > div.style-list > div.box" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/updater/UpdateDownloader.kt b/app/src/main/java/eu/kanade/tachiyomi/data/updater/UpdateDownloader.kt index 7c23e496f..108426011 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/updater/UpdateDownloader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/updater/UpdateDownloader.kt @@ -11,9 +11,10 @@ import android.support.v4.app.NotificationCompat import eu.kanade.tachiyomi.App import eu.kanade.tachiyomi.Constants import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.data.network.GET import eu.kanade.tachiyomi.data.network.NetworkHelper import eu.kanade.tachiyomi.data.network.ProgressListener -import eu.kanade.tachiyomi.data.network.get +import eu.kanade.tachiyomi.data.network.newCallWithProgress import eu.kanade.tachiyomi.util.notificationManager import eu.kanade.tachiyomi.util.saveTo import timber.log.Timber @@ -100,12 +101,14 @@ class UpdateDownloader(private val context: Context) : try { // Make the request and download the file - val response = network.requestBodyProgressBlocking(get(result.url), progressListener) + val response = network.client.newCallWithProgress(GET(result.url), progressListener).execute() if (response.isSuccessful) { response.body().source().saveTo(apkFile) // Set download successful result.successful = true + } else { + response.close() } } catch (e: Exception) { Timber.e(e, e.message)