pull/811/head
gedoor 4 years ago
parent d3e0a1f605
commit 14bc109a2b
  1. 32
      app/src/main/java/io/legado/app/service/help/ReadBook.kt
  2. 10
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  3. 6
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt
  4. 1
      app/src/main/res/values/pref_key_value.xml
  5. 6
      app/src/main/res/xml/about.xml

@ -240,19 +240,28 @@ object ReadBook {
/** /**
* 加载章节内容 * 加载章节内容
*/ */
fun loadContent(resetPageOffset: Boolean) { fun loadContent(resetPageOffset: Boolean, success: (() -> Unit)? = null) {
loadContent(durChapterIndex, resetPageOffset = resetPageOffset) loadContent(durChapterIndex, resetPageOffset = resetPageOffset) {
success?.invoke()
}
loadContent(durChapterIndex + 1, resetPageOffset = resetPageOffset) loadContent(durChapterIndex + 1, resetPageOffset = resetPageOffset)
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 -> book?.let { book ->
if (addLoading(index)) { if (addLoading(index)) {
Coroutine.async { Coroutine.async {
App.db.bookChapterDao.getChapter(book.bookUrl, index)?.let { chapter -> App.db.bookChapterDao.getChapter(book.bookUrl, index)?.let { chapter ->
BookHelp.getContent(book, chapter)?.let { BookHelp.getContent(book, chapter)?.let {
contentLoadFinish(book, chapter, it, upContent, resetPageOffset) contentLoadFinish(book, chapter, it, upContent, resetPageOffset) {
success?.invoke()
}
removeLoading(chapter.index) removeLoading(chapter.index)
} ?: download(chapter, resetPageOffset = resetPageOffset) } ?: download(chapter, resetPageOffset = resetPageOffset)
} ?: removeLoading(index) } ?: 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 book = book
val webBook = webBook val webBook = webBook
if (book != null && webBook != null) { if (book != null && webBook != null) {
@ -290,7 +303,9 @@ object ReadBook {
} else if (book != null) { } else if (book != null) {
contentLoadFinish( contentLoadFinish(
book, chapter, "没有书源", resetPageOffset = resetPageOffset book, chapter, "没有书源", resetPageOffset = resetPageOffset
) ) {
success?.invoke()
}
removeLoading(chapter.index) removeLoading(chapter.index)
} else { } else {
removeLoading(chapter.index) removeLoading(chapter.index)
@ -379,7 +394,8 @@ object ReadBook {
chapter: BookChapter, chapter: BookChapter,
content: String, content: String,
upContent: Boolean = true, upContent: Boolean = true,
resetPageOffset: Boolean resetPageOffset: Boolean,
success: (() -> Unit)? = null
) { ) {
Coroutine.async { Coroutine.async {
ImageProvider.clearOut(durChapterIndex) ImageProvider.clearOut(durChapterIndex)
@ -420,6 +436,8 @@ object ReadBook {
}.onError { }.onError {
it.printStackTrace() it.printStackTrace()
App.INSTANCE.toast("ChapterProvider ERROR:\n${it.getStackTraceString()}") App.INSTANCE.toast("ChapterProvider ERROR:\n${it.getStackTraceString()}")
}.onSuccess {
success?.invoke()
} }
} }

@ -806,14 +806,9 @@ class ReadBookActivity : ReadBookBaseActivity(),
} }
private fun skipToSearch(index: Int, indexWithinChapter: Int) { private fun skipToSearch(index: Int, indexWithinChapter: Int) {
viewModel.openChapter(index) {
launch(IO) { launch(IO) {
viewModel.openChapter(index) val pages = ReadBook.curTextChapter?.pages ?: return@launch
// 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( val positions = ReadBook.searchResultPositions(
pages, pages,
indexWithinChapter, indexWithinChapter,
@ -846,6 +841,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
} }
} }
} }
}
override fun finish() { override fun finish() {
ReadBook.book?.let { ReadBook.book?.let {

@ -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.prevTextChapter = null
ReadBook.curTextChapter = null ReadBook.curTextChapter = null
ReadBook.nextTextChapter = null ReadBook.nextTextChapter = null
@ -260,7 +260,9 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
ReadBook.durChapterPos = durChapterPos ReadBook.durChapterPos = durChapterPos
} }
ReadBook.saveRead() ReadBook.saveRead()
ReadBook.loadContent(resetPageOffset = true) ReadBook.loadContent(resetPageOffset = true) {
success?.invoke()
}
} }
fun removeFromBookshelf(success: (() -> Unit)?) { fun removeFromBookshelf(success: (() -> Unit)?) {

@ -13,4 +13,5 @@
<string name="latest_release_url" translatable="false">https://github.com/gedoor/legado/releases/latest</string> <string name="latest_release_url" translatable="false">https://github.com/gedoor/legado/releases/latest</string>
<string name="latest_release_api" translatable="false">https://api.github.com/repos/gedoor/legado/releases/latest</string> <string name="latest_release_api" translatable="false">https://api.github.com/repos/gedoor/legado/releases/latest</string>
<string name="tg_url" translatable="false">https://t.me/yueduguanfang</string> <string name="tg_url" translatable="false">https://t.me/yueduguanfang</string>
<string name="discord_url" translatable="false">https://discord.gg/qDE52P5xGW</string>
</resources> </resources>

@ -53,6 +53,12 @@
android:summary="@string/this_github_url" android:summary="@string/this_github_url"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.Preference
android:key="discord"
android:title="Discord"
android:summary="@string/tg_url"
app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.Preference <io.legado.app.ui.widget.prefs.Preference
android:key="tg" android:key="tg"
android:title="TG" android:title="TG"

Loading…
Cancel
Save