优化代码

pull/736/head 3.20.121417
gedoor 4 years ago
parent 2721e75ecc
commit 9527f73f51
  1. 1
      app/src/main/assets/updateLog.md
  2. 31
      app/src/main/java/io/legado/app/help/http/StrResponse.kt
  3. 4
      app/src/main/java/io/legado/app/model/webBook/WebBook.kt

@ -6,6 +6,7 @@
**2020/12/14** **2020/12/14**
* 修复bug * 修复bug
* 电池图标不允许改字体 * 电池图标不允许改字体
* 升级js库
**2020/12/13** **2020/12/13**
* 修复bug * 修复bug

@ -8,17 +8,20 @@ import okhttp3.Response.Builder
*/ */
@Suppress("unused", "MemberVisibilityCanBePrivate") @Suppress("unused", "MemberVisibilityCanBePrivate")
class StrResponse { class StrResponse {
var rawResponse: Response var raw: Response
private set
var body: String? = null var body: String? = null
private set
var errorBody: ResponseBody? = null var errorBody: ResponseBody? = null
private set
constructor(rawResponse: Response, body: String?) { constructor(rawResponse: Response, body: String?) {
this.rawResponse = rawResponse this.raw = rawResponse
this.body = body this.body = body
} }
constructor(url: String, body: String?) { constructor(url: String, body: String?) {
rawResponse = Builder() raw = Builder()
.code(200) .code(200)
.message("OK") .message("OK")
.protocol(Protocol.HTTP_1_1) .protocol(Protocol.HTTP_1_1)
@ -28,39 +31,43 @@ class StrResponse {
} }
constructor(rawResponse: Response, errorBody: ResponseBody?) { constructor(rawResponse: Response, errorBody: ResponseBody?) {
this.rawResponse = rawResponse this.raw = rawResponse
this.errorBody = errorBody this.errorBody = errorBody
} }
fun raw() = rawResponse fun raw() = raw
fun url(): String { fun url(): String {
rawResponse.networkResponse?.let { raw.networkResponse?.let {
return it.request.url.toString() return it.request.url.toString()
} }
return rawResponse.request.url.toString() return raw.request.url.toString()
} }
val url: String get() = url()
fun body() = body
fun code(): Int { fun code(): Int {
return rawResponse.code return raw.code
} }
fun message(): String { fun message(): String {
return rawResponse.message return raw.message
} }
fun headers(): Headers { fun headers(): Headers {
return rawResponse.headers return raw.headers
} }
fun isSuccessful(): Boolean = rawResponse.isSuccessful fun isSuccessful(): Boolean = raw.isSuccessful
fun errorBody(): ResponseBody? { fun errorBody(): ResponseBody? {
return errorBody return errorBody
} }
override fun toString(): String { override fun toString(): String {
return rawResponse.toString() return raw.toString()
} }
} }

@ -52,7 +52,7 @@ class WebBook(val bookSource: BookSource) {
res.body, res.body,
bookSource, bookSource,
analyzeUrl, analyzeUrl,
res.url(), res.url,
variableBook, variableBook,
true true
) )
@ -83,7 +83,7 @@ class WebBook(val bookSource: BookSource) {
res.body, res.body,
bookSource, bookSource,
analyzeUrl, analyzeUrl,
res.url(), res.url,
variableBook, variableBook,
false false
) )

Loading…
Cancel
Save