feat: 优化代码

pull/198/head
kunfei 5 years ago
parent 7ff4f0cb12
commit 05debdcfae
  1. 7
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt
  2. 3
      app/src/main/java/io/legado/app/ui/filechooser/utils/ConvertUtils.kt
  3. 6
      app/src/main/java/io/legado/app/utils/NetworkUtils.kt

@ -13,9 +13,8 @@ import io.legado.app.help.http.api.HttpGetApi
import io.legado.app.help.http.api.HttpPostApi
import io.legado.app.utils.*
import okhttp3.FormBody
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.MediaType
import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.toRequestBody
import retrofit2.Call
import java.net.URLEncoder
import java.util.*
@ -40,7 +39,7 @@ class AnalyzeUrl(
) : JsExtensions {
companion object {
private val pagePattern = Pattern.compile("<(.*?)>")
private val jsonType = "application/json; charset=utf-8".toMediaTypeOrNull()
private val jsonType = MediaType.parse("application/json; charset=utf-8")
}
private var baseUrl: String = ""
@ -182,7 +181,7 @@ class AnalyzeUrl(
RequestMethod.POST -> {
bodyTxt?.let {
if (it.isJson()) {
body = it.toRequestBody(jsonType)
body = RequestBody.create(jsonType, it)
} else {
analyzeFields(it)
}

@ -5,7 +5,6 @@ import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import okhttp3.internal.and
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStream
@ -36,7 +35,7 @@ object ConvertUtils {
var abyte: Byte
for (i in bytes.indices) {
abyte = bytes[i]
result += abyte and 0xFF shl 8 * i
result += (abyte.toInt() and 0xFF).shl(8 * i)
}
return result
}

@ -11,9 +11,9 @@ import java.util.regex.Pattern
@Suppress("unused")
object NetworkUtils {
fun getUrl(response: Response<*>): String {
val networkResponse = response.raw().networkResponse
return networkResponse?.request?.url?.toString()
?: response.raw().request.url.toString()
val networkResponse = response.raw().networkResponse()
return networkResponse?.request()?.url()?.toString()
?: response.raw().request().url().toString()
}
private val notNeedEncoding: BitSet by lazy {

Loading…
Cancel
Save