pull/811/head
gedoor 4 years ago
parent cfc9726a43
commit ebb760aeb8
  1. 17
      app/src/main/java/io/legado/app/service/help/ReadBook.kt
  2. 33
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt

@ -183,9 +183,11 @@ object ReadBook {
} }
} }
fun skipToPage(index: Int) { fun skipToPage(index: Int, success: (() -> Unit)? = null) {
durChapterPos = curTextChapter?.getReadLength(index) ?: index durChapterPos = curTextChapter?.getReadLength(index) ?: index
callBack?.upContent() callBack?.upContent() {
success?.invoke()
}
curPageChanged() curPageChanged()
saveRead() saveRead()
} }
@ -478,10 +480,19 @@ object ReadBook {
interface CallBack { interface CallBack {
fun loadChapterList(book: Book) fun loadChapterList(book: Book)
fun upContent(relativePosition: Int = 0, resetPageOffset: Boolean = true)
fun upContent(
relativePosition: Int = 0,
resetPageOffset: Boolean = true,
success: (() -> Unit)? = null
)
fun upView() fun upView()
fun pageChanged() fun pageChanged()
fun contentLoadFinish() fun contentLoadFinish()
fun upPageAnim() fun upPageAnim()
} }

@ -51,10 +51,8 @@ import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.* import io.legado.app.utils.*
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivity
import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.startActivityForResult
import org.jetbrains.anko.toast import org.jetbrains.anko.toast
@ -531,13 +529,18 @@ class ReadBookActivity : ReadBookBaseActivity(),
/** /**
* 更新内容 * 更新内容
*/ */
override fun upContent(relativePosition: Int, resetPageOffset: Boolean) { override fun upContent(
autoPageProgress = 0 relativePosition: Int,
resetPageOffset: Boolean,
success: (() -> Unit)?
) {
launch { launch {
autoPageProgress = 0
binding.readView.upContent(relativePosition, resetPageOffset) binding.readView.upContent(relativePosition, resetPageOffset)
binding.readMenu.setSeekPage(ReadBook.durPageIndex()) binding.readMenu.setSeekPage(ReadBook.durPageIndex())
loadStates = false
success?.invoke()
} }
loadStates = false
} }
/** /**
@ -807,18 +810,14 @@ class ReadBookActivity : ReadBookBaseActivity(),
private fun skipToSearch(index: Int, indexWithinChapter: Int) { private fun skipToSearch(index: Int, indexWithinChapter: Int) {
viewModel.openChapter(index) { viewModel.openChapter(index) {
launch(IO) { val pages = ReadBook.curTextChapter?.pages ?: return@openChapter
val pages = ReadBook.curTextChapter?.pages ?: return@launch val positions = ReadBook.searchResultPositions(
val positions = ReadBook.searchResultPositions( pages,
pages, indexWithinChapter,
indexWithinChapter, viewModel.searchContentQuery
viewModel.searchContentQuery )
) ReadBook.skipToPage(positions[0]) {
while (ReadBook.durPageIndex() != positions[0]) { launch {
delay(100L)
ReadBook.skipToPage(positions[0])
}
withContext(Main) {
binding.readView.curPage.selectStartMoveIndex(0, positions[1], positions[2]) binding.readView.curPage.selectStartMoveIndex(0, positions[1], positions[2])
delay(20L) delay(20L)
when (positions[3]) { when (positions[3]) {

Loading…
Cancel
Save