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

pull/2176/head
kunfei 2 years ago
parent 528dde2ee4
commit 9494f91430
  1. 16
      app/src/main/java/io/legado/app/service/BaseReadAloudService.kt
  2. 10
      app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt
  3. 21
      app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChapter.kt

@ -123,17 +123,11 @@ abstract class BaseReadAloudService : BaseService(),
nowSpeak = 0 nowSpeak = 0
readAloudNumber = textChapter.getReadLength(pageIndex) + startPos readAloudNumber = textChapter.getReadLength(pageIndex) + startPos
contentList.clear() contentList.clear()
if (getPrefBoolean(PreferKey.readAloudByPage)) { val readAloudByPage = getPrefBoolean(PreferKey.readAloudByPage)
for (index in pageIndex..textChapter.lastIndex) { textChapter.getNeedReadAloud(pageIndex, readAloudByPage, startPos)
textChapter.getPage(index)?.text?.split("\n")?.let { .split("\n").forEach { text ->
contentList.addAll(it) if (text.isNotEmpty()) {
} contentList.add(text)
}
} else {
textChapter.getUnRead(pageIndex).split("\n").forEach {
if (it.isNotEmpty()) {
contentList.add(it)
}
} }
} }
if (play) play() if (play) play()

@ -562,11 +562,17 @@ class ReadView(context: Context, attrs: AttributeSet) :
* 从选择位置开始朗读 * 从选择位置开始朗读
*/ */
fun aloudStartSelect() { fun aloudStartSelect() {
//todo 未完成
val selectStartPos = curPage.selectStartPos val selectStartPos = curPage.selectStartPos
curPage.textPage.textLines.forEach {
}
if (selectStartPos.relativePagePos > 0) { if (selectStartPos.relativePagePos > 0) {
ReadBook.moveToNextPage() if (!ReadBook.moveToNextPage()) {
ReadBook.moveToNextChapter(false)
}
} }
//TODO 未完成 ReadAloud.play(context)
} }
/** /**

@ -2,6 +2,7 @@ package io.legado.app.ui.book.read.page.entities
import kotlin.math.min import kotlin.math.min
@Suppress("unused")
data class TextChapter( data class TextChapter(
val position: Int, val position: Int,
val title: String, val title: String,
@ -85,6 +86,26 @@ data class TextChapter(
return stringBuilder.toString() 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 根据索引位置获取所在页 * @return 根据索引位置获取所在页
*/ */

Loading…
Cancel
Save