pull/1759/head
kunfei 3 years ago
parent aa6039273d
commit 3a2ed37f1f
  1. 4
      app/src/main/java/io/legado/app/data/entities/Book.kt
  2. 2
      app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt
  3. 4
      app/src/main/java/io/legado/app/ui/book/audio/AudioPlayViewModel.kt
  4. 11
      app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt
  5. 1
      app/src/main/java/io/legado/app/ui/book/manage/BookshelfManageViewModel.kt
  6. 1
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  7. 3
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt

@ -287,10 +287,6 @@ data class Book(
newBook.customTag = customTag
newBook.canUpdate = canUpdate
newBook.readConfig = readConfig
if (appDb.bookDao.has(bookUrl) == true) {
delete()
appDb.bookDao.insert(newBook)
}
return newBook
}

@ -16,6 +16,7 @@ import io.legado.app.constant.BookType
import io.legado.app.constant.EventBus
import io.legado.app.constant.Status
import io.legado.app.constant.Theme
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
import io.legado.app.data.entities.BookSource
@ -212,6 +213,7 @@ class AudioPlayActivity :
launch {
withContext(IO) {
AudioPlay.book?.changeTo(book, toc)
appDb.bookDao.insert(book)
}
startActivity<ReadBookActivity> {
putExtra("bookUrl", book.bookUrl)

@ -78,7 +78,9 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
fun changeTo(source: BookSource, book: Book, toc: List<BookChapter>) {
execute {
AudioPlay.book = AudioPlay.book!!.changeTo(book, toc)
AudioPlay.book?.changeTo(book, toc)
appDb.bookDao.insert(book)
AudioPlay.book = book
AudioPlay.bookSource = source
appDb.bookChapterDao.insert(*toc.toTypedArray())
AudioPlay.upDurChapter(book)

@ -178,18 +178,19 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
}
}
fun changeTo(source: BookSource, newBook: Book, toc: List<BookChapter>) {
fun changeTo(source: BookSource, book: Book, toc: List<BookChapter>) {
changeSourceCoroutine?.cancel()
changeSourceCoroutine = execute {
bookSource = source
bookData.value!!.changeTo(newBook, toc)
bookData.postValue(newBook)
chapterListData.postValue(toc)
bookData.value?.changeTo(book, toc)
if (inBookshelf) {
appDb.bookDao.insert(book)
appDb.bookChapterDao.insert(*toc.toTypedArray())
}
bookData.postValue(book)
chapterListData.postValue(toc)
}.onFinally {
postEvent(EventBus.SOURCE_CHANGED, newBook.bookUrl)
postEvent(EventBus.SOURCE_CHANGED, book.bookUrl)
}
}

@ -50,6 +50,7 @@ class BookshelfManageViewModel(application: Application) : BaseViewModel(applica
.getOrNull()?.let { newBook ->
val toc = WebBook.getChapterListAwait(this, source, newBook)
book.changeTo(newBook, toc)
appDb.bookDao.insert(newBook)
appDb.bookChapterDao.insert(*toc.toTypedArray())
}
}

@ -724,6 +724,7 @@ class ReadBookActivity : BaseReadBookActivity(),
ReadAloud.stop(this)
launch {
ReadBook.book?.changeTo(book, toc)
appDb.bookDao.insert(book)
}
startActivity<AudioPlayActivity> {
putExtra("bookUrl", book.bookUrl)

@ -195,7 +195,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
changeSourceCoroutine?.cancel()
changeSourceCoroutine = execute {
ReadBook.upMsg(context.getString(R.string.loading))
ReadBook.book!!.changeTo(book, toc)
ReadBook.book?.changeTo(book, toc)
val nextChapter = toc.getOrElse(book.durChapterIndex) {
toc.first()
}
@ -206,6 +206,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
bookChapter = toc[book.durChapterIndex],
nextChapterUrl = nextChapter.url
)
appDb.bookDao.insert(book)
appDb.bookChapterDao.insert(*toc.toTypedArray())
ReadBook.resetData(book)
ReadBook.upMsg(null)

Loading…
Cancel
Save