|
|
@ -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() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|