mirror of
https://github.com/gedoor/legado.git
synced 2024-09-03 09:55:00 +08:00
commit
842a7f16ac
@ -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()
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user