mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package io.legado.app.lib.cronet
|
||||
|
||||
import androidx.annotation.Keep
|
||||
import io.legado.app.help.http.cookieJar
|
||||
import io.legado.app.utils.printOnDebug
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||
@@ -16,7 +15,7 @@ import kotlin.coroutines.resumeWithException
|
||||
|
||||
@Keep
|
||||
@Suppress("unused")
|
||||
class CronetCoroutineInterceptor : Interceptor {
|
||||
class CronetCoroutineInterceptor(private val cookieJar: CookieJar) : Interceptor {
|
||||
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
if (chain.call().isCanceled()) {
|
||||
|
||||
@@ -2,7 +2,6 @@ package io.legado.app.lib.cronet
|
||||
|
||||
import android.os.Build
|
||||
import androidx.annotation.Keep
|
||||
import io.legado.app.help.http.cookieJar
|
||||
import io.legado.app.utils.printOnDebug
|
||||
import okhttp3.*
|
||||
import okhttp3.internal.http.receiveHeaders
|
||||
@@ -10,7 +9,7 @@ import java.io.IOException
|
||||
|
||||
@Keep
|
||||
@Suppress("unused")
|
||||
class CronetInterceptor : Interceptor {
|
||||
class CronetInterceptor(private val cookieJar: CookieJar) : Interceptor {
|
||||
|
||||
@Throws(IOException::class)
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
|
||||
@@ -9,7 +9,7 @@ import androidx.annotation.Keep
|
||||
import io.legado.app.BuildConfig
|
||||
import io.legado.app.constant.AppConst
|
||||
import io.legado.app.help.coroutine.Coroutine
|
||||
import io.legado.app.help.http.cronet.CronetLoaderInterface
|
||||
import io.legado.app.help.http.Cronet
|
||||
import io.legado.app.utils.DebugLog
|
||||
import io.legado.app.utils.printOnDebug
|
||||
|
||||
@@ -25,7 +25,7 @@ import java.security.MessageDigest
|
||||
import java.util.*
|
||||
|
||||
@Keep
|
||||
object CronetLoader : CronetEngine.Builder.LibraryLoader(), CronetLoaderInterface {
|
||||
object CronetLoader : CronetEngine.Builder.LibraryLoader(), Cronet.LoaderInterface {
|
||||
//https://storage.googleapis.com/chromium-cronet/android/92.0.4515.159/Release/cronet/libs/arm64-v8a/libcronet.92.0.4515.159.so
|
||||
|
||||
private const val soVersion = BuildConfig.Cronet_Version
|
||||
|
||||
@@ -24,7 +24,7 @@ import io.legado.app.help.book.BookHelp
|
||||
import io.legado.app.help.config.AppConfig
|
||||
import io.legado.app.help.config.ThemeConfig.applyDayNight
|
||||
import io.legado.app.help.coroutine.Coroutine
|
||||
import io.legado.app.help.http.cronet.Cronet
|
||||
import io.legado.app.help.http.Cronet
|
||||
import io.legado.app.model.BookCover
|
||||
import io.legado.app.utils.defaultSharedPreferences
|
||||
import io.legado.app.utils.getPrefBoolean
|
||||
|
||||
35
app/src/main/java/io/legado/app/help/http/Cronet.kt
Normal file
35
app/src/main/java/io/legado/app/help/http/Cronet.kt
Normal file
@@ -0,0 +1,35 @@
|
||||
package io.legado.app.help.http
|
||||
|
||||
import okhttp3.CookieJar
|
||||
import okhttp3.Interceptor
|
||||
|
||||
object Cronet {
|
||||
|
||||
val loader: LoaderInterface? by lazy {
|
||||
kotlin.runCatching {
|
||||
Class.forName("io.legado.app.lib.cronet.CronetLoader")
|
||||
.kotlin.objectInstance as LoaderInterface
|
||||
}.getOrNull()
|
||||
}
|
||||
|
||||
fun preDownload() {
|
||||
loader?.preDownload()
|
||||
}
|
||||
|
||||
val interceptor: Interceptor? by lazy {
|
||||
kotlin.runCatching {
|
||||
val iClass = Class.forName("io.legado.app.lib.cronet.CronetInterceptor")
|
||||
iClass.getDeclaredConstructor(CookieJar::class.java)
|
||||
.newInstance(cookieJar) as Interceptor
|
||||
}.getOrNull()
|
||||
}
|
||||
|
||||
interface LoaderInterface {
|
||||
|
||||
fun install(): Boolean
|
||||
|
||||
fun preDownload()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package io.legado.app.help.http
|
||||
import io.legado.app.constant.AppConst
|
||||
import io.legado.app.help.CacheManager
|
||||
import io.legado.app.help.config.AppConfig
|
||||
import io.legado.app.help.http.cronet.Cronet
|
||||
import io.legado.app.utils.NetworkUtils
|
||||
import okhttp3.*
|
||||
import java.net.InetSocketAddress
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
package io.legado.app.help.http.cronet
|
||||
|
||||
import okhttp3.Interceptor
|
||||
|
||||
object Cronet {
|
||||
|
||||
val loader: CronetLoaderInterface? by lazy {
|
||||
kotlin.runCatching {
|
||||
Class.forName("io.legado.app.lib.cronet.CronetLoader")
|
||||
.kotlin.objectInstance as CronetLoaderInterface
|
||||
}.getOrNull()
|
||||
}
|
||||
|
||||
fun preDownload() {
|
||||
loader?.preDownload()
|
||||
}
|
||||
|
||||
val interceptor: Interceptor? by lazy {
|
||||
kotlin.runCatching {
|
||||
Class.forName("io.legado.app.lib.cronet.CronetInterceptor")
|
||||
.newInstance() as Interceptor
|
||||
}.getOrNull()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package io.legado.app.help.http.cronet
|
||||
|
||||
interface CronetLoaderInterface {
|
||||
|
||||
fun install(): Boolean
|
||||
|
||||
fun preDownload()
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user