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.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")

@ -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)
}
}
.onError {
log(debugSource, it.msg, state = -1)

@ -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
}

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

@ -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)
} else {
context.toastOnUi(R.string.error_load_toc)
}
}.onError {
context.toastOnUi(R.string.error_load_toc)
}

@ -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)
}
}.onError {
it.printOnDebug()
}

@ -110,7 +110,6 @@ 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())
@ -120,9 +119,6 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
} else {
changeDruChapterIndex(it)
}
} else {
context.toastOnUi(R.string.chapter_list_empty)
}
}.onError {
chapterListData.postValue(emptyList())
context.toastOnUi(R.string.error_get_chapter_list)

Loading…
Cancel
Save