|
|
@ -31,7 +31,7 @@ object ReadBook { |
|
|
|
var inBookshelf = false |
|
|
|
var inBookshelf = false |
|
|
|
var chapterSize = 0 |
|
|
|
var chapterSize = 0 |
|
|
|
var durChapterIndex = 0 |
|
|
|
var durChapterIndex = 0 |
|
|
|
var durPageIndex = 0 |
|
|
|
var durChapterPos = 0 |
|
|
|
var isLocalBook = true |
|
|
|
var isLocalBook = true |
|
|
|
var callBack: CallBack? = null |
|
|
|
var callBack: CallBack? = null |
|
|
|
var prevTextChapter: TextChapter? = null |
|
|
|
var prevTextChapter: TextChapter? = null |
|
|
@ -50,7 +50,7 @@ object ReadBook { |
|
|
|
readRecord.bookName = book.name |
|
|
|
readRecord.bookName = book.name |
|
|
|
readRecord.readTime = App.db.readRecordDao().getReadTime(book.name) ?: 0 |
|
|
|
readRecord.readTime = App.db.readRecordDao().getReadTime(book.name) ?: 0 |
|
|
|
durChapterIndex = book.durChapterIndex |
|
|
|
durChapterIndex = book.durChapterIndex |
|
|
|
durPageIndex = book.durChapterPos |
|
|
|
durChapterPos = book.durChapterPos |
|
|
|
isLocalBook = book.origin == BookType.local |
|
|
|
isLocalBook = book.origin == BookType.local |
|
|
|
chapterSize = 0 |
|
|
|
chapterSize = 0 |
|
|
|
prevTextChapter = null |
|
|
|
prevTextChapter = null |
|
|
@ -96,14 +96,14 @@ object ReadBook { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun moveToNextPage() { |
|
|
|
fun moveToNextPage() { |
|
|
|
durPageIndex++ |
|
|
|
durChapterPos = curTextChapter?.getNextPageLength(durChapterPos) ?: durChapterPos |
|
|
|
callBack?.upContent() |
|
|
|
callBack?.upContent() |
|
|
|
saveRead() |
|
|
|
saveRead() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun moveToNextChapter(upContent: Boolean): Boolean { |
|
|
|
fun moveToNextChapter(upContent: Boolean): Boolean { |
|
|
|
if (durChapterIndex < chapterSize - 1) { |
|
|
|
if (durChapterIndex < chapterSize - 1) { |
|
|
|
durPageIndex = 0 |
|
|
|
durChapterPos = 0 |
|
|
|
durChapterIndex++ |
|
|
|
durChapterIndex++ |
|
|
|
prevTextChapter = curTextChapter |
|
|
|
prevTextChapter = curTextChapter |
|
|
|
curTextChapter = nextTextChapter |
|
|
|
curTextChapter = nextTextChapter |
|
|
@ -133,7 +133,7 @@ object ReadBook { |
|
|
|
|
|
|
|
|
|
|
|
fun moveToPrevChapter(upContent: Boolean, toLast: Boolean = true): Boolean { |
|
|
|
fun moveToPrevChapter(upContent: Boolean, toLast: Boolean = true): Boolean { |
|
|
|
if (durChapterIndex > 0) { |
|
|
|
if (durChapterIndex > 0) { |
|
|
|
durPageIndex = if (toLast) prevTextChapter?.lastIndex ?: 0 else 0 |
|
|
|
durChapterPos = if (toLast) prevTextChapter?.lastReadLength ?: 0 else 0 |
|
|
|
durChapterIndex-- |
|
|
|
durChapterIndex-- |
|
|
|
nextTextChapter = curTextChapter |
|
|
|
nextTextChapter = curTextChapter |
|
|
|
curTextChapter = prevTextChapter |
|
|
|
curTextChapter = prevTextChapter |
|
|
@ -161,15 +161,15 @@ object ReadBook { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun skipToPage(page: Int) { |
|
|
|
fun skipToPage(index: Int) { |
|
|
|
durPageIndex = page |
|
|
|
durChapterPos = curTextChapter?.getReadLength(index) ?: index |
|
|
|
callBack?.upContent() |
|
|
|
callBack?.upContent() |
|
|
|
curPageChanged() |
|
|
|
curPageChanged() |
|
|
|
saveRead() |
|
|
|
saveRead() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun setPageIndex(pageIndex: Int) { |
|
|
|
fun setPageIndex(index: Int) { |
|
|
|
durPageIndex = pageIndex |
|
|
|
durChapterPos = curTextChapter?.getReadLength(index) ?: index |
|
|
|
saveRead() |
|
|
|
saveRead() |
|
|
|
curPageChanged() |
|
|
|
curPageChanged() |
|
|
|
} |
|
|
|
} |
|
|
@ -191,19 +191,16 @@ object ReadBook { |
|
|
|
if (book != null && textChapter != null) { |
|
|
|
if (book != null && textChapter != null) { |
|
|
|
val key = IntentDataHelp.putData(textChapter) |
|
|
|
val key = IntentDataHelp.putData(textChapter) |
|
|
|
ReadAloud.play( |
|
|
|
ReadAloud.play( |
|
|
|
App.INSTANCE, book.name, textChapter.title, durPageIndex, key, play |
|
|
|
App.INSTANCE, book.name, textChapter.title, durPageIndex(), key, play |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun durChapterPos(): Int { |
|
|
|
fun durPageIndex(): Int { |
|
|
|
curTextChapter?.let { |
|
|
|
curTextChapter?.let { |
|
|
|
if (durPageIndex < it.pageSize) { |
|
|
|
return it.getPageIndexByCharIndex(durChapterPos) |
|
|
|
return durPageIndex |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return it.pageSize - 1 |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return durPageIndex |
|
|
|
return durChapterPos |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -430,7 +427,7 @@ object ReadBook { |
|
|
|
book.lastCheckCount = 0 |
|
|
|
book.lastCheckCount = 0 |
|
|
|
book.durChapterTime = System.currentTimeMillis() |
|
|
|
book.durChapterTime = System.currentTimeMillis() |
|
|
|
book.durChapterIndex = durChapterIndex |
|
|
|
book.durChapterIndex = durChapterIndex |
|
|
|
book.durChapterPos = durPageIndex |
|
|
|
book.durChapterPos = durChapterPos |
|
|
|
App.db.bookChapterDao().getChapter(book.bookUrl, durChapterIndex)?.let { |
|
|
|
App.db.bookChapterDao().getChapter(book.bookUrl, durChapterIndex)?.let { |
|
|
|
book.durChapterTitle = it.title |
|
|
|
book.durChapterTitle = it.title |
|
|
|
} |
|
|
|
} |
|
|
|