pull/1391/head
gedoor 3 years ago
parent 8a38226823
commit 32335c9ee1
  1. 15
      app/src/main/java/io/legado/app/help/http/cronet/CronetHelper.kt
  2. 8
      app/src/main/java/io/legado/app/model/BookCover.kt

@ -1,6 +1,5 @@
package io.legado.app.help.http.cronet package io.legado.app.help.http.cronet
import android.util.Log
import com.google.android.gms.net.CronetProviderInstaller import com.google.android.gms.net.CronetProviderInstaller
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import okhttp3.Headers import okhttp3.Headers
@ -12,6 +11,7 @@ import org.chromium.net.ExperimentalCronetEngine
import org.chromium.net.UploadDataProviders import org.chromium.net.UploadDataProviders
import org.chromium.net.UrlRequest import org.chromium.net.UrlRequest
import splitties.init.appCtx import splitties.init.appCtx
import timber.log.Timber
import java.util.concurrent.ExecutorService import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors import java.util.concurrent.Executors
@ -24,8 +24,6 @@ val cronetEngine: ExperimentalCronetEngine by lazy {
} else { } else {
CronetLoader.preDownload() CronetLoader.preDownload()
} }
val builder = ExperimentalCronetEngine.Builder(appCtx).apply { val builder = ExperimentalCronetEngine.Builder(appCtx).apply {
if (!AppConfig.isGooglePlay && CronetLoader.install()) { if (!AppConfig.isGooglePlay && CronetLoader.install()) {
setLibraryLoader(CronetLoader)//设置自定义so库加载 setLibraryLoader(CronetLoader)//设置自定义so库加载
@ -35,12 +33,15 @@ val cronetEngine: ExperimentalCronetEngine by lazy {
enableQuic(true)//设置支持http/3 enableQuic(true)//设置支持http/3
enableHttp2(true) //设置支持http/2 enableHttp2(true) //设置支持http/2
enablePublicKeyPinningBypassForLocalTrustAnchors(true) enablePublicKeyPinningBypassForLocalTrustAnchors(true)
enableBrotli(true)//Brotli压缩 enableBrotli(true)//Brotli压缩
} }
val engine = builder.build() val engine = try {
Log.d("Cronet", "Cronet Version:" + engine.versionString) builder.build()
} catch (e: Exception) {
CronetLoader.preDownload()
builder.build()
}
Timber.d("Cronet Version:" + engine.versionString)
//这会导致Jsoup的网络请求出现问题,暂时不接管系统URL //这会导致Jsoup的网络请求出现问题,暂时不接管系统URL
//URL.setURLStreamHandlerFactory(CronetURLStreamHandlerFactory(engine)) //URL.setURLStreamHandlerFactory(CronetURLStreamHandlerFactory(engine))
return@lazy engine return@lazy engine

@ -42,8 +42,14 @@ object BookCover {
} }
val key = if (isNightTheme) PreferKey.defaultCoverDark else PreferKey.defaultCover val key = if (isNightTheme) PreferKey.defaultCoverDark else PreferKey.defaultCover
val path = appCtx.getPrefString(key) val path = appCtx.getPrefString(key)
defaultDrawable = Drawable.createFromPath(path) defaultDrawable = try {
Drawable.createFromPath(path)
?: appCtx.resources.getDrawable(R.drawable.image_cover_default, null) ?: appCtx.resources.getDrawable(R.drawable.image_cover_default, null)
} catch (e: OutOfMemoryError) {
appCtx.resources.getDrawable(R.drawable.image_cover_default, null)
} catch (e: Exception) {
appCtx.resources.getDrawable(R.drawable.image_cover_default, null)
}
} }
fun getBlurDefaultCover(context: Context): RequestBuilder<Drawable> { fun getBlurDefaultCover(context: Context): RequestBuilder<Drawable> {

Loading…
Cancel
Save