From cbf5ee0d792fb41d9b907c0ac9145fa2c9e3dfbb Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 20 Sep 2021 09:49:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=B0=81=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/help/ContentProcessor.kt | 8 ++++---- .../app/model/analyzeRule/AnalyzeByJSoup.kt | 16 ++++++++-------- .../legado/app/model/webBook/BookChapterList.kt | 4 ++-- .../legado/app/service/HttpReadAloudService.kt | 2 ++ 4 files changed, 16 insertions(+), 14 deletions(-) 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 fbfbf913e..6aa2566c7 100644 --- a/app/src/main/java/io/legado/app/help/ContentProcessor.kt +++ b/app/src/main/java/io/legado/app/help/ContentProcessor.kt @@ -77,6 +77,10 @@ class ContentProcessor private constructor( //重新添加标题 mContent = chapter.getDisplayTitle() + "\n" + mContent } + if (reSegment && book.getReSegment()) { + //重新分段 + mContent = ContentHelp.reSegment(mContent, chapter.title) + } if (useReplace && book.getUseReplaceRule()) { //替换 getReplaceRules().forEach { item -> @@ -93,10 +97,6 @@ class ContentProcessor private constructor( } } } - if (reSegment && book.getReSegment()) { - //重新分段 - mContent = ContentHelp.reSegment(mContent, chapter.title) - } if (chineseConvert) { //简繁转换 try { diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt index 19d016416..ffb08f274 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt @@ -277,7 +277,7 @@ class AnalyzeByJSoup(doc: Any) { var split: Char = '.', var beforeRule: String = "", val indexDefault: MutableList = mutableListOf(), - val indexs: MutableList = mutableListOf() + val indexes: MutableList = mutableListOf() ) { /** * 获取Elements按照一个规则 @@ -304,13 +304,13 @@ class AnalyzeByJSoup(doc: Any) { } val len = elements.size - val lastIndexs = (indexDefault.size - 1).takeIf { it != -1 } ?: indexs.size - 1 + val lastIndexs = (indexDefault.size - 1).takeIf { it != -1 } ?: indexes.size - 1 val indexSet = mutableSetOf() /** * 获取无重且不越界的索引集合 * */ - if (indexs.isEmpty()) for (ix in lastIndexs downTo 0) { //indexs为空,表明是非[]式索引,集合是逆向遍历插入的,所以这里也逆向遍历,好还原顺序 + if (indexes.isEmpty()) for (ix in lastIndexs downTo 0) { //indexs为空,表明是非[]式索引,集合是逆向遍历插入的,所以这里也逆向遍历,好还原顺序 val it = indexDefault[ix] if (it in 0 until len) indexSet.add(it) //将正数不越界的索引添加到集合 @@ -318,8 +318,8 @@ class AnalyzeByJSoup(doc: Any) { } else for (ix in lastIndexs downTo 0) { //indexs不空,表明是[]式索引,集合是逆向遍历插入的,所以这里也逆向遍历,好还原顺序 - if (indexs[ix] is Triple<*, *, *>) { //区间 - val (startx, endx, stepx) = indexs[ix] as Triple //还原储存时的类型 + if (indexes[ix] is Triple<*, *, *>) { //区间 + val (startx, endx, stepx) = indexes[ix] as Triple //还原储存时的类型 val start = if (startx == null) 0 //左端省略表示0 else if (startx >= 0) if (startx < len) startx else len - 1 //右端越界,设置为最大索引 @@ -344,7 +344,7 @@ class AnalyzeByJSoup(doc: Any) { } else {//单个索引 - val it = indexs[ix] as Int //还原储存时的类型 + val it = indexes[ix] as Int //还原储存时的类型 if (it in 0 until len) indexSet.add(it) //将正数不越界的索引添加到集合 else if (it < 0 && len >= -it) indexSet.add(it + len) //将负数不越界的索引添加到集合 @@ -415,11 +415,11 @@ class AnalyzeByJSoup(doc: Any) { if (curInt == null) break //是jsoup选择器而非索引列表,跳出 - indexs.add(curInt) + indexes.add(curInt) } else { //列表最后压入的是区间右端,若列表有两位则最先压入的是间隔 - indexs.add( + indexes.add( Triple( curInt, curList.last(), diff --git a/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt b/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt index 1f94aa89c..d8ad4dfac 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt @@ -173,7 +173,7 @@ object BookChapterList { val urlRule = analyzeRule.splitSourceRule(tocRule.chapterUrl) val vipRule = analyzeRule.splitSourceRule(tocRule.isVip) val payRule = analyzeRule.splitSourceRule(tocRule.isPay) - val update = analyzeRule.splitSourceRule(tocRule.updateTime) + val upTimeRule = analyzeRule.splitSourceRule(tocRule.updateTime) var isVip: String? var isPay: String? for (item in elements) { @@ -183,7 +183,7 @@ object BookChapterList { analyzeRule.chapter = bookChapter bookChapter.title = analyzeRule.getString(nameRule) bookChapter.url = analyzeRule.getString(urlRule) - bookChapter.tag = analyzeRule.getString(update) + bookChapter.tag = analyzeRule.getString(upTimeRule) isVip = analyzeRule.getString(vipRule) isPay = analyzeRule.getString(payRule) if (bookChapter.url.isEmpty()) { diff --git a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt index 13f4d90c9..67606ebb9 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -2,6 +2,7 @@ package io.legado.app.service import android.app.PendingIntent import android.media.MediaPlayer +import android.util.Log import io.legado.app.constant.AppLog import io.legado.app.constant.EventBus import io.legado.app.help.AppConfig @@ -76,6 +77,7 @@ class HttpReadAloudService : BaseReadAloudService(), private fun playNext() { readAloudNumber += contentList[nowSpeak].length + 1 + Log.e("playNext", "$readAloudNumber") if (nowSpeak < contentList.lastIndex) { nowSpeak++ play()