feat(ReadBook): 添加跳转进度恢复

pull/2403/head
Xwite 2 years ago
parent 9af86699a3
commit a659c03ff9
  1. 25
      app/src/main/java/io/legado/app/model/ReadBook.kt
  2. 16
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt

@ -42,6 +42,30 @@ object ReadBook : CoroutineScope by MainScope() {
private val loadingChapters = arrayListOf<Int>()
private val readRecord = ReadRecord()
var readStartTime: Long = System.currentTimeMillis()
/* 跳转历史记录 */
var bookProgressHistory: List<BookProgress>? = null
/* 跳转进度前进度记录 */
var lastBookPress: BookProgress? = null
//暂时保存跳转前进度
fun saveCurrentBookProcess() {
lastBookPress = book?.let { BookProgress(it) }
}
//恢复跳转前进度
fun restoreLastBookProcess() {
lastBookPress?.let {
durChapterPos = it.durChapterPos
if (durChapterIndex != it.durChapterIndex) {
clearTextChapter()
durChapterIndex = it.durChapterIndex
}
callBack?.upContent()
saveRead()
loadContent(resetPageOffset = true) {
lastBookPress = null
}
}
}
fun resetData(book: Book) {
ReadBook.book = book
@ -55,6 +79,7 @@ object ReadBook : CoroutineScope by MainScope() {
callBack?.upMenuView()
callBack?.upPageAnim()
upWebBook(book)
lastBookPress = null
synchronized(this) {
loadingChapters.clear()
}

@ -926,13 +926,6 @@ class ReadBookActivity : BaseReadBookActivity(),
}
}
/**
* 跳转到指定章节
*/
override fun skipToChapter(index: Int) {
viewModel.openChapter(index)
}
/**
* 打开搜索界面
*/
@ -1141,11 +1134,20 @@ class ReadBookActivity : BaseReadBookActivity(),
}
}
/* 回复到 全文搜索/进度条跳转前的位置 */
/* 进度条跳转到指定章节 */
override fun skipToChapter(index: Int) {
viewModel.openChapter(index)
}
/* 全文搜索跳转 */
override fun navigateToSearch(searchResult: SearchResult, index: Int) {
viewModel.searchResultIndex = index
skipToSearch(searchResult)
}
/* 全文搜索跳转 */
private fun skipToSearch(searchResult: SearchResult) {
val previousResult = binding.searchMenu.previousSearchResult

Loading…
Cancel
Save