Merge pull request #2403 from Xwite/master

跳转进度恢复
This commit is contained in:
kunfei 2022-10-10 14:45:35 +08:00 committed by GitHub
commit 842a7f16ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 63 additions and 7 deletions

View File

@ -42,6 +42,31 @@ 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() {
if (lastBookPress != null) return //避免进度条连续跳转不能覆盖最初的进度记录
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 +80,7 @@ object ReadBook : CoroutineScope by MainScope() {
callBack?.upMenuView()
callBack?.upPageAnim()
upWebBook(book)
lastBookPress = null
synchronized(this) {
loadingChapters.clear()
}

View File

@ -125,6 +125,7 @@ class ReadBookActivity : BaseReadBookActivity(),
viewModel.searchResultIndex = index
binding.searchMenu.updateSearchResultIndex(index)
binding.searchMenu.selectedSearchResult?.let { currentResult ->
ReadBook.saveCurrentBookProcess() //退出全文搜索恢复此时进度
skipToSearch(currentResult)
showActionMenu()
}
@ -493,6 +494,11 @@ class ReadBookActivity : BaseReadBookActivity(),
keyCode == KeyEvent.KEYCODE_BACK -> {
if (isShowingSearchResult) {
exitSearchMenu()
restoreLastBookProcess()
return true
}
if (ReadBook.lastBookPress != null) {
restoreLastBookProcess()
return true
}
}
@ -926,13 +932,6 @@ class ReadBookActivity : BaseReadBookActivity(),
}
}
/**
* 跳转到指定章节
*/
override fun skipToChapter(index: Int) {
viewModel.openChapter(index)
}
/**
* 打开搜索界面
*/
@ -984,6 +983,7 @@ class ReadBookActivity : BaseReadBookActivity(),
upNavigationBarColor()
}
// 退出全文搜索
override fun exitSearchMenu() {
if (isShowingSearchResult) {
isShowingSearchResult = false
@ -994,6 +994,20 @@ class ReadBookActivity : BaseReadBookActivity(),
}
}
/* 恢复到 全文搜索/进度条跳转前的位置 */
private fun restoreLastBookProcess() {
// 默认提示恢复
alert(R.string.draw) {
setMessage(R.string.restore_last_book_process)
yesButton {
ReadBook.restoreLastBookProcess() //恢复启动全文搜索前的进度
}
noButton {
ReadBook.lastBookPress = null
}
}
}
override fun showLogin() {
ReadBook.bookSource?.let {
startActivity<SourceLoginActivity> {
@ -1141,11 +1155,18 @@ 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

View File

@ -375,11 +375,13 @@ class ReadMenu @JvmOverloads constructor(
"page" -> ReadBook.skipToPage(seekBar.progress)
"chapter" -> {
if (confirmSkipToChapter) {
ReadBook.saveCurrentBookProcess()
callBack.skipToChapter(seekBar.progress)
} else {
context.alert("章节跳转确认", "确定要跳转章节吗?") {
yesButton {
confirmSkipToChapter = true
ReadBook.saveCurrentBookProcess()
callBack.skipToChapter(seekBar.progress)
}
noButton {

View File

@ -1039,4 +1039,5 @@
<string name="progress_bar_behavior">进度条行为</string>
<string name="source_edit_text_max_line">源编辑框最大行数</string>
<string name="source_edit_max_line_summary">%s,设置行数小于屏幕可显示的最大行数可以更方便的滑动到其他的字段进行编辑</string>
<string name="restore_last_book_process">是否恢复到跳转前的阅读进度?</string>
</resources>

View File

@ -1042,4 +1042,5 @@
<string name="progress_bar_behavior">进度条行为</string>
<string name="source_edit_text_max_line">源编辑框最大行数</string>
<string name="source_edit_max_line_summary">%s,设置行数小于屏幕可显示的最大行数可以更方便的滑动到其他的字段进行编辑</string>
<string name="restore_last_book_process">是否恢复到跳转前的阅读进度?</string>
</resources>

View File

@ -1042,4 +1042,5 @@
<string name="progress_bar_behavior">进度条行为</string>
<string name="source_edit_text_max_line">源编辑框最大行数</string>
<string name="source_edit_max_line_summary">%s,设置行数小于屏幕可显示的最大行数可以更方便的滑动到其他的字段进行编辑</string>
<string name="restore_last_book_process">是否恢复到跳转前的阅读进度?</string>
</resources>

View File

@ -1039,4 +1039,5 @@
<string name="progress_bar_behavior">进度条行为</string>
<string name="source_edit_text_max_line">源编辑框最大行数</string>
<string name="source_edit_max_line_summary">%s,设置行数小于屏幕可显示的最大行数可以更方便的滑动到其他的字段进行编辑</string>
<string name="restore_last_book_process">是否恢复到跳转前的阅读进度?</string>
</resources>

View File

@ -1041,4 +1041,5 @@
<string name="progress_bar_behavior">进度条行为</string>
<string name="source_edit_text_max_line">源编辑框最大行数</string>
<string name="source_edit_max_line_summary">%s,设置行数小于屏幕可显示的最大行数可以更方便的滑动到其他的字段进行编辑</string>
<string name="restore_last_book_process">是否恢复到跳转前的阅读进度?</string>
</resources>

View File

@ -1041,4 +1041,5 @@
<string name="progress_bar_behavior">进度条行为</string>
<string name="source_edit_text_max_line">源编辑框最大行数</string>
<string name="source_edit_max_line_summary">%s,设置行数小于屏幕可显示的最大行数可以更方便的滑动到其他的字段进行编辑</string>
<string name="restore_last_book_process">是否恢复到跳转前的阅读进度?</string>
</resources>

View File

@ -1042,4 +1042,5 @@
<string name="progress_bar_behavior">进度条行为</string>
<string name="source_edit_text_max_line">源编辑框最大行数</string>
<string name="source_edit_max_line_summary">%s,设置行数小于屏幕可显示的最大行数可以更方便的滑动到其他的字段进行编辑</string>
<string name="restore_last_book_process">是否恢复到跳转前的阅读进度?</string>
</resources>