pull/49/head
kunfei 5 years ago
parent c917671e3f
commit 0b8bcfb3d6
  1. 19
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  2. 14
      app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt

@ -63,7 +63,6 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
private val requestCodeChapterList = 568 private val requestCodeChapterList = 568
private val requestCodeEditSource = 111 private val requestCodeEditSource = 111
private var timeElectricityReceiver: TimeElectricityReceiver? = null private var timeElectricityReceiver: TimeElectricityReceiver? = null
override var readAloudStatus = Status.STOP
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
Help.upLayoutInDisplayCutoutMode(window) Help.upLayoutInDisplayCutoutMode(window)
@ -215,7 +214,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
&& event.isTracking && event.isTracking
&& !event.isCanceled && !event.isCanceled
) { ) {
if (readAloudStatus == Status.PLAY) { if (!BaseReadAloudService.pause) {
ReadAloud.pause(this) ReadAloud.pause(this)
toast(R.string.read_aloud_pause) toast(R.string.read_aloud_pause)
return true return true
@ -231,7 +230,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
if (!read_menu.isVisible) { if (!read_menu.isVisible) {
if (getPrefBoolean("volumeKeyPage", true)) { if (getPrefBoolean("volumeKeyPage", true)) {
if (getPrefBoolean("volumeKeyPageOnPlay") if (getPrefBoolean("volumeKeyPageOnPlay")
|| readAloudStatus != Status.PLAY || BaseReadAloudService.pause
) { ) {
when (direction) { when (direction) {
PageDelegate.Direction.PREV -> page_view.moveToPrevPage() PageDelegate.Direction.PREV -> page_view.moveToPrevPage()
@ -374,7 +373,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
} }
override fun clickCenter() { override fun clickCenter() {
if (readAloudStatus != Status.STOP) { if (BaseReadAloudService.isRun) {
showReadAloudDialog() showReadAloudDialog()
} else { } else {
read_menu.runMenuIn() read_menu.runMenuIn()
@ -426,13 +425,12 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
*/ */
override fun onClickReadAloud() { override fun onClickReadAloud() {
if (!BaseReadAloudService.isRun) { if (!BaseReadAloudService.isRun) {
readAloudStatus = Status.STOP
SystemUtils.ignoreBatteryOptimization(this) SystemUtils.ignoreBatteryOptimization(this)
} }
when (readAloudStatus) { when {
Status.STOP -> ReadBook.readAloud() !BaseReadAloudService.isRun -> ReadBook.readAloud()
Status.PLAY -> ReadAloud.pause(this) BaseReadAloudService.pause -> ReadAloud.resume(this)
Status.PAUSE -> ReadAloud.resume(this) else -> ReadAloud.pause(this)
} }
} }
@ -485,7 +483,6 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
override fun observeLiveBus() { override fun observeLiveBus() {
super.observeLiveBus() super.observeLiveBus()
observeEvent<Int>(Bus.ALOUD_STATE) { observeEvent<Int>(Bus.ALOUD_STATE) {
readAloudStatus = it
if (it == Status.STOP || it == Status.PAUSE) { if (it == Status.STOP || it == Status.PAUSE) {
ReadBook.curTextChapter?.let { textChapter -> ReadBook.curTextChapter?.let { textChapter ->
val page = textChapter.page(ReadBook.durPageIndex) val page = textChapter.page(ReadBook.durPageIndex)
@ -506,7 +503,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
if (it) { if (it) {
onClickReadAloud() onClickReadAloud()
} else { } else {
ReadBook.readAloud(readAloudStatus == Status.PLAY) ReadBook.readAloud(!BaseReadAloudService.pause)
} }
} }
observeEvent<Boolean>(Bus.UP_CONFIG) { observeEvent<Boolean>(Bus.UP_CONFIG) {

@ -10,7 +10,6 @@ import android.widget.SeekBar
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.Bus import io.legado.app.constant.Bus
import io.legado.app.constant.Status
import io.legado.app.service.BaseReadAloudService import io.legado.app.service.BaseReadAloudService
import io.legado.app.service.help.ReadAloud import io.legado.app.service.help.ReadAloud
import io.legado.app.ui.book.read.Help import io.legado.app.ui.book.read.Help
@ -57,11 +56,9 @@ class ReadAloudDialog : DialogFragment() {
} }
private fun initData() { private fun initData() {
observeEvent<Int>(Bus.ALOUD_STATE) { upPlayState(it) } observeEvent<Int>(Bus.ALOUD_STATE) { upPlayState() }
observeEvent<Int>(Bus.TTS_DS) { seek_timer.progress = it } observeEvent<Int>(Bus.TTS_DS) { seek_timer.progress = it }
callBack?.readAloudStatus?.let { upPlayState()
upPlayState(it)
}
seek_timer.progress = BaseReadAloudService.timeMinute seek_timer.progress = BaseReadAloudService.timeMinute
tv_timer.text = tv_timer.text =
requireContext().getString(R.string.timer_m, BaseReadAloudService.timeMinute) requireContext().getString(R.string.timer_m, BaseReadAloudService.timeMinute)
@ -117,8 +114,8 @@ class ReadAloudDialog : DialogFragment() {
iv_play_next.onLongClick { postEvent(Bus.TTS_TURN_PAGE, 2); true } iv_play_next.onLongClick { postEvent(Bus.TTS_TURN_PAGE, 2); true }
} }
private fun upPlayState(state: Int) { private fun upPlayState() {
if (state == Status.PLAY) { if (!BaseReadAloudService.pause) {
iv_play_pause.setImageResource(R.drawable.ic_pause_24dp) iv_play_pause.setImageResource(R.drawable.ic_pause_24dp)
} else { } else {
iv_play_pause.setImageResource(R.drawable.ic_play_24dp) iv_play_pause.setImageResource(R.drawable.ic_play_24dp)
@ -127,7 +124,7 @@ class ReadAloudDialog : DialogFragment() {
private fun upTtsSpeechRate() { private fun upTtsSpeechRate() {
ReadAloud.upTtsSpeechRate(requireContext()) ReadAloud.upTtsSpeechRate(requireContext())
if (callBack?.readAloudStatus == Status.PLAY) { if (!BaseReadAloudService.pause) {
ReadAloud.pause(requireContext()) ReadAloud.pause(requireContext())
ReadAloud.resume(requireContext()) ReadAloud.resume(requireContext())
} }
@ -137,6 +134,5 @@ class ReadAloudDialog : DialogFragment() {
fun showMenu() fun showMenu()
fun openChapterList() fun openChapterList()
fun onClickReadAloud() fun onClickReadAloud()
var readAloudStatus: Int
} }
} }
Loading…
Cancel
Save