From f4f7c7063ecb64fbd49640084c5c32e40821b348 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 5 Sep 2022 17:05:00 +0800 Subject: [PATCH 01/11] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/api/controller/BookController.kt | 2 +- .../java/io/legado/app/help/ContentProcessor.kt | 4 ++-- .../main/java/io/legado/app/help/CrashHandler.kt | 4 ++-- .../main/java/io/legado/app/help/JsExtensions.kt | 13 +++++-------- app/src/main/java/io/legado/app/model/Debug.kt | 16 ++++++++-------- .../main/java/io/legado/app/model/ReadBook.kt | 4 ++-- .../legado/app/model/analyzeRule/AnalyzeRule.kt | 2 +- .../app/ui/book/explore/ExploreShowViewModel.kt | 4 ++-- .../legado/app/ui/book/read/ReadBookViewModel.kt | 5 +++-- .../ui/book/read/config/BgTextConfigDialog.kt | 2 +- .../ui/book/source/manage/BookSourceViewModel.kt | 2 +- .../ui/rss/source/edit/RssSourceEditViewModel.kt | 4 ++-- .../ui/rss/source/manage/RssSourceViewModel.kt | 2 +- .../io/legado/app/utils/ContextExtensions.kt | 2 +- .../io/legado/app/utils/ThrowableExtensions.kt | 2 +- 15 files changed, 33 insertions(+), 35 deletions(-) diff --git a/app/src/main/java/io/legado/app/api/controller/BookController.kt b/app/src/main/java/io/legado/app/api/controller/BookController.kt index d37a43aac..71636242e 100644 --- a/app/src/main/java/io/legado/app/api/controller/BookController.kt +++ b/app/src/main/java/io/legado/app/api/controller/BookController.kt @@ -188,7 +188,7 @@ object BookController { } returnData.setData(content) } catch (e: Exception) { - returnData.setErrorMsg(e.msg) + returnData.setErrorMsg(e.stackTraceStr) } return returnData } diff --git a/app/src/main/java/io/legado/app/help/ContentProcessor.kt b/app/src/main/java/io/legado/app/help/ContentProcessor.kt index 0fc46dd1a..a8db44beb 100644 --- a/app/src/main/java/io/legado/app/help/ContentProcessor.kt +++ b/app/src/main/java/io/legado/app/help/ContentProcessor.kt @@ -9,8 +9,8 @@ import io.legado.app.data.entities.ReplaceRule import io.legado.app.exception.RegexTimeoutException import io.legado.app.help.config.AppConfig import io.legado.app.help.config.ReadBookConfig -import io.legado.app.utils.msg import io.legado.app.utils.replace +import io.legado.app.utils.stackTraceStr import io.legado.app.utils.toastOnUi import kotlinx.coroutines.CancellationException import splitties.init.appCtx @@ -149,7 +149,7 @@ class ContentProcessor private constructor( } catch (e: RegexTimeoutException) { item.isEnabled = false appDb.replaceRuleDao.update(item) - return item.name + e.msg + return item.name + e.stackTraceStr } catch (e: CancellationException) { return mContent } catch (e: Exception) { diff --git a/app/src/main/java/io/legado/app/help/CrashHandler.kt b/app/src/main/java/io/legado/app/help/CrashHandler.kt index a13c38161..0de9105a7 100644 --- a/app/src/main/java/io/legado/app/help/CrashHandler.kt +++ b/app/src/main/java/io/legado/app/help/CrashHandler.kt @@ -8,7 +8,7 @@ import io.legado.app.model.ReadAloud import io.legado.app.utils.FileUtils import io.legado.app.utils.getFile import io.legado.app.utils.longToastOnUi -import io.legado.app.utils.msg +import io.legado.app.utils.stackTraceStr import splitties.init.appCtx import java.io.PrintWriter import java.io.StringWriter @@ -48,7 +48,7 @@ class CrashHandler(val context: Context) : Thread.UncaughtExceptionHandler { if (ex == null) return //保存日志文件 saveCrashInfo2File(ex) - context.longToastOnUi(ex.msg) + context.longToastOnUi(ex.stackTraceStr) Thread.sleep(3000) } diff --git a/app/src/main/java/io/legado/app/help/JsExtensions.kt b/app/src/main/java/io/legado/app/help/JsExtensions.kt index c9a1aae89..8280c8e6b 100644 --- a/app/src/main/java/io/legado/app/help/JsExtensions.kt +++ b/app/src/main/java/io/legado/app/help/JsExtensions.kt @@ -56,9 +56,8 @@ interface JsExtensions { analyzeUrl.getStrResponseAwait().body }.onFailure { AppLog.put("ajax(${urlStr}) error\n${it.localizedMessage}", it) - it.printOnDebug() }.getOrElse { - it.msg + it.stackTraceStr } } } @@ -91,10 +90,9 @@ interface JsExtensions { kotlin.runCatching { analyzeUrl.getStrResponseAwait() }.onFailure { - log("connect(${urlStr}) error\n${it.stackTraceToString()}") - it.printOnDebug() + AppLog.put("connect(${urlStr}) error\n${it.localizedMessage}", it) }.getOrElse { - StrResponse(analyzeUrl.url, it.localizedMessage) + StrResponse(analyzeUrl.url, it.stackTraceStr) } } } @@ -106,10 +104,9 @@ interface JsExtensions { kotlin.runCatching { analyzeUrl.getStrResponseAwait() }.onFailure { - log("ajax($urlStr,$header) error\n${it.stackTraceToString()}") - it.printOnDebug() + AppLog.put("ajax($urlStr,$header) error\n${it.localizedMessage}", it) }.getOrElse { - StrResponse(analyzeUrl.url, it.localizedMessage) + StrResponse(analyzeUrl.url, it.stackTraceStr) } } } diff --git a/app/src/main/java/io/legado/app/model/Debug.kt b/app/src/main/java/io/legado/app/model/Debug.kt index 8cab89c29..30b427788 100644 --- a/app/src/main/java/io/legado/app/model/Debug.kt +++ b/app/src/main/java/io/legado/app/model/Debug.kt @@ -9,7 +9,7 @@ import io.legado.app.model.rss.Rss import io.legado.app.model.webBook.WebBook import io.legado.app.utils.HtmlFormatter import io.legado.app.utils.isAbsUrl -import io.legado.app.utils.msg +import io.legado.app.utils.stackTraceStr import kotlinx.coroutines.CoroutineScope import java.text.SimpleDateFormat import java.util.* @@ -128,7 +128,7 @@ object Debug { } } .onError { - log(debugSource, it.msg, state = -1) + log(debugSource, it.stackTraceStr, state = -1) } } @@ -145,7 +145,7 @@ object Debug { log(debugSource, "︽内容页解析完成", state = 1000) } .onError { - log(debugSource, it.msg, state = -1) + log(debugSource, it.stackTraceStr, state = -1) } } @@ -204,7 +204,7 @@ object Debug { } } .onError { - log(debugSource, it.msg, state = -1) + log(debugSource, it.stackTraceStr, state = -1) } tasks.add(explore) } @@ -222,7 +222,7 @@ object Debug { } } .onError { - log(debugSource, it.msg, state = -1) + log(debugSource, it.stackTraceStr, state = -1) } tasks.add(search) } @@ -246,7 +246,7 @@ object Debug { } } .onError { - log(debugSource, it.msg, state = -1) + log(debugSource, it.stackTraceStr, state = -1) } tasks.add(info) } @@ -261,7 +261,7 @@ object Debug { contentDebug(scope, bookSource, book, it.first(), nextChapterUrl) } .onError { - log(debugSource, it.msg, state = -1) + log(debugSource, it.stackTraceStr, state = -1) } tasks.add(chapterList) } @@ -284,7 +284,7 @@ object Debug { ).onSuccess { log(debugSource, "︽正文页解析完成", state = 1000) }.onError { - log(debugSource, it.msg, state = -1) + log(debugSource, it.stackTraceStr, state = -1) } tasks.add(content) } diff --git a/app/src/main/java/io/legado/app/model/ReadBook.kt b/app/src/main/java/io/legado/app/model/ReadBook.kt index 7f9f6d1df..d1e4a1a43 100644 --- a/app/src/main/java/io/legado/app/model/ReadBook.kt +++ b/app/src/main/java/io/legado/app/model/ReadBook.kt @@ -14,7 +14,7 @@ import io.legado.app.model.webBook.WebBook import io.legado.app.service.BaseReadAloudService import io.legado.app.ui.book.read.page.entities.TextChapter import io.legado.app.ui.book.read.page.provider.ChapterProvider -import io.legado.app.utils.msg +import io.legado.app.utils.stackTraceStr import io.legado.app.utils.toastOnUi import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers.IO @@ -387,7 +387,7 @@ object ReadBook : CoroutineScope by MainScope() { } }.onError { AppLog.put("ChapterProvider ERROR", it) - appCtx.toastOnUi("ChapterProvider ERROR:\n${it.msg}") + appCtx.toastOnUi("ChapterProvider ERROR:\n${it.stackTraceStr}") }.onSuccess { success?.invoke() } diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt index 1be49d990..a7588e903 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt @@ -667,7 +667,7 @@ class AnalyzeRule( log("ajax(${urlStr}) error\n${it.stackTraceToString()}") it.printOnDebug() }.getOrElse { - it.msg + it.stackTraceStr } } } diff --git a/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowViewModel.kt b/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowViewModel.kt index 1ae0e2c61..067047f7c 100644 --- a/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowViewModel.kt @@ -9,8 +9,8 @@ import io.legado.app.data.appDb import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.SearchBook import io.legado.app.model.webBook.WebBook -import io.legado.app.utils.msg import io.legado.app.utils.printOnDebug +import io.legado.app.utils.stackTraceStr import kotlinx.coroutines.Dispatchers.IO @@ -46,7 +46,7 @@ class ExploreShowViewModel(application: Application) : BaseViewModel(application page++ }.onError { it.printOnDebug() - errorLiveData.postValue(it.msg) + errorLiveData.postValue(it.stackTraceStr) } } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt index d04486ac3..2aa416e4b 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt @@ -254,11 +254,12 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { return@execute } } - throw NoStackTraceException("自动换源失败") + throw NoStackTraceException("没有搜索到 ${name}(${author})") }.onStart { ReadBook.upMsg(context.getString(R.string.source_auto_changing)) }.onError { - context.toastOnUi(it.msg) + AppLog.put("自动换源失败\n${it.localizedMessage}", it) + context.toastOnUi("自动换源失败\n${it.localizedMessage}") }.onFinally { ReadBook.upMsg(null) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt index 0f357bcc9..089070aee 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt @@ -322,7 +322,7 @@ class BgTextConfigDialog : BaseDialogFragment(R.layout.dialog_read_bg_text) { importConfig(it) } }.onError { - longToast(it.msg) + longToast(it.stackTraceStr) } } diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt index f90633923..ad3e2e426 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt @@ -128,7 +128,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application) }.onSuccess { success.invoke(it) }.onError { - context.toastOnUi(it.msg) + context.toastOnUi(it.stackTraceStr) } } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt index da911a5f4..184fe8d58 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt @@ -8,8 +8,8 @@ import io.legado.app.data.entities.RssSource import io.legado.app.help.RuleComplete import io.legado.app.help.http.CookieStore import io.legado.app.utils.getClipText -import io.legado.app.utils.msg import io.legado.app.utils.printOnDebug +import io.legado.app.utils.stackTraceStr import io.legado.app.utils.toastOnUi import kotlinx.coroutines.Dispatchers @@ -74,7 +74,7 @@ class RssSourceEditViewModel(application: Application) : BaseViewModel(applicati finally.invoke(it) } }.onError { - context.toastOnUi(it.msg) + context.toastOnUi(it.stackTraceStr) } } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt index 8bf64b790..52f0db6b5 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt @@ -83,7 +83,7 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application) }.onSuccess { success.invoke(it) }.onError { - context.toastOnUi(it.msg) + context.toastOnUi(it.stackTraceStr) } } diff --git a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt index 94e35680c..534cce626 100644 --- a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt @@ -325,7 +325,7 @@ fun Context.openFileUri(uri: Uri, type: String? = null) { try { startActivity(intent) } catch (e: Exception) { - toastOnUi(e.msg) + toastOnUi(e.stackTraceStr) } } diff --git a/app/src/main/java/io/legado/app/utils/ThrowableExtensions.kt b/app/src/main/java/io/legado/app/utils/ThrowableExtensions.kt index 088db9b3b..4163b8211 100644 --- a/app/src/main/java/io/legado/app/utils/ThrowableExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ThrowableExtensions.kt @@ -2,7 +2,7 @@ package io.legado.app.utils import java.io.IOException -val Throwable.msg: String +val Throwable.stackTraceStr: String get() { val stackTrace = stackTraceToString() val lMsg = this.localizedMessage ?: "noErrorMsg" From f79f361510b82769b982b852388412c0fcc3411d Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 6 Sep 2022 00:24:22 +0000 Subject: [PATCH 02/11] Bump cronet from 105.0.5195.77 to 105.0.5195.79 - Changes in the [Git log](https://chromium.googlesource.com/chromium/src/+log/105.0.5195.77..105.0.5195.79) --- app/cronetlib/cronet_api.jar | Bin 69819 -> 69819 bytes app/cronetlib/cronet_impl_common_java.jar | Bin 119653 -> 119653 bytes app/src/main/assets/cronet.json | 2 +- app/src/main/assets/updateLog.md | 1 + gradle.properties | 2 +- 5 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/cronetlib/cronet_api.jar b/app/cronetlib/cronet_api.jar index b974d88b80ce31e2442bf3db92756b199e1b5b81..ce9b6a5957e549efc582aae6a846fc4303be8ad9 100644 GIT binary patch delta 129 zcmdnJkY)Em7U=+QW)=|!2vF3z^x{!v9SZ{k2rEurXelz;fQf6Pr2vzWr2`Lx0fQkU zgL{f`TB<=(vRSfGikU%LqIt5hv9Vc7im8!hQi{2mg{6Uog>jOlNz&wMCRs+y$uq&^ WLP62ZXP6ZKvw&>a{*jUK6dwRUdL(fG delta 129 zcmdnJkY)Em7U=+QW)=|!2vF3zoGi;$$HKq>!itj@T8d0IVB*?nDZpf8?!d!fz+lM8 z;GSq;X<(d~lxC4=nQW1oWR#d7EsUbgDGRozEMUx3W&v5g{o-N9Df|GG(k&7I diff --git a/app/src/main/assets/cronet.json b/app/src/main/assets/cronet.json index 8869820fb..41a9bc317 100644 --- a/app/src/main/assets/cronet.json +++ b/app/src/main/assets/cronet.json @@ -1 +1 @@ -{"arm64-v8a":"11ded68691faa98fb1ab552210c8d4a8","armeabi-v7a":"4a986b523de502fc85ba6ea51f6f7184","x86_64":"80a642112fe079f3d689a6420a27e926","x86":"e72bf103350222d212bcb0b641733d43","version":"105.0.5195.77"} \ No newline at end of file +{"arm64-v8a":"27f6651b39339e6734e7ca63a9c9022b","armeabi-v7a":"abbf91c8b8f3dd02a4bda8872e3b9b98","x86_64":"d6923e011add8b18a824ef5a7c85772e","x86":"ba27795b663a8420790da40d40b99f96","version":"105.0.5195.79"} \ No newline at end of file diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 2481b92f2..634f47a01 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -13,6 +13,7 @@ **2022/09/03** +* 更新cronet: 105.0.5195.79 * 更新cronet: 105.0.5195.77 * 更新web端书源编辑 by jgckM diff --git a/gradle.properties b/gradle.properties index 5373be72b..cff0bf657 100644 --- a/gradle.properties +++ b/gradle.properties @@ -26,4 +26,4 @@ android.experimental.enableNewResourceShrinker.preciseShrinking=true # and none from the library's dependencies, thereby reducing the size of the R class for that library. android.nonTransitiveRClass=true #https://chromiumdash.appspot.com/releases?platform=Android -CronetVersion=105.0.5195.77 +CronetVersion=105.0.5195.79 From 450467628943c7ab02aceba459e3b1ac9ab9333b Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 6 Sep 2022 11:17:43 +0800 Subject: [PATCH 03/11] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/help/JsExtensions.kt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/JsExtensions.kt b/app/src/main/java/io/legado/app/help/JsExtensions.kt index 8280c8e6b..3e4ba7689 100644 --- a/app/src/main/java/io/legado/app/help/JsExtensions.kt +++ b/app/src/main/java/io/legado/app/help/JsExtensions.kt @@ -433,13 +433,15 @@ interface JsExtensions { } /** - * js实现文件夹内所有文件读取 + * js实现文件夹内所有文本文件读取 + * @param path 文件夹相对路径 + * @return 所有文件字符串换行连接 */ - fun getTxtInFolder(unzipPath: String): String { - if (unzipPath.isEmpty()) return "" - val unzipFolder = getFile(unzipPath) + fun getTxtInFolder(path: String): String { + if (path.isEmpty()) return "" + val folder = getFile(path) val contents = StringBuilder() - unzipFolder.listFiles().let { + folder.listFiles().let { if (it != null) { for (f in it) { val charsetName = EncodingDetect.getEncode(f) @@ -449,7 +451,7 @@ interface JsExtensions { contents.deleteCharAt(contents.length - 1) } } - FileUtils.delete(unzipFolder.absolutePath) + FileUtils.delete(folder.absolutePath) return contents.toString() } From 5d2c43da527353f037641278493a43ba0484397e Mon Sep 17 00:00:00 2001 From: Horis <821938089@qq.com> Date: Tue, 6 Sep 2022 14:04:43 +0800 Subject: [PATCH 04/11] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/book/read/page/delegate/HorizontalPageDelegate.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt index 9201880ea..ee703faf9 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt @@ -119,7 +119,11 @@ abstract class HorizontalPageDelegate(readView: ReadView) : PageDelegate(readVie abortAnim() if (!hasNext()) return setDirection(PageDirection.NEXT) - readView.setStartPoint(viewWidth.toFloat(), 1f, false) + val y = when { + viewHeight / 2 < startY -> viewHeight.toFloat() * 0.9f + else -> 1f + } + readView.setStartPoint(viewWidth.toFloat() * 0.9f, y, false) onAnimStart(animationSpeed) } From d8f6575416263628aff84c59f05ebedffd0080bc Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 6 Sep 2022 14:44:51 +0800 Subject: [PATCH 05/11] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/help/JsExtensions.kt | 54 ++++++++++++++----- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/JsExtensions.kt b/app/src/main/java/io/legado/app/help/JsExtensions.kt index 3e4ba7689..16c9dc14e 100644 --- a/app/src/main/java/io/legado/app/help/JsExtensions.kt +++ b/app/src/main/java/io/legado/app/help/JsExtensions.kt @@ -27,6 +27,7 @@ import splitties.init.appCtx import java.io.ByteArrayInputStream import java.io.ByteArrayOutputStream import java.io.File +import java.io.FileOutputStream import java.net.URLEncoder import java.nio.charset.Charset import java.text.SimpleDateFormat @@ -125,7 +126,7 @@ interface JsExtensions { html = html, javaScript = js, headerMap = getSource()?.getHeaderMap(true), - tag = getSource()?.getKey() + tag = getSource()?.getKey() ).getStrResponse().body } } @@ -143,15 +144,18 @@ interface JsExtensions { * 使用内置浏览器打开链接,并等待网页结果 */ fun startBrowserAwait(url: String, title: String): StrResponse { - return StrResponse(url, SourceVerificationHelp.getVerificationResult(getSource(), url, title, true)) + return StrResponse( + url, + SourceVerificationHelp.getVerificationResult(getSource(), url, title, true) + ) } /** * 打开图片验证码对话框,等待返回验证结果 */ - fun getVerificationCode(imageUrl: String): String { - return SourceVerificationHelp.getVerificationResult(getSource(), imageUrl, "", false) - } + fun getVerificationCode(imageUrl: String): String { + return SourceVerificationHelp.getVerificationResult(getSource(), imageUrl, "", false) + } /** * 可从网络,本地文件(阅读私有缓存目录和书籍保存位置支持相对路径)导入JavaScript脚本 @@ -203,6 +207,29 @@ interface JsExtensions { } } + /** + * 下载文件 + * @param url 下载地址:可带参数type,文件后缀,不带默认zip + * @return 下载的文件相对路径 + */ + fun downloadFile(url: String): String { + val analyzeUrl = AnalyzeUrl(url, source = getSource()) + val type = analyzeUrl.type ?: "zip" + val path = FileUtils.getPath( + FileUtils.createFolderIfNotExist(FileUtils.getCachePath()), + "${MD5Utils.md5Encode16(url)}.${type}" + ) + FileUtils.delete(path) + analyzeUrl.getInputStream().use { iStream -> + val file = FileUtils.createFileIfNotExist(path) + FileOutputStream(file).use { oStream -> + iStream.copyTo(oStream) + } + } + return path.substring(FileUtils.getCachePath().length) + } + + /** * 实现16进制字符串转文件 * @param content 需要转成文件的16进制字符串 @@ -211,18 +238,18 @@ interface JsExtensions { */ fun downloadFile(content: String, url: String): String { val type = AnalyzeUrl(url, source = getSource()).type ?: return "" - val zipPath = FileUtils.getPath( + val path = FileUtils.getPath( FileUtils.createFolderIfNotExist(FileUtils.getCachePath()), "${MD5Utils.md5Encode16(url)}.${type}" ) - FileUtils.delete(zipPath) - val zipFile = FileUtils.createFileIfNotExist(zipPath) + FileUtils.delete(path) + val file = FileUtils.createFileIfNotExist(path) StringUtils.hexStringToByte(content).let { if (it.isNotEmpty()) { - zipFile.writeBytes(it) + file.writeBytes(it) } } - return zipPath.substring(FileUtils.getCachePath().length) + return path.substring(FileUtils.getCachePath().length) } /** @@ -835,7 +862,7 @@ interface JsExtensions { } fun desBase64DecodeToString( - data: String, key: String, transformation: String, iv: String + data: String, key: String, transformation: String, iv: String ): String? { return EncoderUtils.decryptBase64DES( data.encodeToByteArray(), @@ -1030,7 +1057,10 @@ interface JsExtensions { algorithm: String, key: String ): String { - return Base64.encodeToString(HMac(algorithm, key.toByteArray()).digest(data), Base64.NO_WRAP) + return Base64.encodeToString( + HMac(algorithm, key.toByteArray()).digest(data), + Base64.NO_WRAP + ) } fun md5Encode(str: String): String { From 6f7581a254401eb53936121472b4a02ab3815875 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 6 Sep 2022 20:39:58 +0800 Subject: [PATCH 06/11] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/book/read/page/PageView.kt | 54 +++++++++++++++++++ .../legado/app/ui/book/read/page/ReadView.kt | 4 +- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index f8d86fa9e..0b15507c7 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -104,6 +104,9 @@ class PageView(context: Context) : FrameLayout(context) { isGone = ReadBookConfig.hideStatusBar || readBookActivity?.isInMultiWindow == true } + /** + * 更新阅读信息 + */ private fun upTipStyle() = binding.run { tvHeaderLeft.tag = null tvHeaderMiddle.tag = null @@ -189,6 +192,10 @@ class PageView(context: Context) : FrameLayout(context) { } } + /** + * 获取信息视图 + * @param tip 信息类型 + */ private fun getTipView(tip: Int): BatteryView? = binding.run { return when (tip) { ReadTipConfig.tipHeaderLeft -> tvHeaderLeft @@ -201,6 +208,9 @@ class PageView(context: Context) : FrameLayout(context) { } } + /** + * 更新背景 + */ fun upBg() { if (ReadBookConfig.bgAlpha < 100) { binding.vwRoot.backgroundColor = ReadBookConfig.bgMeanColor @@ -211,15 +221,24 @@ class PageView(context: Context) : FrameLayout(context) { upBgAlpha() } + /** + * 更新背景透明度 + */ fun upBgAlpha() { binding.vwBg.alpha = ReadBookConfig.bgAlpha / 100f } + /** + * 更新时间信息 + */ fun upTime() { tvTime?.text = timeFormat.format(Date(System.currentTimeMillis())) upTimeBattery() } + /** + * 更新电池信息 + */ @SuppressLint("SetTextI18n") fun upBattery(battery: Int) { this.battery = battery @@ -228,6 +247,9 @@ class PageView(context: Context) : FrameLayout(context) { upTimeBattery() } + /** + * 更新电池信息 + */ @SuppressLint("SetTextI18n") private fun upTimeBattery() { val time = timeFormat.format(Date(System.currentTimeMillis())) @@ -235,6 +257,9 @@ class PageView(context: Context) : FrameLayout(context) { tvTimeBatteryP?.text = "$time $battery%" } + /** + * 设置内容 + */ fun setContent(textPage: TextPage, resetPageOffset: Boolean = true) { setProgress(textPage) if (resetPageOffset) { @@ -243,14 +268,23 @@ class PageView(context: Context) : FrameLayout(context) { binding.contentTextView.setContent(textPage) } + /** + * 设置无障碍文本 + */ fun setContentDescription(content: String) { binding.contentTextView.contentDescription = content } + /** + * 重置滚动位置 + */ fun resetPageOffset() { binding.contentTextView.resetPageOffset() } + /** + * 设置进度 + */ @SuppressLint("SetTextI18n") fun setProgress(textPage: TextPage) = textPage.apply { tvBookName?.text = ReadBook.book?.name @@ -260,14 +294,31 @@ class PageView(context: Context) : FrameLayout(context) { tvPageAndTotal?.text = "${index.plus(1)}/$pageSize $readProgress" } + /** + * 滚动事件 + */ fun scroll(offset: Int) { binding.contentTextView.scroll(offset) } + /** + * 更新是否开启选择功能 + */ fun upSelectAble(selectAble: Boolean) { binding.contentTextView.selectAble = selectAble } + /** + * 优先处理页面内单击 + * @return true:已处理, false:未处理 + */ + fun onClick(x: Float, y: Float): Boolean { + return false + } + + /** + * 长按事件 + */ fun longPress( x: Float, y: Float, select: (relativePagePos: Int, lineIndex: Int, charIndex: Int) -> Unit, @@ -275,6 +326,9 @@ class PageView(context: Context) : FrameLayout(context) { return binding.contentTextView.longPress(x, y - headerHeight, select) } + /** + * 选择文本 + */ fun selectText( x: Float, y: Float, select: (relativePagePos: Int, lineIndex: Int, charIndex: Int) -> Unit, 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 6a8abc9bf..b4fef733a 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 @@ -222,7 +222,9 @@ class ReadView(context: Context, attrs: AttributeSet) : pressDown = false if (!isPageMove) { if (!longPressed && !pressOnTextSelected) { - onSingleTapUp() + if (!curPage.onClick(startX, startY)) { + onSingleTapUp() + } return true } } From 93e0cb7eeab75345b0cd02901f8367fb1f02eb1e Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 6 Sep 2022 20:47:24 +0800 Subject: [PATCH 07/11] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/read/page/ContentTextView.kt | 8 ++++++++ .../main/java/io/legado/app/ui/book/read/page/PageView.kt | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index 232e90959..b4f9dc173 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -283,6 +283,14 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } } + /** + * 单击 + * @return true:已处理, false:未处理 + */ + fun click(x: Float, y: Float): Boolean { + return false + } + /** * 选择文字 */ diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index 0b15507c7..286dc8aa0 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -313,7 +313,7 @@ class PageView(context: Context) : FrameLayout(context) { * @return true:已处理, false:未处理 */ fun onClick(x: Float, y: Float): Boolean { - return false + return binding.contentTextView.click(x, y - headerHeight) } /** From 9d5f197997fb88baaf47426b809741d846214d31 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 7 Sep 2022 10:04:55 +0800 Subject: [PATCH 08/11] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/ContentTextView.kt | 21 ++++++++++++++++++- .../legado/app/ui/book/read/page/PageView.kt | 2 +- .../legado/app/ui/book/read/page/ReadView.kt | 4 +++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index b4f9dc173..e11d5c335 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -28,7 +28,7 @@ import io.legado.app.utils.toastOnUi import kotlin.math.min /** - * 阅读内容界面 + * 阅读内容视图 */ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, attrs) { var selectAble = context.getPrefBoolean(PreferKey.textSelectAble, true) @@ -65,12 +65,18 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at callBack = activity as CallBack } + /** + * 设置内容 + */ fun setContent(textPage: TextPage) { this.textPage = textPage imagePaint.isAntiAlias = AppConfig.useAntiAlias invalidate() } + /** + * 更新绘制区域 + */ fun upVisibleRect() { visibleRect.set( ChapterProvider.paddingLeft.toFloat(), @@ -121,6 +127,9 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } } + /** + * 绘制页面 + */ private fun draw( canvas: Canvas, textPage: TextPage, @@ -259,6 +268,9 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at invalidate() } + /** + * 重置滚动位置 + */ fun resetPageOffset() { pageOffset = 0 } @@ -288,6 +300,9 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at * @return true:已处理, false:未处理 */ fun click(x: Float, y: Float): Boolean { + touch(x, y) { _, relativePos, textPage, lineIndex, textLine, charIndex, textChar -> + + } return false } @@ -342,6 +357,10 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } } + /** + * 触碰位置信息 + * @param touched 回调 + */ private fun touch( x: Float, y: Float, diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index 286dc8aa0..3637438f1 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -24,7 +24,7 @@ import splitties.views.backgroundColor import java.util.* /** - * 阅读界面 + * 页面视图 */ class PageView(context: Context) : FrameLayout(context) { 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 b4fef733a..eafd9a7bb 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 @@ -32,7 +32,9 @@ import java.text.BreakIterator import java.util.* import kotlin.math.abs - +/** + * 阅读视图 + */ class ReadView(context: Context, attrs: AttributeSet) : FrameLayout(context, attrs), DataSource { From 949cdb3a904eeba3678158dee67391c62b2e568e Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 7 Sep 2022 12:24:32 +0800 Subject: [PATCH 09/11] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/ContentTextView.kt | 41 ++++++++----------- .../legado/app/ui/book/read/page/PageView.kt | 5 ++- .../legado/app/ui/book/read/page/ReadView.kt | 36 +++++++++------- .../ui/book/read/page/entities/TextChapter.kt | 3 ++ .../ui/book/read/page/entities/TextChar.kt | 3 ++ .../ui/book/read/page/entities/TextLine.kt | 3 ++ .../ui/book/read/page/entities/TextPage.kt | 3 ++ .../app/ui/book/read/page/entities/TextPos.kt | 3 ++ 8 files changed, 58 insertions(+), 39 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index e11d5c335..fe1e9e09d 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -281,16 +281,16 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at fun longPress( x: Float, y: Float, - select: (relativePage: Int, lineIndex: Int, charIndex: Int) -> Unit, + select: (textPos: TextPos) -> Unit, ) { - touch(x, y) { _, relativePos, _, lineIndex, _, charIndex, textChar -> + touch(x, y) { _, textPos, _, _, textChar -> if (textChar.isImage) { callBack.onImageLongPress(x, y, textChar.charData) } else { if (!selectAble) return@touch textChar.selected = true invalidate() - select(relativePos, lineIndex, charIndex) + select(textPos) } } } @@ -300,7 +300,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at * @return true:已处理, false:未处理 */ fun click(x: Float, y: Float): Boolean { - touch(x, y) { _, relativePos, textPage, lineIndex, textLine, charIndex, textChar -> + touch(x, y) { _, textPos, textPage, textLine, textChar -> } return false @@ -312,12 +312,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at fun selectText( x: Float, y: Float, - select: (relativePage: Int, lineIndex: Int, charIndex: Int) -> Unit, + select: (textPos: TextPos) -> Unit, ) { - touch(x, y) { _, relativePos, _, lineIndex, _, charIndex, textChar -> + touch(x, y) { _, textPos, _, _, textChar -> textChar.selected = true invalidate() - select(relativePos, lineIndex, charIndex) + select(textPos) } } @@ -325,11 +325,10 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at * 开始选择符移动 */ fun selectStartMove(x: Float, y: Float) { - touch(x, y) { relativeOffset, relativePos, _, lineIndex, textLine, charIndex, textChar -> - val pos = TextPos(relativePos, lineIndex, charIndex) - if (selectStart.compare(pos) != 0) { - if (pos.compare(selectEnd) <= 0) { - selectStart.upData(pos = pos) + touch(x, y) { relativeOffset, textPos, _, textLine, textChar -> + if (selectStart.compare(textPos) != 0) { + if (textPos.compare(selectEnd) <= 0) { + selectStart.upData(pos = textPos) upSelectedStart( textChar.start, textLine.lineBottom + relativeOffset, @@ -345,11 +344,10 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at * 结束选择符移动 */ fun selectEndMove(x: Float, y: Float) { - touch(x, y) { relativeOffset, relativePos, _, lineIndex, textLine, charIndex, textChar -> - val pos = TextPos(relativePos, lineIndex, charIndex) - if (pos.compare(selectEnd) != 0) { - if (pos.compare(selectStart) >= 0) { - selectEnd.upData(pos) + touch(x, y) { relativeOffset, textPos, _, textLine, textChar -> + if (textPos.compare(selectEnd) != 0) { + if (textPos.compare(selectStart) >= 0) { + selectEnd.upData(textPos) upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) upSelectChars() } @@ -366,11 +364,9 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at y: Float, touched: ( relativeOffset: Float, - relativePos: Int, + textPos: TextPos, textPage: TextPage, - lineIndex: Int, textLine: TextLine, - charIndex: Int, textChar: TextChar ) -> Unit ) { @@ -390,9 +386,8 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (textChar.isTouch(x)) { touched.invoke( relativeOffset, - relativePos, textPage, - lineIndex, textLine, - charIndex, textChar + TextPos(relativePos, lineIndex, charIndex), + textPage, textLine, textChar ) return } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index 3637438f1..048f9725b 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -14,6 +14,7 @@ import io.legado.app.help.config.ReadTipConfig import io.legado.app.model.ReadBook import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.book.read.page.entities.TextPage +import io.legado.app.ui.book.read.page.entities.TextPos import io.legado.app.ui.book.read.page.provider.ChapterProvider import io.legado.app.ui.widget.BatteryView import io.legado.app.utils.activity @@ -321,7 +322,7 @@ class PageView(context: Context) : FrameLayout(context) { */ fun longPress( x: Float, y: Float, - select: (relativePagePos: Int, lineIndex: Int, charIndex: Int) -> Unit, + select: (textPos: TextPos) -> Unit, ) { return binding.contentTextView.longPress(x, y - headerHeight, select) } @@ -331,7 +332,7 @@ class PageView(context: Context) : FrameLayout(context) { */ fun selectText( x: Float, y: Float, - select: (relativePagePos: Int, lineIndex: Int, charIndex: Int) -> Unit, + select: (textPos: TextPos) -> Unit, ) { return binding.contentTextView.selectText(x, y - headerHeight, select) } 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 eafd9a7bb..3ac543f11 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 @@ -296,18 +296,18 @@ class ReadView(context: Context, attrs: AttributeSet) : */ private fun onLongPress() { kotlin.runCatching { - curPage.longPress(startX, startY) { relativePos, lineIndex, charIndex -> + curPage.longPress(startX, startY) { textPos: TextPos -> isTextSelected = true pressOnTextSelected = true - initialTextPos.upData(relativePos, lineIndex, charIndex) - val startPos = TextPos(relativePos, lineIndex, charIndex) - val endPos = TextPos(relativePos, lineIndex, charIndex) - val page = curPage.relativePage(relativePos) + initialTextPos.upData(textPos) + val startPos = textPos.copy() + val endPos = textPos.copy() + val page = curPage.relativePage(textPos.relativePagePos) val stringBuilder = StringBuilder() - var cIndex = charIndex - var lineStart = lineIndex - var lineEnd = lineIndex - for (index in lineIndex - 1 downTo 0) { + var cIndex = textPos.charIndex + var lineStart = textPos.lineIndex + var lineEnd = textPos.lineIndex + for (index in textPos.lineIndex - 1 downTo 0) { val textLine = page.getLine(index) if (textLine.isParagraphEnd) { break @@ -317,7 +317,7 @@ class ReadView(context: Context, attrs: AttributeSet) : cIndex += textLine.charSize } } - for (index in lineIndex until page.lineSize) { + for (index in textPos.lineIndex until page.lineSize) { val textLine = page.getLine(index) stringBuilder.append(textLine.text) lineEnd += 1 @@ -423,11 +423,15 @@ class ReadView(context: Context, attrs: AttributeSet) : * 选择文本 */ private fun selectText(x: Float, y: Float) { - curPage.selectText(x, y) { relativePagePos, lineIndex, charIndex -> - val compare = initialTextPos.compare(relativePagePos, lineIndex, charIndex) + curPage.selectText(x, y) { textPos -> + val compare = initialTextPos.compare(textPos) when { compare >= 0 -> { - curPage.selectStartMoveIndex(relativePagePos, lineIndex, charIndex) + curPage.selectStartMoveIndex( + textPos.relativePagePos, + textPos.lineIndex, + textPos.charIndex + ) curPage.selectEndMoveIndex( initialTextPos.relativePagePos, initialTextPos.lineIndex, @@ -440,7 +444,11 @@ class ReadView(context: Context, attrs: AttributeSet) : initialTextPos.lineIndex, initialTextPos.charIndex ) - curPage.selectEndMoveIndex(relativePagePos, lineIndex, charIndex) + curPage.selectEndMoveIndex( + textPos.relativePagePos, + textPos.lineIndex, + textPos.charIndex + ) } } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChapter.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChapter.kt index dfbf4a9cf..50d254e58 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChapter.kt @@ -2,6 +2,9 @@ package io.legado.app.ui.book.read.page.entities import kotlin.math.min +/** + * 章节信息 + */ @Suppress("unused") data class TextChapter( val position: Int, diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChar.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChar.kt index 518067182..f52525597 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChar.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChar.kt @@ -1,5 +1,8 @@ package io.legado.app.ui.book.read.page.entities +/** + * 字符信息 + */ data class TextChar( val charData: String, var start: Float, diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt index 3ec66b3ca..176c4fea4 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt @@ -4,6 +4,9 @@ import android.text.TextPaint import io.legado.app.ui.book.read.page.provider.ChapterProvider import io.legado.app.utils.textHeight +/** + * 行信息 + */ @Suppress("unused", "MemberVisibilityCanBePrivate") data class TextLine( var text: String = "", diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt index 3997b1ead..82966b138 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt @@ -11,6 +11,9 @@ import splitties.init.appCtx import java.text.DecimalFormat import kotlin.math.min +/** + * 页面信息 + */ @Suppress("unused", "MemberVisibilityCanBePrivate") data class TextPage( var index: Int = 0, diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPos.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPos.kt index cc650c622..35dbfa589 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPos.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPos.kt @@ -1,5 +1,8 @@ package io.legado.app.ui.book.read.page.entities +/** + * 位置信息 + */ data class TextPos( var relativePagePos: Int, var lineIndex: Int, From 1523f1ca959885af8f5a7470c8cfbef470194238 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 7 Sep 2022 20:49:10 +0800 Subject: [PATCH 10/11] =?UTF-8?q?=E5=87=86=E5=A4=87=E5=9C=A8=E6=AD=A3?= =?UTF-8?q?=E6=96=87=E6=B7=BB=E5=8A=A0=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/book/read/page/ContentTextView.kt | 10 +++++----- .../page/entities/{TextChar.kt => TextColumn.kt} | 4 ++-- .../app/ui/book/read/page/entities/TextLine.kt | 6 +++--- .../app/ui/book/read/page/entities/TextPage.kt | 2 +- .../ui/book/read/page/provider/ChapterProvider.kt | 12 ++++++------ 5 files changed, 17 insertions(+), 17 deletions(-) rename app/src/main/java/io/legado/app/ui/book/read/page/entities/{TextChar.kt => TextColumn.kt} (79%) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index fe1e9e09d..7408efd7d 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -14,7 +14,7 @@ import io.legado.app.help.config.AppConfig import io.legado.app.help.config.ReadBookConfig import io.legado.app.lib.theme.accentColor import io.legado.app.model.ReadBook -import io.legado.app.ui.book.read.page.entities.TextChar +import io.legado.app.ui.book.read.page.entities.TextColumn import io.legado.app.ui.book.read.page.entities.TextLine import io.legado.app.ui.book.read.page.entities.TextPage import io.legado.app.ui.book.read.page.entities.TextPos @@ -160,7 +160,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } val textColor = if (textLine.isReadAloud) context.accentColor else ReadBookConfig.textColor textLine.textChars.forEach { - if (it.isImage) { + if (it.style == 1) { drawImage(canvas, textPage, textLine, it, lineTop, lineBottom) } else { textPaint.color = textColor @@ -183,7 +183,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at canvas: Canvas, textPage: TextPage, textLine: TextLine, - textChar: TextChar, + textChar: TextColumn, lineTop: Float, lineBottom: Float ) { @@ -284,7 +284,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at select: (textPos: TextPos) -> Unit, ) { touch(x, y) { _, textPos, _, _, textChar -> - if (textChar.isImage) { + if (textChar.style == 1) { callBack.onImageLongPress(x, y, textChar.charData) } else { if (!selectAble) return@touch @@ -367,7 +367,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at textPos: TextPos, textPage: TextPage, textLine: TextLine, - textChar: TextChar + textColumn: TextColumn ) -> Unit ) { if (!visibleRect.contains(x, y)) return diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChar.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextColumn.kt similarity index 79% rename from app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChar.kt rename to app/src/main/java/io/legado/app/ui/book/read/page/entities/TextColumn.kt index f52525597..82badb33f 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChar.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextColumn.kt @@ -3,12 +3,12 @@ package io.legado.app.ui.book.read.page.entities /** * 字符信息 */ -data class TextChar( +data class TextColumn( val charData: String, var start: Float, var end: Float, + val style: Int = 0, //0:文字,1:图片,2:按钮 var selected: Boolean = false, - var isImage: Boolean = false, var isSearchResult: Boolean = false ) { diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt index 176c4fea4..28ac5b24f 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt @@ -10,7 +10,7 @@ import io.legado.app.utils.textHeight @Suppress("unused", "MemberVisibilityCanBePrivate") data class TextLine( var text: String = "", - val textChars: ArrayList = arrayListOf(), + val textChars: ArrayList = arrayListOf(), var lineTop: Float = 0f, var lineBase: Float = 0f, var lineBottom: Float = 0f, @@ -30,13 +30,13 @@ data class TextLine( lineBase = lineBottom - textPaint.fontMetrics.descent } - fun getTextChar(index: Int): TextChar { + fun getTextChar(index: Int): TextColumn { return textChars.getOrElse(index) { textChars.last() } } - fun getTextCharReverseAt(index: Int): TextChar { + fun getTextCharReverseAt(index: Int): TextColumn { return textChars[textChars.lastIndex - index] } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt index 82966b138..a69483ab2 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt @@ -114,7 +114,7 @@ data class TextPage( val cw = StaticLayout.getDesiredWidth(char, ChapterProvider.contentPaint) val x1 = x + cw textLine.textChars.add( - TextChar(char, start = x, end = x1) + TextColumn(char, start = x, end = x1) ) x = x1 } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt index 5ae48f727..185d251e6 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt @@ -14,7 +14,7 @@ import io.legado.app.help.config.AppConfig import io.legado.app.help.config.ReadBookConfig import io.legado.app.model.ReadBook import io.legado.app.ui.book.read.page.entities.TextChapter -import io.legado.app.ui.book.read.page.entities.TextChar +import io.legado.app.ui.book.read.page.entities.TextColumn import io.legado.app.ui.book.read.page.entities.TextLine import io.legado.app.ui.book.read.page.entities.TextPage import io.legado.app.utils.* @@ -252,7 +252,7 @@ object ChapterProvider { Pair(0f, width.toFloat()) } textLine.textChars.add( - TextChar(charData = src, start = x + start, end = x + end, isImage = true) + TextColumn(charData = src, start = x + start, end = x + end, style = 1) ) textPages.last().textLines.add(textLine) } @@ -401,7 +401,7 @@ object ChapterProvider { bodyIndent.toStringArray().forEach { char -> val x1 = x + icw textLine.textChars.add( - TextChar(charData = char, start = absStartX + x, end = absStartX + x1) + TextColumn(charData = char, start = absStartX + x, end = absStartX + x1) ) x = x1 } @@ -480,16 +480,16 @@ object ChapterProvider { val src = srcList.removeFirst() ImageProvider.cacheImage(book, src, ReadBook.bookSource) textLine.textChars.add( - TextChar( + TextColumn( charData = src, start = absStartX + xStart, end = absStartX + xEnd, - isImage = true + style = 1 ) ) } else { textLine.textChars.add( - TextChar( + TextColumn( charData = char, start = absStartX + xStart, end = absStartX + xEnd From 64e34fb614e027ee2d9a3b52e670bdef1f0f9ef8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 7 Sep 2022 20:56:47 +0800 Subject: [PATCH 11/11] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 634f47a01..bf011d6b2 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -11,11 +11,11 @@ * 正文出现缺字漏字、内容缺失、排版错乱等情况,有可能是净化规则或简繁转换出现问题。 * 漫画源看书显示乱码,**阅读与其他软件的源并不通用**,请导入阅读的支持的漫画源! -**2022/09/03** +**2022/09/07** * 更新cronet: 105.0.5195.79 -* 更新cronet: 105.0.5195.77 * 更新web端书源编辑 by jgckM +* 修复仿真翻页点击时翻页动画异常,化仿真翻页点击翻页效果 by 821938089 **2022/08/31**