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() { override fun observeLiveBus() {
observeEvent<Int>(Bus.AUDIO_NEXT) { observeEvent<Int>(Bus.AUDIO_NEXT) {
viewModel.durChapterIndex = viewModel.durChapterIndex + 1 viewModel.moveToNext()
viewModel.bookData.value?.let {
viewModel.loadContent(it, viewModel.durChapterIndex)
}
} }
observeEvent<Int>(Bus.AUDIO_STATE) { observeEvent<Int>(Bus.AUDIO_STATE) {
status = it status = it

@ -11,6 +11,7 @@ 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 import io.legado.app.model.WebBook
import io.legado.app.service.help.AudioPlay
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext 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) { fun saveRead(book: Book? = bookData.value) {
execute { execute {
book?.let { book -> book?.let { book ->

Loading…
Cancel
Save