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 1ef4a3caa..b7338596c 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 @@ -36,7 +36,7 @@ object ReadBook { var msg: String? = null private val loadingChapters = arrayListOf() - fun resetData(book: Book, noSource: (name: String, author: String) -> Unit) { + fun resetData(book: Book) { this.book = book titleDate.postValue(book.name) durChapterIndex = book.durChapterIndex @@ -46,20 +46,19 @@ object ReadBook { prevTextChapter = null curTextChapter = null nextTextChapter = null - upWebBook(book, noSource) + upWebBook(book) } - fun upWebBook(book: Book?, noSource: (name: String, author: String) -> Unit) { + fun upWebBook(book: Book?) { book ?: return - if (book.origin == BookType.local) { - webBook = null + webBook = if (book.origin == BookType.local) { + null } else { val bookSource = App.db.bookSourceDao().getBookSource(book.origin) if (bookSource != null) { - webBook = WebBook(bookSource) + WebBook(bookSource) } else { - webBook = null - noSource.invoke(book.name, book.author) + null } } } 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 bf6ad1925..d73ffd07a 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 @@ -40,8 +40,10 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { private fun initBook(book: Book) { if (ReadBook.book?.bookUrl != book.bookUrl) { - ReadBook.resetData(book) { name, author -> - autoChangeSource(name, author) + ReadBook.resetData(book) + if (ReadBook.webBook == null) { + autoChangeSource(book.name, book.author) + return } isInitFinish = true ReadBook.chapterSize = App.db.bookChapterDao().getChapterCount(book.bookUrl) @@ -63,8 +65,10 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { } else { isInitFinish = true ReadBook.titleDate.postValue(book.name) - ReadBook.upWebBook(book) { name, author -> - autoChangeSource(name, author) + ReadBook.upWebBook(book) + if (ReadBook.webBook == null) { + autoChangeSource(book.name, book.author) + return } ReadBook.chapterSize = App.db.bookChapterDao().getChapterCount(book.bookUrl) if (ReadBook.chapterSize == 0) {