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