From 70f2353136660f28ae21a91e36e02cfd71a987f5 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 4 Nov 2019 17:20:35 +0800 Subject: [PATCH] up --- .../app/receiver/MediaButtonReceiver.kt | 2 +- .../legado/app/ui/audio/AudioPlayActivity.kt | 21 ++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt b/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt index 586d13423..1df892cda 100644 --- a/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt +++ b/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt @@ -34,7 +34,7 @@ class MediaButtonReceiver : BroadcastReceiver() { private fun readAloud(context: Context) { if (ActivityHelp.isExist(AudioPlayActivity::class.java)) { - postEvent(Bus.READ_ALOUD_BUTTON, true) + postEvent(Bus.AUDIO_PLAY_BUTTON, true) } else if (!ActivityHelp.isExist(ReadBookActivity::class.java)) { val intent = Intent(context, ReadBookActivity::class.java) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) 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 092a49c09..73ed2b909 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 @@ -37,13 +37,7 @@ class AudioPlayActivity : VMBaseActivity(R.layout.activity_a private fun initView() { fab_play_stop.onClick { - when (status) { - Status.PLAY -> AudioPlay.pause(this) - Status.PAUSE -> AudioPlay.resume(this) - else -> viewModel.bookData.value?.let { - viewModel.loadContent(it, viewModel.durChapterIndex) - } - } + playButton() } fab_play_stop.onLongClick { AudioPlay.stop(this) @@ -80,6 +74,16 @@ class AudioPlayActivity : VMBaseActivity(R.layout.activity_a .setAsDrawable(iv_cover) } + private fun playButton() { + when (status) { + Status.PLAY -> AudioPlay.pause(this) + Status.PAUSE -> AudioPlay.resume(this) + else -> viewModel.bookData.value?.let { + viewModel.loadContent(it, viewModel.durChapterIndex) + } + } + } + override fun contentLoadFinish(bookChapter: BookChapter, content: String) { AudioPlay.play( this, @@ -94,6 +98,9 @@ class AudioPlayActivity : VMBaseActivity(R.layout.activity_a } override fun observeLiveBus() { + observeEvent(Bus.AUDIO_PLAY_BUTTON) { + playButton() + } observeEvent(Bus.AUDIO_NEXT) { viewModel.moveToNext() }