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

@ -10,7 +10,6 @@ import android.widget.SeekBar
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.BaseReadAloudService
import io.legado.app.service.help.ReadAloud
import io.legado.app.ui.book.read.Help
@ -57,11 +56,9 @@ class ReadAloudDialog : DialogFragment() {
}
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 }
callBack?.readAloudStatus?.let {
upPlayState(it)
}
upPlayState()
seek_timer.progress = BaseReadAloudService.timeMinute
tv_timer.text =
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 }
}
private fun upPlayState(state: Int) {
if (state == Status.PLAY) {
private fun upPlayState() {
if (!BaseReadAloudService.pause) {
iv_play_pause.setImageResource(R.drawable.ic_pause_24dp)
} else {
iv_play_pause.setImageResource(R.drawable.ic_play_24dp)
@ -127,7 +124,7 @@ class ReadAloudDialog : DialogFragment() {
private fun upTtsSpeechRate() {
ReadAloud.upTtsSpeechRate(requireContext())
if (callBack?.readAloudStatus == Status.PLAY) {
if (!BaseReadAloudService.pause) {
ReadAloud.pause(requireContext())
ReadAloud.resume(requireContext())
}
@ -137,6 +134,5 @@ class ReadAloudDialog : DialogFragment() {
fun showMenu()
fun openChapterList()
fun onClickReadAloud()
var readAloudStatus: Int
}
}
Loading…
Cancel
Save