pull/508/head
gedoor 4 years ago
parent f3ef37edff
commit ed61b63975
  1. 30
      app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt

@ -16,27 +16,27 @@ import kotlinx.coroutines.Dispatchers
class AudioPlayViewModel(application: Application) : BaseViewModel(application) { class AudioPlayViewModel(application: Application) : BaseViewModel(application) {
fun initData(intent: Intent) { fun initData(intent: Intent) = AudioPlay.apply {
execute { execute {
val bookUrl = intent.getStringExtra("bookUrl") val bookUrl = intent.getStringExtra("bookUrl")
if (AudioPlay.book?.bookUrl != bookUrl) { if (book?.bookUrl != bookUrl) {
AudioPlay.stop(context) stop(context)
AudioPlay.inBookshelf = intent.getBooleanExtra("inBookshelf", true) inBookshelf = intent.getBooleanExtra("inBookshelf", true)
AudioPlay.book = if (!bookUrl.isNullOrEmpty()) { book = if (!bookUrl.isNullOrEmpty()) {
App.db.bookDao().getBook(bookUrl) App.db.bookDao().getBook(bookUrl)
} else { } else {
App.db.bookDao().lastReadBook App.db.bookDao().lastReadBook
} }
AudioPlay.book?.let { book -> book?.let { book ->
AudioPlay.titleData.postValue(book.name) titleData.postValue(book.name)
AudioPlay.coverData.postValue(book.getDisplayCover()) coverData.postValue(book.getDisplayCover())
AudioPlay.durChapterIndex = book.durChapterIndex durChapterIndex = book.durChapterIndex
AudioPlay.durPageIndex = book.durChapterPos durPageIndex = book.durChapterPos
App.db.bookChapterDao().getChapter(book.bookUrl, book.durChapterIndex)?.let { App.db.bookChapterDao().getChapter(book.bookUrl, book.durChapterIndex)?.let {
postEvent(EventBus.AUDIO_SUB_TITLE, it.title) postEvent(EventBus.AUDIO_SUB_TITLE, it.title)
} }
App.db.bookSourceDao().getBookSource(book.origin)?.let { App.db.bookSourceDao().getBookSource(book.origin)?.let {
AudioPlay.webBook = WebBook(it) webBook = WebBook(it)
} }
val count = App.db.bookChapterDao().getChapterCount(book.bookUrl) val count = App.db.bookChapterDao().getChapterCount(book.bookUrl)
if (count == 0) { if (count == 0) {
@ -46,13 +46,13 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
loadChapterList(book) loadChapterList(book)
} }
} else { } else {
if (AudioPlay.durChapterIndex > count - 1) { if (durChapterIndex > count - 1) {
AudioPlay.durChapterIndex = count - 1 durChapterIndex = count - 1
} }
AudioPlay.chapterSize = count chapterSize = count
} }
} }
AudioPlay.saveRead() saveRead()
} }
} }
} }

Loading…
Cancel
Save