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

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

Loading…
Cancel
Save