pull/32/head
kunfei 5 years ago
parent 543b3d51c7
commit 6fd47432cf
  1. 2
      app/src/main/java/io/legado/app/constant/Bus.kt
  2. 2
      app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt
  3. 4
      app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt
  4. 2
      app/src/main/java/io/legado/app/ui/readbook/ReadMenu.kt
  5. 36
      app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudDialog.kt
  6. 3
      app/src/main/res/layout/dialog_read_aloud.xml

@ -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"
}

@ -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)
}
}

@ -53,7 +53,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(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<ReadBookViewModel>(R.layout.activity_rea
viewModel.openChapter(it)
page_view.upContent()
}
observeEvent<Boolean>(Bus.READ_ALOUD) { onClickReadAloud() }
observeEvent<Boolean>(Bus.READ_ALOUD_BUTTON) { onClickReadAloud() }
observeEvent<Boolean>(Bus.UP_CONFIG) {
Help.upSystemUiVisibility(window, !read_menu.isVisible)
page_view.upBg()

@ -153,7 +153,7 @@ class ReadMenu : FrameLayout {
//朗读
ll_read_aloud.onClick {
runMenuOut {
postEvent(Bus.READ_ALOUD, true)
postEvent(Bus.READ_ALOUD_BUTTON, true)
}
}

@ -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<Int>(Bus.ALOUD_STATE) {}
observeEvent<Int>(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)
}
}
}

@ -75,6 +75,7 @@
android:layout_weight="1" />
<io.legado.app.lib.theme.view.ATECheckBox
android:id="@+id/cb_by_page"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@null"
@ -142,7 +143,7 @@
android:textSize="14sp" />
<io.legado.app.lib.theme.view.ATECheckBox
android:id="@+id/scb_tts_follow_sys"
android:id="@+id/cb_tts_follow_sys"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"

Loading…
Cancel
Save