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. 12
      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. 12
      app/src/main/java/io/legado/app/ui/book/audio/AudioPlayViewModel.kt
  6. 8
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt
  7. 18
      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)
}
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)

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

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

@ -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())

Loading…
Cancel
Save