从文字选择处开始朗读,未完成

This commit is contained in:
kunfei
2022-08-14 20:30:07 +08:00
parent 080576ae65
commit 7cad2c1c85
3 changed files with 35 additions and 14 deletions
@@ -123,19 +123,13 @@ abstract class BaseReadAloudService : BaseService(),
nowSpeak = 0
readAloudNumber = textChapter.getReadLength(pageIndex) + startPos
contentList.clear()
if (getPrefBoolean(PreferKey.readAloudByPage)) {
for (index in pageIndex..textChapter.lastIndex) {
textChapter.getPage(index)?.text?.split("\n")?.let {
contentList.addAll(it)
val readAloudByPage = getPrefBoolean(PreferKey.readAloudByPage)
textChapter.getNeedReadAloud(pageIndex, readAloudByPage, startPos)
.split("\n").forEach { text ->
if (text.isNotEmpty()) {
contentList.add(text)
}
}
} else {
textChapter.getUnRead(pageIndex).split("\n").forEach {
if (it.isNotEmpty()) {
contentList.add(it)
}
}
}
if (play) play()
}
}
@@ -562,11 +562,17 @@ class ReadView(context: Context, attrs: AttributeSet) :
* 从选择位置开始朗读
*/
fun aloudStartSelect() {
//todo 未完成
val selectStartPos = curPage.selectStartPos
if (selectStartPos.relativePagePos > 0) {
ReadBook.moveToNextPage()
curPage.textPage.textLines.forEach {
}
//TODO 未完成
if (selectStartPos.relativePagePos > 0) {
if (!ReadBook.moveToNextPage()) {
ReadBook.moveToNextChapter(false)
}
}
ReadAloud.play(context)
}
/**
@@ -2,6 +2,7 @@ package io.legado.app.ui.book.read.page.entities
import kotlin.math.min
@Suppress("unused")
data class TextChapter(
val position: Int,
val title: String,
@@ -85,6 +86,26 @@ data class TextChapter(
return stringBuilder.toString()
}
/**
* @return 需要朗读的文本列表
* @param pageIndex 起始页
* @param pageSplit 是否分页
* @param startPos 从当前页什么地方开始朗读
*/
fun getNeedReadAloud(pageIndex: Int, pageSplit: Boolean, startPos: Int): String {
//todo 未完成
val stringBuilder = StringBuilder()
if (pages.isNotEmpty()) {
for (index in pageIndex..pages.lastIndex) {
stringBuilder.append(pages[index].text)
if (pageSplit && !stringBuilder.endsWith("\n")) {
stringBuilder.append("\n")
}
}
}
return stringBuilder.toString()
}
/**
* @return 根据索引位置获取所在页
*/