From a53017be90407763f3a4cc0d33fac08ecf04cf03 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 16 Dec 2019 17:52:01 +0800 Subject: [PATCH] up --- .../io/legado/app/service/AudioPlayService.kt | 15 ++------------- .../java/io/legado/app/service/help/AudioPlay.kt | 8 -------- .../io/legado/app/ui/audio/AudioPlayActivity.kt | 12 +++++++++++- .../io/legado/app/ui/audio/AudioPlayViewModel.kt | 5 ++++- 4 files changed, 17 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/AudioPlayService.kt b/app/src/main/java/io/legado/app/service/AudioPlayService.kt index 0856ca100..2cedf7542 100644 --- a/app/src/main/java/io/legado/app/service/AudioPlayService.kt +++ b/app/src/main/java/io/legado/app/service/AudioPlayService.kt @@ -45,10 +45,10 @@ class AudioPlayService : BaseService(), companion object { var isRun = false + var pause = false var timeMinute: Int = 0 } - var pause = false private val handler = Handler() private lateinit var audioManager: AudioManager private var mFocusRequest: AudioFocusRequest? = null @@ -92,7 +92,6 @@ class AudioPlayService : BaseService(), Action.prev -> moveToPrev() Action.next -> moveToNext() Action.adjustSpeed -> upSpeed(intent.getFloatExtra("adjust", 1f)) - Action.moveTo -> moveTo(intent.getIntExtra("index", AudioPlay.durChapterIndex)) Action.addTimer -> addTimer() Action.setTimer -> setTimer(intent.getIntExtra("minute", 0)) Action.adjustProgress -> adjustProgress(intent.getIntExtra("position", position)) @@ -135,7 +134,7 @@ class AudioPlayService : BaseService(), } private fun pause(pause: Boolean) { - this.pause = pause + AudioPlayService.pause = pause handler.removeCallbacks(mpRunnable) position = mediaPlayer.currentPosition mediaPlayer.pause() @@ -313,16 +312,6 @@ class AudioPlayService : BaseService(), } } - private fun moveTo(index: Int) { - mediaPlayer.pause() - AudioPlay.durChapterIndex = index - AudioPlay.durPageIndex = 0 - AudioPlay.book?.durChapterIndex = AudioPlay.durChapterIndex - saveRead() - position = 0 - loadContent(AudioPlay.durChapterIndex) - } - private fun moveToPrev() { if (AudioPlay.durChapterIndex > 0) { mediaPlayer.pause() diff --git a/app/src/main/java/io/legado/app/service/help/AudioPlay.kt b/app/src/main/java/io/legado/app/service/help/AudioPlay.kt index 67d9d7658..add1a3fab 100644 --- a/app/src/main/java/io/legado/app/service/help/AudioPlay.kt +++ b/app/src/main/java/io/legado/app/service/help/AudioPlay.kt @@ -89,12 +89,4 @@ object AudioPlay { } } - fun moveTo(context: Context, index: Int) { - if (AudioPlayService.isRun) { - val intent = Intent(context, AudioPlayService::class.java) - intent.action = Action.moveTo - intent.putExtra("index", index) - context.startService(intent) - } - } } \ No newline at end of file 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 1524ac422..2b27a1600 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 @@ -22,6 +22,7 @@ import io.legado.app.help.ImageLoader import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.okButton +import io.legado.app.service.AudioPlayService import io.legado.app.service.help.AudioPlay import io.legado.app.ui.changesource.ChangeSourceDialog import io.legado.app.ui.chapterlist.ChapterListActivity @@ -172,7 +173,16 @@ class AudioPlayActivity : VMBaseActivity(R.layout.activity_a when (requestCode) { requestCodeChapter -> data?.getIntExtra("index", AudioPlay.durChapterIndex)?.let { if (it != AudioPlay.durChapterIndex) { - AudioPlay.moveTo(this, it) + val isPlay = !AudioPlayService.pause + AudioPlay.pause(this) + AudioPlay.status = Status.STOP + AudioPlay.durChapterIndex = it + AudioPlay.durPageIndex = 0 + AudioPlay.book?.durChapterIndex = AudioPlay.durChapterIndex + viewModel.saveRead() + if (isPlay) { + AudioPlay.play(this) + } } } } 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 c236ef787..5adc2c7be 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 @@ -124,13 +124,16 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application) } } - private fun saveRead() { + fun saveRead() { execute { AudioPlay.book?.let { book -> book.lastCheckCount = 0 book.durChapterTime = System.currentTimeMillis() book.durChapterIndex = AudioPlay.durChapterIndex book.durChapterPos = AudioPlay.durPageIndex + App.db.bookChapterDao().getChapter(book.bookUrl, book.durChapterIndex)?.let { + book.durChapterTitle = it.title + } App.db.bookDao().update(book) } }