From 2721e75ecc7c702eeb46e82c27208a721cfba6e2 Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 14 Dec 2020 17:04:16 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/help/http/AjaxWebView.kt | 4 +- .../io/legado/app/help/http/HttpHelper.kt | 2 +- .../io/legado/app/help/http/StrResponse.kt | 106 +++++------------- .../app/help/http/parser/StrResponseParser.kt | 5 +- .../app/model/analyzeRule/AnalyzeUrl.kt | 2 +- 5 files changed, 32 insertions(+), 87 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/http/AjaxWebView.kt b/app/src/main/java/io/legado/app/help/http/AjaxWebView.kt index c14423c8b..b57409671 100644 --- a/app/src/main/java/io/legado/app/help/http/AjaxWebView.kt +++ b/app/src/main/java/io/legado/app/help/http/AjaxWebView.kt @@ -160,7 +160,7 @@ class AjaxWebView { if (it.isNotEmpty() && it != "null") { val content = StringEscapeUtils.unescapeJson(it) .replace("^\"|\"$".toRegex(), "") - handler.obtainMessage(MSG_SUCCESS, StrResponse.success(content, url)) + handler.obtainMessage(MSG_SUCCESS, StrResponse(url, content)) .sendToTarget() handler.removeCallbacks(this) return@evaluateJavascript @@ -188,7 +188,7 @@ class AjaxWebView { if (url.matches(it.toRegex())) { handler.obtainMessage( MSG_SUCCESS, - StrResponse.success(url, view.url ?: params.url) + StrResponse(view.url ?: params.url, url) ).sendToTarget() } } diff --git a/app/src/main/java/io/legado/app/help/http/HttpHelper.kt b/app/src/main/java/io/legado/app/help/http/HttpHelper.kt index 0b83c0616..31e8dfecf 100644 --- a/app/src/main/java/io/legado/app/help/http/HttpHelper.kt +++ b/app/src/main/java/io/legado/app/help/http/HttpHelper.kt @@ -111,7 +111,7 @@ object HttpHelper { override fun onError(error: Throwable) { if (!block.isCompleted) - block.resume(StrResponse.success(error.msg, params.url)) + block.resume(StrResponse(params.url, error.msg)) } } webView.load(params) diff --git a/app/src/main/java/io/legado/app/help/http/StrResponse.kt b/app/src/main/java/io/legado/app/help/http/StrResponse.kt index 19255c47e..c7ccad9a1 100644 --- a/app/src/main/java/io/legado/app/help/http/StrResponse.kt +++ b/app/src/main/java/io/legado/app/help/http/StrResponse.kt @@ -2,17 +2,36 @@ package io.legado.app.help.http import okhttp3.* import okhttp3.Response.Builder -import java.util.* /** * An HTTP response. */ @Suppress("unused", "MemberVisibilityCanBePrivate") -class StrResponse private constructor( - val rawResponse: Response, - val body: String?, - val errorBody: ResponseBody? -) { +class StrResponse { + var rawResponse: Response + var body: String? = null + var errorBody: ResponseBody? = null + + constructor(rawResponse: Response, body: String?) { + this.rawResponse = rawResponse + this.body = body + } + + constructor(url: String, body: String?) { + rawResponse = Builder() + .code(200) + .message("OK") + .protocol(Protocol.HTTP_1_1) + .request(Request.Builder().url(url).build()) + .build() + this.body = body + } + + constructor(rawResponse: Response, errorBody: ResponseBody?) { + this.rawResponse = rawResponse + this.errorBody = errorBody + } + fun raw() = rawResponse fun url(): String { @@ -44,79 +63,4 @@ class StrResponse private constructor( return rawResponse.toString() } - companion object { - fun success(code: Int, body: String): StrResponse { - require(!(code < 200 || code >= 300)) { "code < 200 or >= 300: $code" } - return success( - body, - Builder() // - .code(code) - .message("Response.success()") - .protocol(Protocol.HTTP_1_1) - .request(Request.Builder().url("http://localhost/").build()) - .build() - ) - } - - fun success(body: String, headers: Headers): StrResponse { - return success( - body, - Builder() // - .code(200) - .message("OK") - .protocol(Protocol.HTTP_1_1) - .headers(headers) - .request(Request.Builder().url("http://localhost/").build()) - .build() - ) - } - - fun success(body: String, url: String): StrResponse { - return success( - body, - Builder() // - .code(200) - .message("OK") - .protocol(Protocol.HTTP_1_1) - .request(Request.Builder().url(url).build()) - .build() - ) - } - - @JvmOverloads - fun success( - body: String?, rawResponse: Response = - Builder() // - .code(200) - .message("OK") - .protocol(Protocol.HTTP_1_1) - .request(Request.Builder().url("http://localhost/").build()) - .build() - ): StrResponse { - Objects.requireNonNull(rawResponse, "rawResponse == null") - require(rawResponse.isSuccessful) { "rawResponse must be successful response" } - return StrResponse(rawResponse, body, null) - } - - fun error(code: Int, body: ResponseBody?): StrResponse { - Objects.requireNonNull(body, "body == null") - require(code >= 400) { "code < 400: $code" } - return error( - body, - Builder() // - .code(code) - .message("Response.error()") - .protocol(Protocol.HTTP_1_1) - .request(Request.Builder().url("http://localhost/").build()) - .build() - ) - } - - fun error(body: ResponseBody?, rawResponse: Response): StrResponse { - Objects.requireNonNull(body, "body == null") - Objects.requireNonNull(rawResponse, "rawResponse == null") - require(!rawResponse.isSuccessful) { "rawResponse should not be successful response" } - return StrResponse(rawResponse, null, body) - } - } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/http/parser/StrResponseParser.kt b/app/src/main/java/io/legado/app/help/http/parser/StrResponseParser.kt index 53ead9d26..9868b9dc8 100644 --- a/app/src/main/java/io/legado/app/help/http/parser/StrResponseParser.kt +++ b/app/src/main/java/io/legado/app/help/http/parser/StrResponseParser.kt @@ -9,11 +9,12 @@ import rxhttp.wrapper.exception.HttpStatusCodeException import java.nio.charset.Charset @Parser(name = "StrResponse") -class StrResponseParser(val encode: String? = null) : rxhttp.wrapper.parse.Parser { +class StrResponseParser(private val encode: String? = null) : + rxhttp.wrapper.parse.Parser { override fun onParse(response: Response): StrResponse { val body = getString(response) - return StrResponse.success(body, response) + return StrResponse(response, body) } private fun getString(response: Response): String { diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt index 00b2e4b95..9991a49f5 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt @@ -280,7 +280,7 @@ class AnalyzeUrl( sourceRegex: String? = null, ): StrResponse { if (type != null) { - return StrResponse.success(StringUtils.byteToHexString(getByteArray(tag)), url) + return StrResponse(url, StringUtils.byteToHexString(getByteArray(tag))) } setCookie(tag) if (useWebView) { From 9527f73f511fb1aff846805d672d42b086b9afd6 Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 14 Dec 2020 17:11:04 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 1 + .../io/legado/app/help/http/StrResponse.kt | 31 ++++++++++++------- .../io/legado/app/model/webBook/WebBook.kt | 4 +-- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 751f4906d..79223d416 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -6,6 +6,7 @@ **2020/12/14** * 修复bug * 电池图标不允许改字体 +* 升级js库 **2020/12/13** * 修复bug diff --git a/app/src/main/java/io/legado/app/help/http/StrResponse.kt b/app/src/main/java/io/legado/app/help/http/StrResponse.kt index c7ccad9a1..1b1f53395 100644 --- a/app/src/main/java/io/legado/app/help/http/StrResponse.kt +++ b/app/src/main/java/io/legado/app/help/http/StrResponse.kt @@ -8,17 +8,20 @@ import okhttp3.Response.Builder */ @Suppress("unused", "MemberVisibilityCanBePrivate") class StrResponse { - var rawResponse: Response + var raw: Response + private set var body: String? = null + private set var errorBody: ResponseBody? = null + private set constructor(rawResponse: Response, body: String?) { - this.rawResponse = rawResponse + this.raw = rawResponse this.body = body } constructor(url: String, body: String?) { - rawResponse = Builder() + raw = Builder() .code(200) .message("OK") .protocol(Protocol.HTTP_1_1) @@ -28,39 +31,43 @@ class StrResponse { } constructor(rawResponse: Response, errorBody: ResponseBody?) { - this.rawResponse = rawResponse + this.raw = rawResponse this.errorBody = errorBody } - fun raw() = rawResponse + fun raw() = raw fun url(): String { - rawResponse.networkResponse?.let { + raw.networkResponse?.let { 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 { - return rawResponse.code + return raw.code } fun message(): String { - return rawResponse.message + return raw.message } fun headers(): Headers { - return rawResponse.headers + return raw.headers } - fun isSuccessful(): Boolean = rawResponse.isSuccessful + fun isSuccessful(): Boolean = raw.isSuccessful fun errorBody(): ResponseBody? { return errorBody } override fun toString(): String { - return rawResponse.toString() + return raw.toString() } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/model/webBook/WebBook.kt b/app/src/main/java/io/legado/app/model/webBook/WebBook.kt index 7b2235aab..7a1c29a05 100644 --- a/app/src/main/java/io/legado/app/model/webBook/WebBook.kt +++ b/app/src/main/java/io/legado/app/model/webBook/WebBook.kt @@ -52,7 +52,7 @@ class WebBook(val bookSource: BookSource) { res.body, bookSource, analyzeUrl, - res.url(), + res.url, variableBook, true ) @@ -83,7 +83,7 @@ class WebBook(val bookSource: BookSource) { res.body, bookSource, analyzeUrl, - res.url(), + res.url, variableBook, false ) From 5b1ac7703ebb9cf12d7d24dac6252530bb812626 Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 14 Dec 2020 17:51:46 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt | 1 + .../io/legado/app/ui/book/read/page/delegate/PageDelegate.kt | 1 + 2 files changed, 2 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt index 716a0bd88..409b57129 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt @@ -547,5 +547,6 @@ class ReadView(context: Context, attrs: AttributeSet) : fun showActionMenu() fun screenOffTimerStart() fun showTextActionMenu() + fun autoPageStop() } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt index 2f1d70c8d..a70961487 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt @@ -173,6 +173,7 @@ abstract class PageDelegate(protected val readView: ReadView) { fun hasNext(): Boolean { val hasNext = readView.pageFactory.hasNext() if (!hasNext) { + readView.callBack.autoPageStop() if (!snackBar.isShown) { snackBar.setText(R.string.no_next_page) snackBar.show() From 23acdff42e902074708857dec0c20d3bc1fb5e14 Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 14 Dec 2020 17:55:13 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/book/read/ReadBookActivity.kt | 4 +++- .../main/java/io/legado/app/ui/book/read/page/ReadView.kt | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 8d3481550..dfdee0a86 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -611,7 +611,9 @@ class ReadBookActivity : ReadBookBaseActivity(), autoPageProgress += scrollOffset if (autoPageProgress >= binding.readView.height) { autoPageProgress = 0 - binding.readView.fillPage(PageDirection.NEXT) + if (!binding.readView.fillPage(PageDirection.NEXT)) { + autoPageStop() + } } else { binding.readView.invalidate() } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt index 409b57129..fb91611af 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt @@ -437,15 +437,15 @@ class ReadView(context: Context, attrs: AttributeSet) : curPage.cancelSelect() } - fun fillPage(direction: PageDirection) { - when (direction) { + fun fillPage(direction: PageDirection): Boolean { + return when (direction) { PageDirection.PREV -> { pageFactory.moveToPrev(true) } PageDirection.NEXT -> { pageFactory.moveToNext(true) } - else -> Unit + else -> false } }