From a66a921e1e1c9a0e99172b11f0d73a575c65dd52 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 4 Nov 2019 16:11:02 +0800 Subject: [PATCH] up --- .../io/legado/app/ui/audio/AudioPlayActivity.kt | 5 +---- .../io/legado/app/ui/audio/AudioPlayViewModel.kt | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt b/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt index efe599857..c22ed4784 100644 --- a/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt +++ b/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt @@ -95,10 +95,7 @@ class AudioPlayActivity : VMBaseActivity(R.layout.activity_a override fun observeLiveBus() { observeEvent(Bus.AUDIO_NEXT) { - viewModel.durChapterIndex = viewModel.durChapterIndex + 1 - viewModel.bookData.value?.let { - viewModel.loadContent(it, viewModel.durChapterIndex) - } + viewModel.moveToNext() } observeEvent(Bus.AUDIO_STATE) { status = it diff --git a/app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt b/app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt index b7022cb82..458097f54 100644 --- a/app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt @@ -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 ->