pull/46/head
kunfei 5 years ago
parent 53cfcce85e
commit a66a921e1e
  1. 5
      app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt
  2. 14
      app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt

@ -95,10 +95,7 @@ class AudioPlayActivity : VMBaseActivity<AudioPlayViewModel>(R.layout.activity_a
override fun observeLiveBus() {
observeEvent<Int>(Bus.AUDIO_NEXT) {
viewModel.durChapterIndex = viewModel.durChapterIndex + 1
viewModel.bookData.value?.let {
viewModel.loadContent(it, viewModel.durChapterIndex)
}
viewModel.moveToNext()
}
observeEvent<Int>(Bus.AUDIO_STATE) {
status = it

@ -11,6 +11,7 @@ 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
import io.legado.app.service.help.AudioPlay
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
@ -183,6 +184,19 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
}
}
fun moveToNext() {
if (durChapterIndex < chapterSize - 1) {
durChapterIndex++
bookData.value?.let {
it.durChapterIndex = durChapterIndex
saveRead(it)
loadContent(it, durChapterIndex)
}
} else {
AudioPlay.stop(context)
}
}
fun saveRead(book: Book? = bookData.value) {
execute {
book?.let { book ->

Loading…
Cancel
Save