|
|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package org.koitharu.kotatsu.ui.reader
|
|
|
|
|
|
|
|
|
|
import android.net.Uri
|
|
|
|
|
import android.util.ArrayMap
|
|
|
|
|
import kotlinx.coroutines.*
|
|
|
|
|
import okhttp3.OkHttpClient
|
|
|
|
|
import okhttp3.Request
|
|
|
|
|
@ -16,7 +17,7 @@ import kotlin.coroutines.CoroutineContext
|
|
|
|
|
class PageLoader : KoinComponent, CoroutineScope, DisposableHandle {
|
|
|
|
|
|
|
|
|
|
private val job = SupervisorJob()
|
|
|
|
|
private val tasks = HashMap<String, Deferred<File>>()
|
|
|
|
|
private val tasks = ArrayMap<String, Deferred<File>>()
|
|
|
|
|
private val okHttp by inject<OkHttpClient>()
|
|
|
|
|
private val cache by inject<PagesCache>()
|
|
|
|
|
|
|
|
|
|
@ -48,16 +49,17 @@ class PageLoader : KoinComponent, CoroutineScope, DisposableHandle {
|
|
|
|
|
val request = Request.Builder()
|
|
|
|
|
.url(url)
|
|
|
|
|
.get()
|
|
|
|
|
.header("Accept", "image/webp,image/png;q=0.9,image/jpeg,*/*;q=0.8")
|
|
|
|
|
.cacheControl(CacheUtils.CONTROL_DISABLED)
|
|
|
|
|
.build()
|
|
|
|
|
okHttp.newCall(request).await().use { response ->
|
|
|
|
|
val body = response.body
|
|
|
|
|
checkNotNull(body) {
|
|
|
|
|
"Null response"
|
|
|
|
|
}
|
|
|
|
|
check(response.isSuccessful) {
|
|
|
|
|
"Invalid response: ${response.code} ${response.message}"
|
|
|
|
|
}
|
|
|
|
|
checkNotNull(body) {
|
|
|
|
|
"Null response"
|
|
|
|
|
}
|
|
|
|
|
cache.put(url) { out ->
|
|
|
|
|
body.byteStream().copyTo(out)
|
|
|
|
|
}
|
|
|
|
|
|