diff --git a/app/src/main/java/io/legado/app/help/http/cronet/CronetUrlRequestCallback.kt b/app/src/main/java/io/legado/app/help/http/cronet/CronetUrlRequestCallback.kt index 0e59ed7de..e9e0e4260 100644 --- a/app/src/main/java/io/legado/app/help/http/cronet/CronetUrlRequestCallback.kt +++ b/app/src/main/java/io/legado/app/help/http/cronet/CronetUrlRequestCallback.kt @@ -142,11 +142,12 @@ class CronetUrlRequestCallback @JvmOverloads internal constructor( companion object { private const val TAG = "Callback" private const val MAX_FOLLOW_COUNT = 20 + + @Suppress("DEPRECATION") private fun protocolFromNegotiatedProtocol(responseInfo: UrlResponseInfo): Protocol { val negotiatedProtocol = responseInfo.negotiatedProtocol.lowercase(Locale.getDefault()) // Log.e("Cronet", responseInfo.url) // Log.e("Cronet", negotiatedProtocol) - return when { negotiatedProtocol.contains("h3") -> { return Protocol.QUIC diff --git a/app/src/main/java/io/legado/app/help/storage/BookWebDav.kt b/app/src/main/java/io/legado/app/help/storage/BookWebDav.kt index cbdbd15ce..a194cf4e7 100644 --- a/app/src/main/java/io/legado/app/help/storage/BookWebDav.kt +++ b/app/src/main/java/io/legado/app/help/storage/BookWebDav.kt @@ -102,7 +102,7 @@ object BookWebDav { suspend fun backUpWebDav(path: String) { try { - if (initWebDav()) { + if (initWebDav() && NetworkUtils.isAvailable()) { val paths = arrayListOf(*Backup.backupFileNames) for (i in 0 until paths.size) { paths[i] = path + File.separator + paths[i] @@ -116,15 +116,13 @@ object BookWebDav { } } } catch (e: Exception) { - Handler(Looper.getMainLooper()).post { - appCtx.toastOnUi("WebDav\n${e.localizedMessage}") - } + appCtx.toastOnUi("WebDav\n${e.localizedMessage}") } } suspend fun exportWebDav(byteArray: ByteArray, fileName: String) { try { - if (initWebDav()) { + if (initWebDav() && NetworkUtils.isAvailable()) { // 默认导出到legado文件夹下exports目录 val exportsWebDavUrl = rootWebDavUrl + EncoderUtils.escape("exports") + "/" // 在legado文件夹创建exports目录,如果不存在的话 @@ -141,6 +139,7 @@ object BookWebDav { } fun uploadBookProgress(book: Book) { + if (!NetworkUtils.isAvailable()) return Coroutine.async { val bookProgress = BookProgress( name = book.name, @@ -159,7 +158,7 @@ object BookWebDav { } suspend fun getBookProgress(book: Book): BookProgress? { - if (initWebDav()) { + if (initWebDav() && NetworkUtils.isAvailable()) { val url = getProgressUrl(book) WebDav(url).download()?.let { byteArray -> val json = String(byteArray) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt index 2cfee12d0..7bc7186e4 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt @@ -16,10 +16,6 @@ import java.util.* @Keep class AnalyzeByJSoup(doc: Any) { companion object { - /** - * "class", "id", "tag", "text", "children" - */ - val validKeys = arrayOf("class", "id", "tag", "text", "children") fun parse(doc: Any): Element { return when (doc) { @@ -260,22 +256,16 @@ class AnalyzeByJSoup(doc: Any) { /** * 1.支持阅读原有写法,':'分隔索引,!或.表示筛选方式,索引可为负数 - * * 例如 tag.div.-1:10:2 或 tag.div!0:3 * * 2. 支持与jsonPath类似的[]索引写法 - * * 格式形如 [it,it,。。。] 或 [!it,it,。。。] 其中[!开头表示筛选方式为排除,it为单个索引或区间。 - * * 区间格式为 start:end 或 start:end:step,其中start为0可省略,end为-1可省略。 - * * 索引,区间两端及间隔都支持负数 - * * 例如 tag.div[-1, 3:-2:-10, 2] - * * 特殊用法 tag.div[-1:0] 可在任意地方让列表反向 - * * */ + @Suppress("UNCHECKED_CAST") data class ElementsSingle( var split: Char = '.', var beforeRule: String = "", @@ -322,7 +312,6 @@ class AnalyzeByJSoup(doc: Any) { } else for (ix in lastIndexs downTo 0) { //indexs不空,表明是[]式索引,集合是逆向遍历插入的,所以这里也逆向遍历,好还原顺序 if (indexs[ix] is Triple<*, *, *>) { //区间 - val (startx, endx, stepx) = indexs[ix] as Triple //还原储存时的类型 val start = if (startx == null) 0 //左端省略表示0 diff --git a/app/src/main/java/io/legado/app/utils/NetworkUtils.kt b/app/src/main/java/io/legado/app/utils/NetworkUtils.kt index 4bc22d456..74f573f38 100644 --- a/app/src/main/java/io/legado/app/utils/NetworkUtils.kt +++ b/app/src/main/java/io/legado/app/utils/NetworkUtils.kt @@ -1,5 +1,9 @@ package io.legado.app.utils +import android.net.ConnectivityManager +import android.net.NetworkCapabilities +import android.os.Build +import splitties.systemservices.connectivityManager import java.net.InetAddress import java.net.NetworkInterface import java.net.SocketException @@ -7,9 +11,40 @@ import java.net.URL import java.util.* import java.util.regex.Pattern + @Suppress("unused", "MemberVisibilityCanBePrivate") object NetworkUtils { + /** + * 判断是否联网 + */ + @Suppress("DEPRECATION") + fun isAvailable(): Boolean { + if (Build.VERSION.SDK_INT < 23) { + val mWiFiNetworkInfo = connectivityManager.activeNetworkInfo + if (mWiFiNetworkInfo != null) { + //移动数据 + return if (mWiFiNetworkInfo.type == ConnectivityManager.TYPE_WIFI) { + //WIFI + true + } else mWiFiNetworkInfo.type == ConnectivityManager.TYPE_MOBILE + } + } else { + val network = connectivityManager.activeNetwork + if (network != null) { + val nc = connectivityManager.getNetworkCapabilities(network) + if (nc != null) { + //移动数据 + return if (nc.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) { + //WIFI + true + } else nc.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) + } + } + } + return false + } + private val notNeedEncoding: BitSet by lazy { val bitSet = BitSet(256) for (i in 'a'.code..'z'.code) {