From 1c855d4f4ab43f325d5ae8e3aeb1cb744b608c5b Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 9 Sep 2020 18:07:14 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 908a968af..db721915a 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 @@ -189,7 +189,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { .getOrNull(0)?.let { if (it.name == name && (it.author == author || author == "")) { changeTo(it.toBook()) - return@forEach + return@execute } } } catch (e: Exception) { From ab2512e7e8af47d74c203e997aab4aa132f882cc Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 9 Sep 2020 20:04:46 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=8D=A2=E6=BA=90=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/data/entities/Book.kt | 17 ++++++++++++++++- .../ui/book/changesource/ChangeSourceDialog.kt | 15 ++------------- .../app/ui/book/read/ReadBookViewModel.kt | 4 +++- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/Book.kt b/app/src/main/java/io/legado/app/data/entities/Book.kt index c6c62aa4b..7996e3ea9 100644 --- a/app/src/main/java/io/legado/app/data/entities/Book.kt +++ b/app/src/main/java/io/legado/app/data/entities/Book.kt @@ -151,11 +151,26 @@ data class Book( delete() App.db.bookDao().insert(newBook) } - + fun delete() { if (ReadBook.book?.bookUrl == bookUrl) { ReadBook.book = null } App.db.bookDao().delete(this) } + + fun upInfoFromOld(oldBook: Book?) { + oldBook?.let { + group = oldBook.group + durChapterIndex = oldBook.durChapterIndex + durChapterPos = oldBook.durChapterPos + durChapterTitle = oldBook.durChapterTitle + customCoverUrl = oldBook.customCoverUrl + customIntro = oldBook.customIntro + order = oldBook.order + if (coverUrl.isNullOrEmpty()) { + coverUrl = oldBook.getDisplayCover() + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt index 7ebb4c0db..bbd627466 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt @@ -166,19 +166,8 @@ class ChangeSourceDialog : BaseDialogFragment(), override fun changeTo(searchBook: SearchBook) { val book = searchBook.toBook() - callBack?.oldBook?.let { oldBook -> - book.group = oldBook.group - book.durChapterIndex = oldBook.durChapterIndex - book.durChapterPos = oldBook.durChapterPos - book.durChapterTitle = oldBook.durChapterTitle - book.customCoverUrl = oldBook.customCoverUrl - book.customIntro = oldBook.customIntro - book.order = oldBook.order - if (book.coverUrl.isNullOrEmpty()) { - book.coverUrl = oldBook.getDisplayCover() - } - callBack?.changeTo(book) - } + book.upInfoFromOld(callBack?.oldBook) + callBack?.changeTo(book) dismiss() } 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 db721915a..0e2b4a050 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 @@ -188,7 +188,9 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { .searchBookSuspend(this, name, variableBook = variableBook) .getOrNull(0)?.let { if (it.name == name && (it.author == author || author == "")) { - changeTo(it.toBook()) + val book = it.toBook() + book.upInfoFromOld(ReadBook.book) + changeTo(book) return@execute } } From a0fc75ba37c57084d6385da6f191ab33216c9dcf Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 9 Sep 2020 20:57:19 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=8D=A2=E6=BA=90=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/ReadBookViewModel.kt | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) 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 0e2b4a050..7fcb65534 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 @@ -65,6 +65,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { ReadBook.loadContent(resetPageOffset = true) } } else { + ReadBook.book = book if (ReadBook.durChapterIndex != book.durChapterIndex) { ReadBook.durChapterIndex = book.durChapterIndex ReadBook.durPageIndex = book.durChapterPos @@ -72,7 +73,6 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { ReadBook.curTextChapter = null ReadBook.nextTextChapter = null } - ReadBook.book!!.group = book.group ReadBook.titleDate.postValue(book.name) ReadBook.upWebBook(book) isInitFinish = true @@ -160,20 +160,24 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { execute { ReadBook.upMsg(null) ReadBook.book?.changeTo(newBook) + ReadBook.book = newBook + App.db.bookSourceDao().getBookSource(newBook.origin)?.let { + ReadBook.webBook = WebBook(it) + } ReadBook.prevTextChapter = null ReadBook.curTextChapter = null ReadBook.nextTextChapter = null withContext(Main) { ReadBook.callBack?.upContent() } - ReadBook.book = newBook - App.db.bookSourceDao().getBookSource(newBook.origin)?.let { - ReadBook.webBook = WebBook(it) - } if (newBook.tocUrl.isEmpty()) { - loadBookInfo(newBook) { upChangeDurChapterIndex(newBook, it) } + loadBookInfo(newBook) { + upChangeDurChapterIndex(newBook, it) + } } else { - loadChapterList(newBook) { upChangeDurChapterIndex(newBook, it) } + loadChapterList(newBook) { + upChangeDurChapterIndex(newBook, it) + } } } } From 63ac140bf29e255e952f0354bb136ad9fc1058fb Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 9 Sep 2020 21:02:27 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=8D=A2=E6=BA=90=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt | 1 + 1 file changed, 1 insertion(+) 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 7fcb65534..fbdcebe65 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 @@ -221,6 +221,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { App.db.bookDao().update(book) App.db.bookChapterDao().insert(*chapters.toTypedArray()) ReadBook.chapterSize = chapters.size + ReadBook.upMsg(null) ReadBook.loadContent(resetPageOffset = true) } } From feea86ff144048a4bf59b8f62ab579729ee4e19d Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 9 Sep 2020 21:16:23 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=8D=A2=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 | 51 ++++++++++++------- 1 file changed, 33 insertions(+), 18 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 25858c022..0e6de3637 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 @@ -264,31 +264,46 @@ object ReadBook { private fun download(chapter: BookChapter, resetPageOffset: Boolean) { book?.let { book -> - webBook?.getContent(book, chapter) - ?.onSuccess(Dispatchers.IO) { content -> - if (content.isEmpty()) { + 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 { contentLoadFinish( book, chapter, - App.INSTANCE.getString(R.string.content_empty), + it.localizedMessage ?: "未知错误", resetPageOffset = resetPageOffset ) removeLoading(chapter.index) - } else { - BookHelp.saveContent(book, chapter, content) - contentLoadFinish(book, chapter, content, resetPageOffset = resetPageOffset) - removeLoading(chapter.index) } - }?.onError { - contentLoadFinish( - book, - chapter, - it.localizedMessage ?: "未知错误", - resetPageOffset = resetPageOffset - ) - removeLoading(chapter.index) - } - } + } ?: let { + contentLoadFinish( + book, + chapter, + "没有书源", + resetPageOffset = resetPageOffset + ) + removeLoading(chapter.index) + } + } ?: removeLoading(chapter.index) } private fun addLoading(index: Int): Boolean { From 01ce78cc5f46f1c79e4e9384f8105d6600ee123e Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 9 Sep 2020 21:23:00 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=8D=A2=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 { From 5c14b044eb2915236d01d61e251692e1d7b51e8e Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 9 Sep 2020 21:59:15 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=8D=A2=E6=BA=90=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/service/help/ReadBook.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 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 4eece2fb3..e8485261c 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 @@ -85,8 +85,10 @@ object ReadBook { } fun upMsg(msg: String?) { - this.msg = msg - callBack?.upContent() + if (this.msg != msg) { + this.msg = msg + callBack?.upContent() + } } fun moveToNextPage() { From f8b309d6efe6314b2e3d8a3481f2e74bbaa00331 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 9 Sep 2020 22:14:33 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=8D=A2=E6=BA=90=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 fbdcebe65..b8efe1cee 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 @@ -46,11 +46,11 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { private fun initBook(book: Book) { if (ReadBook.book?.bookUrl != book.bookUrl) { ReadBook.resetData(book) + isInitFinish = true if (!book.isLocalBook() && ReadBook.webBook == null) { autoChangeSource(book.name, book.author) return } - isInitFinish = true ReadBook.chapterSize = App.db.bookChapterDao().getChapterCount(book.bookUrl) if (ReadBook.chapterSize == 0) { if (book.tocUrl.isEmpty()) {