From 904cd0f1e259de80fadb94c1d5a540d57efdb6bb Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 14 Sep 2021 16:59:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/api/controller/BookController.kt | 12 ++---------- app/src/main/java/io/legado/app/model/Debug.kt | 12 ++++-------- .../io/legado/app/model/localBook/LocalBook.kt | 3 ++- .../app/model/webBook/BookChapterList.kt | 2 +- .../app/ui/book/audio/AudioPlayViewModel.kt | 12 ++++-------- .../book/changesource/ChangeSourceViewModel.kt | 8 +++----- .../app/ui/book/info/BookInfoViewModel.kt | 18 +++++++----------- 7 files changed, 23 insertions(+), 44 deletions(-) diff --git a/app/src/main/java/io/legado/app/api/controller/BookController.kt b/app/src/main/java/io/legado/app/api/controller/BookController.kt index 2ef0e2113..d235e878c 100644 --- a/app/src/main/java/io/legado/app/api/controller/BookController.kt +++ b/app/src/main/java/io/legado/app/api/controller/BookController.kt @@ -73,11 +73,7 @@ object BookController { appDb.bookChapterDao.delByBook(book.bookUrl) appDb.bookChapterDao.insert(*toc.toTypedArray()) appDb.bookDao.update(book) - return if (toc.isEmpty()) { - returnData.setErrorMsg(appCtx.getString(R.string.error_load_toc)) - } else { - returnData.setData(toc) - } + return returnData.setData(toc) } else { val bookSource = appDb.bookSourceDao.getBookSource(book.origin) ?: return returnData.setErrorMsg("未找到对应书源,请换源") @@ -90,11 +86,7 @@ object BookController { appDb.bookChapterDao.delByBook(book.bookUrl) appDb.bookChapterDao.insert(*toc.toTypedArray()) appDb.bookDao.update(book) - return if (toc.isEmpty()) { - returnData.setErrorMsg(appCtx.getString(R.string.error_load_toc)) - } else { - returnData.setData(toc) - } + return returnData.setData(toc) } } catch (e: Exception) { return returnData.setErrorMsg(e.localizedMessage ?: "refresh toc error") diff --git a/app/src/main/java/io/legado/app/model/Debug.kt b/app/src/main/java/io/legado/app/model/Debug.kt index 959a05972..cc39171c0 100644 --- a/app/src/main/java/io/legado/app/model/Debug.kt +++ b/app/src/main/java/io/legado/app/model/Debug.kt @@ -251,14 +251,10 @@ object Debug { log(debugSource, "︾开始解析目录页") val chapterList = WebBook.getChapterList(scope, bookSource, book) .onSuccess { - if (it.isNotEmpty()) { - log(debugSource, "︽目录页解析完成") - log(debugSource, showTime = false) - val nextChapterUrl = it.getOrNull(1)?.url - contentDebug(scope, bookSource, book, it[0], nextChapterUrl) - } else { - log(debugSource, "︽目录列表为空", state = -1) - } + log(debugSource, "︽目录页解析完成") + log(debugSource, showTime = false) + val nextChapterUrl = it.getOrNull(1)?.url + contentDebug(scope, bookSource, book, it[0], nextChapterUrl) } .onError { log(debugSource, it.msg, state = -1) diff --git a/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt b/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt index 9c566e957..8ef90ad73 100644 --- a/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt +++ b/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt @@ -2,6 +2,7 @@ package io.legado.app.model.localBook import android.net.Uri import androidx.documentfile.provider.DocumentFile +import io.legado.app.R import io.legado.app.constant.AppConst import io.legado.app.constant.AppPattern import io.legado.app.data.appDb @@ -37,7 +38,7 @@ object LocalBook { } } if (chapters.isEmpty()) { - throw AppException("目录为空") + throw AppException(appCtx.getString(R.string.chapter_list_empty)) } return chapters } diff --git a/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt b/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt index 59a63a9be..5af755625 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt @@ -99,7 +99,7 @@ object BookChapterList { } } if (chapterList.isEmpty()) { - throw AppException("目录为空") + throw AppException(appCtx.getString(R.string.chapter_list_empty)) } //去重 if (!reverse) { diff --git a/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayViewModel.kt b/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayViewModel.kt index 7e39f94bb..a21cb3364 100644 --- a/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayViewModel.kt @@ -66,16 +66,12 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application) AudioPlay.bookSource?.let { WebBook.getChapterList(this, it, book) .onSuccess(Dispatchers.IO) { cList -> - if (cList.isNotEmpty()) { - if (changeDruChapterIndex == null) { - appDb.bookChapterDao.insert(*cList.toTypedArray()) - } else { - changeDruChapterIndex(cList) - } - AudioPlay.upDurChapter(book) + if (changeDruChapterIndex == null) { + appDb.bookChapterDao.insert(*cList.toTypedArray()) } else { - context.toastOnUi(R.string.error_load_toc) + changeDruChapterIndex(cList) } + AudioPlay.upDurChapter(book) }.onError { context.toastOnUi(R.string.error_load_toc) } diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt index ec9eb6bc2..d1680727e 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt @@ -192,11 +192,9 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio private fun loadBookToc(source: BookSource, book: Book) { WebBook.getChapterList(viewModelScope, source, book) .onSuccess(IO) { chapters -> - if (chapters.isNotEmpty()) { - book.latestChapterTitle = chapters.last().title - val searchBook: SearchBook = book.toSearchBook() - searchFinish(searchBook) - } + book.latestChapterTitle = chapters.last().title + val searchBook: SearchBook = book.toSearchBook() + searchFinish(searchBook) }.onError { it.printOnDebug() } diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt index 214bf10c3..4a6daad01 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt @@ -110,18 +110,14 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { bookSource?.let { bookSource -> WebBook.getChapterList(this, bookSource, book) .onSuccess(IO) { - if (it.isNotEmpty()) { - if (inBookshelf) { - appDb.bookDao.update(book) - appDb.bookChapterDao.insert(*it.toTypedArray()) - } - if (changeDruChapterIndex == null) { - chapterListData.postValue(it) - } else { - changeDruChapterIndex(it) - } + if (inBookshelf) { + appDb.bookDao.update(book) + appDb.bookChapterDao.insert(*it.toTypedArray()) + } + if (changeDruChapterIndex == null) { + chapterListData.postValue(it) } else { - context.toastOnUi(R.string.chapter_list_empty) + changeDruChapterIndex(it) } }.onError { chapterListData.postValue(emptyList())