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 c76386bd6..512f7ff7e 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
@@ -240,19 +240,28 @@ object ReadBook {
/**
* 加载章节内容
*/
- fun loadContent(resetPageOffset: Boolean) {
- loadContent(durChapterIndex, resetPageOffset = resetPageOffset)
+ fun loadContent(resetPageOffset: Boolean, success: (() -> Unit)? = null) {
+ loadContent(durChapterIndex, resetPageOffset = resetPageOffset) {
+ success?.invoke()
+ }
loadContent(durChapterIndex + 1, resetPageOffset = resetPageOffset)
loadContent(durChapterIndex - 1, resetPageOffset = resetPageOffset)
}
- fun loadContent(index: Int, upContent: Boolean = true, resetPageOffset: Boolean) {
+ fun loadContent(
+ index: Int,
+ upContent: Boolean = true,
+ resetPageOffset: Boolean,
+ success: (() -> Unit)? = null
+ ) {
book?.let { book ->
if (addLoading(index)) {
Coroutine.async {
App.db.bookChapterDao.getChapter(book.bookUrl, index)?.let { chapter ->
BookHelp.getContent(book, chapter)?.let {
- contentLoadFinish(book, chapter, it, upContent, resetPageOffset)
+ contentLoadFinish(book, chapter, it, upContent, resetPageOffset) {
+ success?.invoke()
+ }
removeLoading(chapter.index)
} ?: download(chapter, resetPageOffset = resetPageOffset)
} ?: removeLoading(index)
@@ -282,7 +291,11 @@ object ReadBook {
}
}
- private fun download(chapter: BookChapter, resetPageOffset: Boolean) {
+ private fun download(
+ chapter: BookChapter,
+ resetPageOffset: Boolean,
+ success: (() -> Unit)? = null
+ ) {
val book = book
val webBook = webBook
if (book != null && webBook != null) {
@@ -290,7 +303,9 @@ object ReadBook {
} else if (book != null) {
contentLoadFinish(
book, chapter, "没有书源", resetPageOffset = resetPageOffset
- )
+ ) {
+ success?.invoke()
+ }
removeLoading(chapter.index)
} else {
removeLoading(chapter.index)
@@ -379,7 +394,8 @@ object ReadBook {
chapter: BookChapter,
content: String,
upContent: Boolean = true,
- resetPageOffset: Boolean
+ resetPageOffset: Boolean,
+ success: (() -> Unit)? = null
) {
Coroutine.async {
ImageProvider.clearOut(durChapterIndex)
@@ -420,6 +436,8 @@ object ReadBook {
}.onError {
it.printStackTrace()
App.INSTANCE.toast("ChapterProvider ERROR:\n${it.getStackTraceString()}")
+ }.onSuccess {
+ success?.invoke()
}
}
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 4a2c8db88..c46eb3dc4 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
@@ -806,43 +806,39 @@ class ReadBookActivity : ReadBookBaseActivity(),
}
private fun skipToSearch(index: Int, indexWithinChapter: Int) {
- launch(IO) {
- viewModel.openChapter(index)
- // block until load correct chapter and pages
- var pages = ReadBook.curTextChapter?.pages
- while (ReadBook.durChapterIndex != index || pages == null) {
- delay(100L)
- pages = ReadBook.curTextChapter?.pages
- }
- val positions = ReadBook.searchResultPositions(
- pages,
- indexWithinChapter,
- viewModel.searchContentQuery
- )
- while (ReadBook.durPageIndex() != positions[0]) {
- delay(100L)
- ReadBook.skipToPage(positions[0])
- }
- withContext(Main) {
- binding.readView.curPage.selectStartMoveIndex(0, positions[1], positions[2])
- delay(20L)
- when (positions[3]) {
- 0 -> binding.readView.curPage.selectEndMoveIndex(
- 0,
- positions[1],
- positions[2] + viewModel.searchContentQuery.length - 1
- )
- 1 -> binding.readView.curPage.selectEndMoveIndex(
- 0,
- positions[1] + 1,
- positions[4]
- )
- //consider change page, jump to scroll position
- -1 -> binding.readView.curPage
- .selectEndMoveIndex(1, 0, positions[4])
+ 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) {
+ binding.readView.curPage.selectStartMoveIndex(0, positions[1], positions[2])
+ delay(20L)
+ when (positions[3]) {
+ 0 -> binding.readView.curPage.selectEndMoveIndex(
+ 0,
+ positions[1],
+ positions[2] + viewModel.searchContentQuery.length - 1
+ )
+ 1 -> binding.readView.curPage.selectEndMoveIndex(
+ 0,
+ positions[1] + 1,
+ positions[4]
+ )
+ //consider change page, jump to scroll position
+ -1 -> binding.readView.curPage
+ .selectEndMoveIndex(1, 0, positions[4])
+ }
+ binding.readView.isTextSelected = true
+ delay(100L)
}
- binding.readView.isTextSelected = true
- delay(100L)
}
}
}
diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt
index 7e718ff36..d73f96658 100644
--- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt
+++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt
@@ -250,7 +250,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
}
}
- fun openChapter(index: Int, durChapterPos: Int = 0) {
+ fun openChapter(index: Int, durChapterPos: Int = 0, success: (() -> Unit)? = null) {
ReadBook.prevTextChapter = null
ReadBook.curTextChapter = null
ReadBook.nextTextChapter = null
@@ -260,7 +260,9 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
ReadBook.durChapterPos = durChapterPos
}
ReadBook.saveRead()
- ReadBook.loadContent(resetPageOffset = true)
+ ReadBook.loadContent(resetPageOffset = true) {
+ success?.invoke()
+ }
}
fun removeFromBookshelf(success: (() -> Unit)?) {
diff --git a/app/src/main/res/values/pref_key_value.xml b/app/src/main/res/values/pref_key_value.xml
index 78e9f018d..ebaac231b 100644
--- a/app/src/main/res/values/pref_key_value.xml
+++ b/app/src/main/res/values/pref_key_value.xml
@@ -13,4 +13,5 @@
https://github.com/gedoor/legado/releases/latest
https://api.github.com/repos/gedoor/legado/releases/latest
https://t.me/yueduguanfang
+ https://discord.gg/qDE52P5xGW
diff --git a/app/src/main/res/xml/about.xml b/app/src/main/res/xml/about.xml
index 847d8c7dc..69e339435 100644
--- a/app/src/main/res/xml/about.xml
+++ b/app/src/main/res/xml/about.xml
@@ -53,6 +53,12 @@
android:summary="@string/this_github_url"
app:iconSpaceReserved="false" />
+
+