|
|
@ -3,27 +3,38 @@ package io.legado.app.help.glide |
|
|
|
import com.bumptech.glide.Priority |
|
|
|
import com.bumptech.glide.Priority |
|
|
|
import com.bumptech.glide.load.DataSource |
|
|
|
import com.bumptech.glide.load.DataSource |
|
|
|
import com.bumptech.glide.load.HttpException |
|
|
|
import com.bumptech.glide.load.HttpException |
|
|
|
|
|
|
|
import com.bumptech.glide.load.Options |
|
|
|
import com.bumptech.glide.load.data.DataFetcher |
|
|
|
import com.bumptech.glide.load.data.DataFetcher |
|
|
|
import com.bumptech.glide.load.model.GlideUrl |
|
|
|
import com.bumptech.glide.load.model.GlideUrl |
|
|
|
import com.bumptech.glide.util.ContentLengthInputStream |
|
|
|
import com.bumptech.glide.util.ContentLengthInputStream |
|
|
|
import com.bumptech.glide.util.Preconditions |
|
|
|
import com.bumptech.glide.util.Preconditions |
|
|
|
import io.legado.app.help.http.okHttpClient |
|
|
|
import io.legado.app.help.http.okHttpClient |
|
|
|
|
|
|
|
import io.legado.app.model.NoStackTraceException |
|
|
|
|
|
|
|
import io.legado.app.utils.isWifiConnect |
|
|
|
import okhttp3.Call |
|
|
|
import okhttp3.Call |
|
|
|
import okhttp3.Request |
|
|
|
import okhttp3.Request |
|
|
|
import okhttp3.Response |
|
|
|
import okhttp3.Response |
|
|
|
import okhttp3.ResponseBody |
|
|
|
import okhttp3.ResponseBody |
|
|
|
|
|
|
|
import splitties.init.appCtx |
|
|
|
import java.io.IOException |
|
|
|
import java.io.IOException |
|
|
|
import java.io.InputStream |
|
|
|
import java.io.InputStream |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class OkHttpStreamFetcher(private val url: GlideUrl) : |
|
|
|
class OkHttpStreamFetcher(private val url: GlideUrl, private val options: Options) : |
|
|
|
DataFetcher<InputStream>, okhttp3.Callback { |
|
|
|
DataFetcher<InputStream>, okhttp3.Callback { |
|
|
|
private var stream: InputStream? = null |
|
|
|
private var stream: InputStream? = null |
|
|
|
private var responseBody: ResponseBody? = null |
|
|
|
private var responseBody: ResponseBody? = null |
|
|
|
private var callback: DataFetcher.DataCallback<in InputStream>? = null |
|
|
|
private var callback: DataFetcher.DataCallback<in InputStream>? = null |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Volatile |
|
|
|
private var call: Call? = null |
|
|
|
private var call: Call? = null |
|
|
|
|
|
|
|
|
|
|
|
override fun loadData(priority: Priority, callback: DataFetcher.DataCallback<in InputStream>) { |
|
|
|
override fun loadData(priority: Priority, callback: DataFetcher.DataCallback<in InputStream>) { |
|
|
|
|
|
|
|
val loadOnlyWifi = options.get(OkHttpModelLoader.loadOnlyWifiOption) ?: false |
|
|
|
|
|
|
|
if (loadOnlyWifi && !appCtx.isWifiConnect) { |
|
|
|
|
|
|
|
callback.onLoadFailed(NoStackTraceException("只在wifi加载图片")) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
val requestBuilder: Request.Builder = Request.Builder().url(url.toStringUrl()) |
|
|
|
val requestBuilder: Request.Builder = Request.Builder().url(url.toStringUrl()) |
|
|
|
for ((key, value) in url.headers.entries) { |
|
|
|
for ((key, value) in url.headers.entries) { |
|
|
|
requestBuilder.addHeader(key, value) |
|
|
|
requestBuilder.addHeader(key, value) |
|
|
|