pull/737/head
Robot 4 years ago
commit f025723129
  1. 1
      app/src/main/assets/updateLog.md
  2. 4
      app/src/main/java/io/legado/app/help/http/AjaxWebView.kt
  3. 2
      app/src/main/java/io/legado/app/help/http/HttpHelper.kt
  4. 129
      app/src/main/java/io/legado/app/help/http/StrResponse.kt
  5. 5
      app/src/main/java/io/legado/app/help/http/parser/StrResponseParser.kt
  6. 2
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt
  7. 4
      app/src/main/java/io/legado/app/model/webBook/WebBook.kt
  8. 4
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  9. 7
      app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt
  10. 1
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt

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

@ -160,7 +160,7 @@ class AjaxWebView {
if (it.isNotEmpty() && it != "null") { if (it.isNotEmpty() && it != "null") {
val content = StringEscapeUtils.unescapeJson(it) val content = StringEscapeUtils.unescapeJson(it)
.replace("^\"|\"$".toRegex(), "") .replace("^\"|\"$".toRegex(), "")
handler.obtainMessage(MSG_SUCCESS, StrResponse.success(content, url)) handler.obtainMessage(MSG_SUCCESS, StrResponse(url, content))
.sendToTarget() .sendToTarget()
handler.removeCallbacks(this) handler.removeCallbacks(this)
return@evaluateJavascript return@evaluateJavascript
@ -188,7 +188,7 @@ class AjaxWebView {
if (url.matches(it.toRegex())) { if (url.matches(it.toRegex())) {
handler.obtainMessage( handler.obtainMessage(
MSG_SUCCESS, MSG_SUCCESS,
StrResponse.success(url, view.url ?: params.url) StrResponse(view.url ?: params.url, url)
).sendToTarget() ).sendToTarget()
} }
} }

@ -111,7 +111,7 @@ object HttpHelper {
override fun onError(error: Throwable) { override fun onError(error: Throwable) {
if (!block.isCompleted) if (!block.isCompleted)
block.resume(StrResponse.success(error.msg, params.url)) block.resume(StrResponse(params.url, error.msg))
} }
} }
webView.load(params) webView.load(params)

@ -2,121 +2,72 @@ package io.legado.app.help.http
import okhttp3.* import okhttp3.*
import okhttp3.Response.Builder import okhttp3.Response.Builder
import java.util.*
/** /**
* An HTTP response. * An HTTP response.
*/ */
@Suppress("unused", "MemberVisibilityCanBePrivate") @Suppress("unused", "MemberVisibilityCanBePrivate")
class StrResponse private constructor( class StrResponse {
val rawResponse: Response, var raw: Response
val body: String?, private set
val errorBody: ResponseBody? var body: String? = null
) { private set
fun raw() = rawResponse var errorBody: ResponseBody? = null
private set
constructor(rawResponse: Response, body: String?) {
this.raw = rawResponse
this.body = body
}
constructor(url: String, body: String?) {
raw = 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.raw = rawResponse
this.errorBody = errorBody
}
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()
} }
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)
}
}
} }

@ -9,11 +9,12 @@ import rxhttp.wrapper.exception.HttpStatusCodeException
import java.nio.charset.Charset import java.nio.charset.Charset
@Parser(name = "StrResponse") @Parser(name = "StrResponse")
class StrResponseParser(val encode: String? = null) : rxhttp.wrapper.parse.Parser<StrResponse> { class StrResponseParser(private val encode: String? = null) :
rxhttp.wrapper.parse.Parser<StrResponse> {
override fun onParse(response: Response): StrResponse { override fun onParse(response: Response): StrResponse {
val body = getString(response) val body = getString(response)
return StrResponse.success(body, response) return StrResponse(response, body)
} }
private fun getString(response: Response): String { private fun getString(response: Response): String {

@ -280,7 +280,7 @@ class AnalyzeUrl(
sourceRegex: String? = null, sourceRegex: String? = null,
): StrResponse { ): StrResponse {
if (type != null) { if (type != null) {
return StrResponse.success(StringUtils.byteToHexString(getByteArray(tag)), url) return StrResponse(url, StringUtils.byteToHexString(getByteArray(tag)))
} }
setCookie(tag) setCookie(tag)
if (useWebView) { if (useWebView) {

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

@ -611,7 +611,9 @@ class ReadBookActivity : ReadBookBaseActivity(),
autoPageProgress += scrollOffset autoPageProgress += scrollOffset
if (autoPageProgress >= binding.readView.height) { if (autoPageProgress >= binding.readView.height) {
autoPageProgress = 0 autoPageProgress = 0
binding.readView.fillPage(PageDirection.NEXT) if (!binding.readView.fillPage(PageDirection.NEXT)) {
autoPageStop()
}
} else { } else {
binding.readView.invalidate() binding.readView.invalidate()
} }

@ -437,15 +437,15 @@ class ReadView(context: Context, attrs: AttributeSet) :
curPage.cancelSelect() curPage.cancelSelect()
} }
fun fillPage(direction: PageDirection) { fun fillPage(direction: PageDirection): Boolean {
when (direction) { return when (direction) {
PageDirection.PREV -> { PageDirection.PREV -> {
pageFactory.moveToPrev(true) pageFactory.moveToPrev(true)
} }
PageDirection.NEXT -> { PageDirection.NEXT -> {
pageFactory.moveToNext(true) pageFactory.moveToNext(true)
} }
else -> Unit else -> false
} }
} }
@ -547,5 +547,6 @@ class ReadView(context: Context, attrs: AttributeSet) :
fun showActionMenu() fun showActionMenu()
fun screenOffTimerStart() fun screenOffTimerStart()
fun showTextActionMenu() fun showTextActionMenu()
fun autoPageStop()
} }
} }

@ -173,6 +173,7 @@ abstract class PageDelegate(protected val readView: ReadView) {
fun hasNext(): Boolean { fun hasNext(): Boolean {
val hasNext = readView.pageFactory.hasNext() val hasNext = readView.pageFactory.hasNext()
if (!hasNext) { if (!hasNext) {
readView.callBack.autoPageStop()
if (!snackBar.isShown) { if (!snackBar.isShown) {
snackBar.setText(R.string.no_next_page) snackBar.setText(R.string.no_next_page)
snackBar.show() snackBar.show()

Loading…
Cancel
Save