pull/1202/head
gedoor 3 years ago
parent 6118ec4214
commit ad71cfac7a
  1. 3
      app/src/main/java/io/legado/app/help/http/cronet/CronetUrlRequestCallback.kt
  2. 9
      app/src/main/java/io/legado/app/help/storage/BookWebDav.kt
  3. 13
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt
  4. 35
      app/src/main/java/io/legado/app/utils/NetworkUtils.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

@ -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}")
}
}
}
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)

@ -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<Int?, Int?, Int> //还原储存时的类型
val start = if (startx == null) 0 //左端省略表示0

@ -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) {

Loading…
Cancel
Save