修复自动换源的bug

pull/370/head
gedoor 4 years ago
parent 63ac140bf2
commit feea86ff14
  1. 51
      app/src/main/java/io/legado/app/service/help/ReadBook.kt

@ -264,31 +264,46 @@ object ReadBook {
private fun download(chapter: BookChapter, resetPageOffset: Boolean) { private fun download(chapter: BookChapter, resetPageOffset: Boolean) {
book?.let { book -> book?.let { book ->
webBook?.getContent(book, chapter) webBook?.let {
?.onSuccess(Dispatchers.IO) { content -> it.getContent(book, chapter)
if (content.isEmpty()) { .onSuccess(Dispatchers.IO) { content ->
if (content.isEmpty()) {
contentLoadFinish(
book,
chapter,
App.INSTANCE.getString(R.string.content_empty),
resetPageOffset = resetPageOffset
)
removeLoading(chapter.index)
} else {
BookHelp.saveContent(book, chapter, content)
contentLoadFinish(
book,
chapter,
content,
resetPageOffset = resetPageOffset
)
removeLoading(chapter.index)
}
}.onError {
contentLoadFinish( contentLoadFinish(
book, book,
chapter, chapter,
App.INSTANCE.getString(R.string.content_empty), it.localizedMessage ?: "未知错误",
resetPageOffset = resetPageOffset resetPageOffset = resetPageOffset
) )
removeLoading(chapter.index) removeLoading(chapter.index)
} else {
BookHelp.saveContent(book, chapter, content)
contentLoadFinish(book, chapter, content, resetPageOffset = resetPageOffset)
removeLoading(chapter.index)
} }
}?.onError { } ?: let {
contentLoadFinish( contentLoadFinish(
book, book,
chapter, chapter,
it.localizedMessage ?: "未知错误", "没有书源",
resetPageOffset = resetPageOffset resetPageOffset = resetPageOffset
) )
removeLoading(chapter.index) removeLoading(chapter.index)
} }
} } ?: removeLoading(chapter.index)
} }
private fun addLoading(index: Int): Boolean { private fun addLoading(index: Int): Boolean {

Loading…
Cancel
Save