From 01ce78cc5f46f1c79e4e9384f8105d6600ee123e Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 9 Sep 2020 21:23:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=87=AA=E5=8A=A8=E6=8D=A2?= =?UTF-8?q?=E6=BA=90=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/service/help/ReadBook.kt | 70 ++++++++++--------- 1 file changed, 36 insertions(+), 34 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 0e6de3637..4eece2fb3 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 @@ -263,47 +263,49 @@ object ReadBook { } private fun download(chapter: BookChapter, resetPageOffset: Boolean) { - book?.let { book -> - webBook?.let { - it.getContent(book, chapter) - .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 { + val book = book + val webBook = webBook + if (book != null && webBook != null) { + webBook.getContent(book, chapter) + .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, - it.localizedMessage ?: "未知错误", + content, resetPageOffset = resetPageOffset ) removeLoading(chapter.index) } - } ?: let { - contentLoadFinish( - book, - chapter, - "没有书源", - resetPageOffset = resetPageOffset - ) - removeLoading(chapter.index) - } - } ?: removeLoading(chapter.index) + }.onError { + contentLoadFinish( + book, + chapter, + it.localizedMessage ?: "未知错误", + resetPageOffset = resetPageOffset + ) + removeLoading(chapter.index) + } + } else if (book != null) { + contentLoadFinish( + book, + chapter, + "没有书源", + resetPageOffset = resetPageOffset + ) + removeLoading(chapter.index) + } else { + removeLoading(chapter.index) + } } private fun addLoading(index: Int): Boolean {