pull/1319/head
gedoor 3 years ago
parent 4b18cdf6cf
commit 904cd0f1e2
  1. 12
      app/src/main/java/io/legado/app/api/controller/BookController.kt
  2. 4
      app/src/main/java/io/legado/app/model/Debug.kt
  3. 3
      app/src/main/java/io/legado/app/model/localBook/LocalBook.kt
  4. 2
      app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt
  5. 4
      app/src/main/java/io/legado/app/ui/book/audio/AudioPlayViewModel.kt
  6. 2
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt
  7. 4
      app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt

@ -73,11 +73,7 @@ object BookController {
appDb.bookChapterDao.delByBook(book.bookUrl) appDb.bookChapterDao.delByBook(book.bookUrl)
appDb.bookChapterDao.insert(*toc.toTypedArray()) appDb.bookChapterDao.insert(*toc.toTypedArray())
appDb.bookDao.update(book) appDb.bookDao.update(book)
return if (toc.isEmpty()) { return returnData.setData(toc)
returnData.setErrorMsg(appCtx.getString(R.string.error_load_toc))
} else {
returnData.setData(toc)
}
} else { } else {
val bookSource = appDb.bookSourceDao.getBookSource(book.origin) val bookSource = appDb.bookSourceDao.getBookSource(book.origin)
?: return returnData.setErrorMsg("未找到对应书源,请换源") ?: return returnData.setErrorMsg("未找到对应书源,请换源")
@ -90,11 +86,7 @@ object BookController {
appDb.bookChapterDao.delByBook(book.bookUrl) appDb.bookChapterDao.delByBook(book.bookUrl)
appDb.bookChapterDao.insert(*toc.toTypedArray()) appDb.bookChapterDao.insert(*toc.toTypedArray())
appDb.bookDao.update(book) appDb.bookDao.update(book)
return if (toc.isEmpty()) { return returnData.setData(toc)
returnData.setErrorMsg(appCtx.getString(R.string.error_load_toc))
} else {
returnData.setData(toc)
}
} }
} catch (e: Exception) { } catch (e: Exception) {
return returnData.setErrorMsg(e.localizedMessage ?: "refresh toc error") return returnData.setErrorMsg(e.localizedMessage ?: "refresh toc error")

@ -251,14 +251,10 @@ object Debug {
log(debugSource, "︾开始解析目录页") log(debugSource, "︾开始解析目录页")
val chapterList = WebBook.getChapterList(scope, bookSource, book) val chapterList = WebBook.getChapterList(scope, bookSource, book)
.onSuccess { .onSuccess {
if (it.isNotEmpty()) {
log(debugSource, "︽目录页解析完成") log(debugSource, "︽目录页解析完成")
log(debugSource, showTime = false) log(debugSource, showTime = false)
val nextChapterUrl = it.getOrNull(1)?.url val nextChapterUrl = it.getOrNull(1)?.url
contentDebug(scope, bookSource, book, it[0], nextChapterUrl) contentDebug(scope, bookSource, book, it[0], nextChapterUrl)
} else {
log(debugSource, "︽目录列表为空", state = -1)
}
} }
.onError { .onError {
log(debugSource, it.msg, state = -1) log(debugSource, it.msg, state = -1)

@ -2,6 +2,7 @@ package io.legado.app.model.localBook
import android.net.Uri import android.net.Uri
import androidx.documentfile.provider.DocumentFile import androidx.documentfile.provider.DocumentFile
import io.legado.app.R
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
import io.legado.app.constant.AppPattern import io.legado.app.constant.AppPattern
import io.legado.app.data.appDb import io.legado.app.data.appDb
@ -37,7 +38,7 @@ object LocalBook {
} }
} }
if (chapters.isEmpty()) { if (chapters.isEmpty()) {
throw AppException("目录为空") throw AppException(appCtx.getString(R.string.chapter_list_empty))
} }
return chapters return chapters
} }

@ -99,7 +99,7 @@ object BookChapterList {
} }
} }
if (chapterList.isEmpty()) { if (chapterList.isEmpty()) {
throw AppException("目录为空") throw AppException(appCtx.getString(R.string.chapter_list_empty))
} }
//去重 //去重
if (!reverse) { if (!reverse) {

@ -66,16 +66,12 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
AudioPlay.bookSource?.let { AudioPlay.bookSource?.let {
WebBook.getChapterList(this, it, book) WebBook.getChapterList(this, it, book)
.onSuccess(Dispatchers.IO) { cList -> .onSuccess(Dispatchers.IO) { cList ->
if (cList.isNotEmpty()) {
if (changeDruChapterIndex == null) { if (changeDruChapterIndex == null) {
appDb.bookChapterDao.insert(*cList.toTypedArray()) appDb.bookChapterDao.insert(*cList.toTypedArray())
} else { } else {
changeDruChapterIndex(cList) changeDruChapterIndex(cList)
} }
AudioPlay.upDurChapter(book) AudioPlay.upDurChapter(book)
} else {
context.toastOnUi(R.string.error_load_toc)
}
}.onError { }.onError {
context.toastOnUi(R.string.error_load_toc) context.toastOnUi(R.string.error_load_toc)
} }

@ -192,11 +192,9 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
private fun loadBookToc(source: BookSource, book: Book) { private fun loadBookToc(source: BookSource, book: Book) {
WebBook.getChapterList(viewModelScope, source, book) WebBook.getChapterList(viewModelScope, source, book)
.onSuccess(IO) { chapters -> .onSuccess(IO) { chapters ->
if (chapters.isNotEmpty()) {
book.latestChapterTitle = chapters.last().title book.latestChapterTitle = chapters.last().title
val searchBook: SearchBook = book.toSearchBook() val searchBook: SearchBook = book.toSearchBook()
searchFinish(searchBook) searchFinish(searchBook)
}
}.onError { }.onError {
it.printOnDebug() it.printOnDebug()
} }

@ -110,7 +110,6 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
bookSource?.let { bookSource -> bookSource?.let { bookSource ->
WebBook.getChapterList(this, bookSource, book) WebBook.getChapterList(this, bookSource, book)
.onSuccess(IO) { .onSuccess(IO) {
if (it.isNotEmpty()) {
if (inBookshelf) { if (inBookshelf) {
appDb.bookDao.update(book) appDb.bookDao.update(book)
appDb.bookChapterDao.insert(*it.toTypedArray()) appDb.bookChapterDao.insert(*it.toTypedArray())
@ -120,9 +119,6 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
} else { } else {
changeDruChapterIndex(it) changeDruChapterIndex(it)
} }
} else {
context.toastOnUi(R.string.chapter_list_empty)
}
}.onError { }.onError {
chapterListData.postValue(emptyList()) chapterListData.postValue(emptyList())
context.toastOnUi(R.string.error_get_chapter_list) context.toastOnUi(R.string.error_get_chapter_list)

Loading…
Cancel
Save