diff --git a/app/src/main/java/io/legado/app/constant/Bus.kt b/app/src/main/java/io/legado/app/constant/Bus.kt index e84d4b8c3..562da87ed 100644 --- a/app/src/main/java/io/legado/app/constant/Bus.kt +++ b/app/src/main/java/io/legado/app/constant/Bus.kt @@ -8,7 +8,7 @@ object Bus { const val TTS_NEXT = "ttsNextPage" const val BATTERY_CHANGED = "batteryChanged" const val TIME_CHANGED = "timeChanged" - const val READ_ALOUD = "readAloud" + const val READ_ALOUD_BUTTON = "readAloudButton" const val UP_CONFIG = "upConfig" const val OPEN_CHAPTER = "openChapter" } \ No newline at end of file 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 f1cbfb52c..2e6d33712 100644 --- a/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt +++ b/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt @@ -50,7 +50,7 @@ class MediaButtonReceiver : BroadcastReceiver() { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) context.startActivity(intent) } - postEvent(Bus.READ_ALOUD, true) + postEvent(Bus.READ_ALOUD_BUTTON, true) } } diff --git a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt index 0dd3790eb..ae660a2a6 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt @@ -53,7 +53,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea private val requestCodeEditSource = 111 private var changeSourceDialog: ChangeSourceDialog? = null private var timeElectricityReceiver: TimeElectricityReceiver? = null - private var readAloudStatus = Status.STOP + var readAloudStatus = Status.STOP override fun onActivityCreated(savedInstanceState: Bundle?) { setSupportActionBar(toolbar) @@ -420,7 +420,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea viewModel.openChapter(it) page_view.upContent() } - observeEvent(Bus.READ_ALOUD) { onClickReadAloud() } + observeEvent(Bus.READ_ALOUD_BUTTON) { onClickReadAloud() } observeEvent(Bus.UP_CONFIG) { Help.upSystemUiVisibility(window, !read_menu.isVisible) page_view.upBg() diff --git a/app/src/main/java/io/legado/app/ui/readbook/ReadMenu.kt b/app/src/main/java/io/legado/app/ui/readbook/ReadMenu.kt index 256e02cb3..630735701 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/ReadMenu.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/ReadMenu.kt @@ -153,7 +153,7 @@ class ReadMenu : FrameLayout { //朗读 ll_read_aloud.onClick { runMenuOut { - postEvent(Bus.READ_ALOUD, true) + postEvent(Bus.READ_ALOUD_BUTTON, true) } } diff --git a/app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudDialog.kt b/app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudDialog.kt index 41015b5f2..02de1d2a1 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudDialog.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudDialog.kt @@ -9,10 +9,14 @@ import android.view.ViewGroup import androidx.fragment.app.DialogFragment import io.legado.app.R import io.legado.app.constant.Bus +import io.legado.app.constant.Status import io.legado.app.service.ReadAloudService import io.legado.app.ui.readbook.Help import io.legado.app.ui.readbook.ReadBookActivity +import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.observeEvent +import io.legado.app.utils.postEvent +import io.legado.app.utils.putPrefBoolean import kotlinx.android.synthetic.main.activity_read_book.* import kotlinx.android.synthetic.main.dialog_read_aloud.* import org.jetbrains.anko.sdk27.listeners.onClick @@ -46,12 +50,33 @@ class ReadAloudDialog : DialogFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) initData() + initOnChange() initOnClick() } private fun initData() { - observeEvent(Bus.ALOUD_STATE) {} + observeEvent(Bus.ALOUD_STATE) { upPlayState(it) } + val activity = activity + if (activity is ReadBookActivity) { + upPlayState(activity.readAloudStatus) + } + cb_by_page.isChecked = requireContext().getPrefBoolean("readAloudByPage") + cb_tts_follow_sys.isChecked = requireContext().getPrefBoolean("ttsFollowSys", true) + seek_tts_SpeechRate.isEnabled = !cb_tts_follow_sys.isChecked + } + private fun initOnChange() { + cb_by_page.setOnCheckedChangeListener { buttonView, isChecked -> + if (buttonView.isPressed) { + requireContext().putPrefBoolean("readAloudByPage", isChecked) + } + } + cb_tts_follow_sys.setOnCheckedChangeListener { buttonView, isChecked -> + if (buttonView.isPressed) { + requireContext().putPrefBoolean("ttsFollowSys", isChecked) + seek_tts_SpeechRate.isEnabled = !isChecked + } + } } private fun initOnClick() { @@ -63,6 +88,15 @@ class ReadAloudDialog : DialogFragment() { } } iv_stop.onClick { ReadAloudService.stop(requireContext()) } + iv_play_pause.onClick { postEvent(Bus.READ_ALOUD_BUTTON, true) } + } + + private fun upPlayState(state: Int) { + if (state == Status.PAUSE) { + iv_play_pause.setImageResource(R.drawable.ic_play_24dp) + } else { + iv_play_pause.setImageResource(R.drawable.ic_pause_24dp) + } } } \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_read_aloud.xml b/app/src/main/res/layout/dialog_read_aloud.xml index 1e7a2c25b..e172e551b 100644 --- a/app/src/main/res/layout/dialog_read_aloud.xml +++ b/app/src/main/res/layout/dialog_read_aloud.xml @@ -75,6 +75,7 @@ android:layout_weight="1" />