From ebb760aeb8fc8e1f671ab22c64236dfbbfb1887d Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 18 Jan 2021 15:36:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/service/help/ReadBook.kt | 17 ++++++++-- .../app/ui/book/read/ReadBookActivity.kt | 33 +++++++++---------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/help/ReadBook.kt b/app/src/main/java/io/legado/app/service/help/ReadBook.kt index 512f7ff7e..1a2d7b340 100644 --- a/app/src/main/java/io/legado/app/service/help/ReadBook.kt +++ b/app/src/main/java/io/legado/app/service/help/ReadBook.kt @@ -183,9 +183,11 @@ object ReadBook { } } - fun skipToPage(index: Int) { + fun skipToPage(index: Int, success: (() -> Unit)? = null) { durChapterPos = curTextChapter?.getReadLength(index) ?: index - callBack?.upContent() + callBack?.upContent() { + success?.invoke() + } curPageChanged() saveRead() } @@ -478,10 +480,19 @@ object ReadBook { interface CallBack { 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 pageChanged() + fun contentLoadFinish() + fun upPageAnim() } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index c46eb3dc4..14482296a 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -51,10 +51,8 @@ import io.legado.app.ui.widget.dialog.TextDialog import io.legado.app.utils.* import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers.IO -import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.delay import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.toast @@ -531,13 +529,18 @@ class ReadBookActivity : ReadBookBaseActivity(), /** * 更新内容 */ - override fun upContent(relativePosition: Int, resetPageOffset: Boolean) { - autoPageProgress = 0 + override fun upContent( + relativePosition: Int, + resetPageOffset: Boolean, + success: (() -> Unit)? + ) { launch { + autoPageProgress = 0 binding.readView.upContent(relativePosition, resetPageOffset) 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) { viewModel.openChapter(index) { - launch(IO) { - val pages = ReadBook.curTextChapter?.pages ?: return@launch - val positions = ReadBook.searchResultPositions( - pages, - indexWithinChapter, - viewModel.searchContentQuery - ) - while (ReadBook.durPageIndex() != positions[0]) { - delay(100L) - ReadBook.skipToPage(positions[0]) - } - withContext(Main) { + val pages = ReadBook.curTextChapter?.pages ?: return@openChapter + val positions = ReadBook.searchResultPositions( + pages, + indexWithinChapter, + viewModel.searchContentQuery + ) + ReadBook.skipToPage(positions[0]) { + launch { binding.readView.curPage.selectStartMoveIndex(0, positions[1], positions[2]) delay(20L) when (positions[3]) {