优化
This commit is contained in:
@@ -118,7 +118,7 @@ abstract class BaseReadAloudService : BaseService(),
|
||||
contentList.clear()
|
||||
if (getPrefBoolean(PreferKey.readAloudByPage)) {
|
||||
for (index in pageIndex..textChapter.lastIndex) {
|
||||
textChapter.page(index)?.text?.split("\n")?.let {
|
||||
textChapter.getPage(index)?.text?.split("\n")?.let {
|
||||
contentList.addAll(it)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -314,7 +314,7 @@ class ReadBookActivity : BaseReadBookActivity(),
|
||||
R.id.menu_download -> showDownloadDialog()
|
||||
R.id.menu_add_bookmark -> {
|
||||
val book = ReadBook.book
|
||||
val page = ReadBook.curTextChapter?.page(ReadBook.durPageIndex)
|
||||
val page = ReadBook.curTextChapter?.getPage(ReadBook.durPageIndex)
|
||||
if (book != null && page != null) {
|
||||
val bookmark = book.createBookMark().apply {
|
||||
chapterIndex = ReadBook.durChapterIndex
|
||||
@@ -1106,8 +1106,9 @@ class ReadBookActivity : BaseReadBookActivity(),
|
||||
launch(IO) {
|
||||
if (BaseReadAloudService.isPlay()) {
|
||||
ReadBook.curTextChapter?.let { textChapter ->
|
||||
val aloudSpanStart = chapterStart - ReadBook.durChapterPos
|
||||
textChapter.getPageByReadPos(ReadBook.durChapterPos)
|
||||
val pageIndex = ReadBook.durPageIndex
|
||||
val aloudSpanStart = chapterStart - textChapter.getReadLength(pageIndex)
|
||||
textChapter.getPage(pageIndex)
|
||||
?.upPageAloudSpan(aloudSpanStart)
|
||||
upContent()
|
||||
}
|
||||
|
||||
@@ -12,12 +12,12 @@ data class TextChapter(
|
||||
val isPay: Boolean,
|
||||
) {
|
||||
|
||||
fun page(index: Int): TextPage? {
|
||||
fun getPage(index: Int): TextPage? {
|
||||
return pages.getOrNull(index)
|
||||
}
|
||||
|
||||
fun getPageByReadPos(readPos: Int): TextPage? {
|
||||
return page(getPageIndexByCharIndex(readPos))
|
||||
return getPage(getPageIndexByCharIndex(readPos))
|
||||
}
|
||||
|
||||
val lastPage: TextPage? get() = pages.lastOrNull()
|
||||
|
||||
@@ -65,7 +65,7 @@ class TextPageFactory(dataSource: DataSource) : PageFactory<TextPage>(dataSource
|
||||
return@with TextPage(text = it).format()
|
||||
}
|
||||
currentChapter?.let {
|
||||
return@with it.page(pageIndex) ?: TextPage(title = it.title).format()
|
||||
return@with it.getPage(pageIndex) ?: TextPage(title = it.title).format()
|
||||
}
|
||||
return TextPage().format()
|
||||
}
|
||||
@@ -77,7 +77,7 @@ class TextPageFactory(dataSource: DataSource) : PageFactory<TextPage>(dataSource
|
||||
}
|
||||
currentChapter?.let {
|
||||
if (pageIndex < it.pageSize - 1) {
|
||||
return@with it.page(pageIndex + 1)?.removePageAloudSpan()
|
||||
return@with it.getPage(pageIndex + 1)?.removePageAloudSpan()
|
||||
?: TextPage(title = it.title).format()
|
||||
}
|
||||
}
|
||||
@@ -85,7 +85,7 @@ class TextPageFactory(dataSource: DataSource) : PageFactory<TextPage>(dataSource
|
||||
return@with TextPage(text = "")
|
||||
}
|
||||
nextChapter?.let {
|
||||
return@with it.page(0)?.removePageAloudSpan()
|
||||
return@with it.getPage(0)?.removePageAloudSpan()
|
||||
?: TextPage(title = it.title).format()
|
||||
}
|
||||
return TextPage().format()
|
||||
@@ -98,7 +98,7 @@ class TextPageFactory(dataSource: DataSource) : PageFactory<TextPage>(dataSource
|
||||
}
|
||||
if (pageIndex > 0) {
|
||||
currentChapter?.let {
|
||||
return@with it.page(pageIndex - 1)?.removePageAloudSpan()
|
||||
return@with it.getPage(pageIndex - 1)?.removePageAloudSpan()
|
||||
?: TextPage(title = it.title).format()
|
||||
}
|
||||
}
|
||||
@@ -113,15 +113,15 @@ class TextPageFactory(dataSource: DataSource) : PageFactory<TextPage>(dataSource
|
||||
get() = with(dataSource) {
|
||||
currentChapter?.let {
|
||||
if (pageIndex < it.pageSize - 2) {
|
||||
return@with it.page(pageIndex + 2)?.removePageAloudSpan()
|
||||
return@with it.getPage(pageIndex + 2)?.removePageAloudSpan()
|
||||
?: TextPage(title = it.title).format()
|
||||
}
|
||||
nextChapter?.let { nc ->
|
||||
if (pageIndex < it.pageSize - 1) {
|
||||
return@with nc.page(0)?.removePageAloudSpan()
|
||||
return@with nc.getPage(0)?.removePageAloudSpan()
|
||||
?: TextPage(title = nc.title).format()
|
||||
}
|
||||
return@with nc.page(1)?.removePageAloudSpan()
|
||||
return@with nc.getPage(1)?.removePageAloudSpan()
|
||||
?: TextPage(title = nc.title).format()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user