pull/525/head
gedoor 4 years ago
parent 56b85eeb92
commit d05b594271
  1. 10
      app/src/main/java/io/legado/app/service/help/AudioPlay.kt
  2. 16
      app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt

@ -45,6 +45,7 @@ object AudioPlay {
fun upDurChapter(book: Book) {
durChapter = App.db.bookChapterDao.getChapter(book.bookUrl, durChapterIndex)
postEvent(EventBus.AUDIO_SUB_TITLE, durChapter?.title ?: "")
postEvent(EventBus.AUDIO_SIZE, durChapter?.end?.toInt() ?: 0)
postEvent(EventBus.AUDIO_PROGRESS, durChapterPos)
}
@ -100,9 +101,6 @@ object AudioPlay {
book.durChapterIndex = durChapterIndex
book.durChapterPos = 0
saveRead()
App.db.bookChapterDao.getChapter(book.bookUrl, durChapterIndex)?.let { chapter ->
postEvent(EventBus.AUDIO_SUB_TITLE, chapter.title)
}
play(context)
}
}
@ -120,9 +118,6 @@ object AudioPlay {
book.durChapterIndex = durChapterIndex
book.durChapterPos = 0
saveRead()
App.db.bookChapterDao.getChapter(book.bookUrl, durChapterIndex)?.let { chapter ->
postEvent(EventBus.AUDIO_SUB_TITLE, chapter.title)
}
play(context)
}
}
@ -140,9 +135,6 @@ object AudioPlay {
book.durChapterIndex = durChapterIndex
book.durChapterPos = 0
saveRead()
App.db.bookChapterDao.getChapter(book.bookUrl, durChapterIndex)?.let { chapter ->
postEvent(EventBus.AUDIO_SUB_TITLE, chapter.title)
}
play(context)
}
}

@ -5,13 +5,11 @@ import android.content.Intent
import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.BaseViewModel
import io.legado.app.constant.EventBus
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
import io.legado.app.help.BookHelp
import io.legado.app.model.webBook.WebBook
import io.legado.app.service.help.AudioPlay
import io.legado.app.utils.postEvent
import kotlinx.coroutines.Dispatchers
class AudioPlayViewModel(application: Application) : BaseViewModel(application) {
@ -32,25 +30,17 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
coverData.postValue(book.getDisplayCover())
durChapterIndex = book.durChapterIndex
durChapterPos = book.durChapterPos
App.db.bookChapterDao.getChapter(book.bookUrl, book.durChapterIndex)?.let {
postEvent(EventBus.AUDIO_SUB_TITLE, it.title)
}
durChapter = App.db.bookChapterDao.getChapter(book.bookUrl, durChapterIndex)
upDurChapter(book)
App.db.bookSourceDao.getBookSource(book.origin)?.let {
webBook = WebBook(it)
}
val count = App.db.bookChapterDao.getChapterCount(book.bookUrl)
if (count == 0) {
if (durChapter == null) {
if (book.tocUrl.isEmpty()) {
loadBookInfo(book)
} else {
loadChapterList(book)
}
} else {
if (durChapterIndex > count - 1) {
durChapterIndex = count - 1
}
durChapter = App.db.bookChapterDao.getChapter(book.bookUrl, durChapterIndex)
upDurChapter(book)
}
}
saveRead()

Loading…
Cancel
Save