优化封面

pull/1336/head
gedoor 3 years ago
parent 4ac4b1fcaa
commit cbf5ee0d79
  1. 8
      app/src/main/java/io/legado/app/help/ContentProcessor.kt
  2. 16
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt
  3. 4
      app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt
  4. 2
      app/src/main/java/io/legado/app/service/HttpReadAloudService.kt

@ -77,6 +77,10 @@ class ContentProcessor private constructor(
//重新添加标题 //重新添加标题
mContent = chapter.getDisplayTitle() + "\n" + mContent mContent = chapter.getDisplayTitle() + "\n" + mContent
} }
if (reSegment && book.getReSegment()) {
//重新分段
mContent = ContentHelp.reSegment(mContent, chapter.title)
}
if (useReplace && book.getUseReplaceRule()) { if (useReplace && book.getUseReplaceRule()) {
//替换 //替换
getReplaceRules().forEach { item -> getReplaceRules().forEach { item ->
@ -93,10 +97,6 @@ class ContentProcessor private constructor(
} }
} }
} }
if (reSegment && book.getReSegment()) {
//重新分段
mContent = ContentHelp.reSegment(mContent, chapter.title)
}
if (chineseConvert) { if (chineseConvert) {
//简繁转换 //简繁转换
try { try {

@ -277,7 +277,7 @@ class AnalyzeByJSoup(doc: Any) {
var split: Char = '.', var split: Char = '.',
var beforeRule: String = "", var beforeRule: String = "",
val indexDefault: MutableList<Int> = mutableListOf(), val indexDefault: MutableList<Int> = mutableListOf(),
val indexs: MutableList<Any> = mutableListOf() val indexes: MutableList<Any> = mutableListOf()
) { ) {
/** /**
* 获取Elements按照一个规则 * 获取Elements按照一个规则
@ -304,13 +304,13 @@ class AnalyzeByJSoup(doc: Any) {
} }
val len = elements.size 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<Int>() val indexSet = mutableSetOf<Int>()
/** /**
* 获取无重且不越界的索引集合 * 获取无重且不越界的索引集合
* */ * */
if (indexs.isEmpty()) for (ix in lastIndexs downTo 0) { //indexs为空,表明是非[]式索引,集合是逆向遍历插入的,所以这里也逆向遍历,好还原顺序 if (indexes.isEmpty()) for (ix in lastIndexs downTo 0) { //indexs为空,表明是非[]式索引,集合是逆向遍历插入的,所以这里也逆向遍历,好还原顺序
val it = indexDefault[ix] val it = indexDefault[ix]
if (it in 0 until len) indexSet.add(it) //将正数不越界的索引添加到集合 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不空,表明是[]式索引,集合是逆向遍历插入的,所以这里也逆向遍历,好还原顺序 } else for (ix in lastIndexs downTo 0) { //indexs不空,表明是[]式索引,集合是逆向遍历插入的,所以这里也逆向遍历,好还原顺序
if (indexs[ix] is Triple<*, *, *>) { //区间 if (indexes[ix] is Triple<*, *, *>) { //区间
val (startx, endx, stepx) = indexs[ix] as Triple<Int?, Int?, Int> //还原储存时的类型 val (startx, endx, stepx) = indexes[ix] as Triple<Int?, Int?, Int> //还原储存时的类型
val start = if (startx == null) 0 //左端省略表示0 val start = if (startx == null) 0 //左端省略表示0
else if (startx >= 0) if (startx < len) startx else len - 1 //右端越界,设置为最大索引 else if (startx >= 0) if (startx < len) startx else len - 1 //右端越界,设置为最大索引
@ -344,7 +344,7 @@ class AnalyzeByJSoup(doc: Any) {
} else {//单个索引 } else {//单个索引
val it = indexs[ix] as Int //还原储存时的类型 val it = indexes[ix] as Int //还原储存时的类型
if (it in 0 until len) indexSet.add(it) //将正数不越界的索引添加到集合 if (it in 0 until len) indexSet.add(it) //将正数不越界的索引添加到集合
else if (it < 0 && len >= -it) indexSet.add(it + len) //将负数不越界的索引添加到集合 else if (it < 0 && len >= -it) indexSet.add(it + len) //将负数不越界的索引添加到集合
@ -415,11 +415,11 @@ class AnalyzeByJSoup(doc: Any) {
if (curInt == null) break //是jsoup选择器而非索引列表,跳出 if (curInt == null) break //是jsoup选择器而非索引列表,跳出
indexs.add(curInt) indexes.add(curInt)
} else { } else {
//列表最后压入的是区间右端,若列表有两位则最先压入的是间隔 //列表最后压入的是区间右端,若列表有两位则最先压入的是间隔
indexs.add( indexes.add(
Triple( Triple(
curInt, curInt,
curList.last(), curList.last(),

@ -173,7 +173,7 @@ object BookChapterList {
val urlRule = analyzeRule.splitSourceRule(tocRule.chapterUrl) val urlRule = analyzeRule.splitSourceRule(tocRule.chapterUrl)
val vipRule = analyzeRule.splitSourceRule(tocRule.isVip) val vipRule = analyzeRule.splitSourceRule(tocRule.isVip)
val payRule = analyzeRule.splitSourceRule(tocRule.isPay) val payRule = analyzeRule.splitSourceRule(tocRule.isPay)
val update = analyzeRule.splitSourceRule(tocRule.updateTime) val upTimeRule = analyzeRule.splitSourceRule(tocRule.updateTime)
var isVip: String? var isVip: String?
var isPay: String? var isPay: String?
for (item in elements) { for (item in elements) {
@ -183,7 +183,7 @@ object BookChapterList {
analyzeRule.chapter = bookChapter analyzeRule.chapter = bookChapter
bookChapter.title = analyzeRule.getString(nameRule) bookChapter.title = analyzeRule.getString(nameRule)
bookChapter.url = analyzeRule.getString(urlRule) bookChapter.url = analyzeRule.getString(urlRule)
bookChapter.tag = analyzeRule.getString(update) bookChapter.tag = analyzeRule.getString(upTimeRule)
isVip = analyzeRule.getString(vipRule) isVip = analyzeRule.getString(vipRule)
isPay = analyzeRule.getString(payRule) isPay = analyzeRule.getString(payRule)
if (bookChapter.url.isEmpty()) { if (bookChapter.url.isEmpty()) {

@ -2,6 +2,7 @@ package io.legado.app.service
import android.app.PendingIntent import android.app.PendingIntent
import android.media.MediaPlayer import android.media.MediaPlayer
import android.util.Log
import io.legado.app.constant.AppLog import io.legado.app.constant.AppLog
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
@ -76,6 +77,7 @@ class HttpReadAloudService : BaseReadAloudService(),
private fun playNext() { private fun playNext() {
readAloudNumber += contentList[nowSpeak].length + 1 readAloudNumber += contentList[nowSpeak].length + 1
Log.e("playNext", "$readAloudNumber")
if (nowSpeak < contentList.lastIndex) { if (nowSpeak < contentList.lastIndex) {
nowSpeak++ nowSpeak++
play() play()

Loading…
Cancel
Save