pull/32/head
kunfei 5 years ago
parent 2e40525679
commit bbc18cf1bd
  1. 2
      app/src/main/java/io/legado/app/constant/Bus.kt
  2. 4
      app/src/main/java/io/legado/app/service/ReadAloudService.kt
  3. 19
      app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt
  4. 3
      app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudDialog.kt

@ -5,7 +5,7 @@ object Bus {
const val UP_BOOK = "sourceDebugLog"
const val ALOUD_STATE = "aloud_state"
const val TTS_START = "ttsStart"
const val TTS_NEXT = "ttsNextPage"
const val TTS_TURN_PAGE = "ttsTurnPage"
const val TTS_DS = "ttsDs"
const val BATTERY_CHANGED = "batteryChanged"
const val TIME_CHANGED = "timeChanged"

@ -416,7 +416,7 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener,
readAloudNumber += contentList[nowSpeak].length + 1
nowSpeak += 1
if (nowSpeak >= contentList.size) {
postEvent(Bus.TTS_NEXT, true)
postEvent(Bus.TTS_TURN_PAGE, 2)
}
}
@ -425,7 +425,7 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener,
textChapter?.let {
if (readAloudNumber + start > it.getReadLength(pageIndex + 1)) {
pageIndex++
postEvent(Bus.TTS_NEXT, false)
postEvent(Bus.TTS_TURN_PAGE, 1)
postEvent(Bus.TTS_START, readAloudNumber + start)
}
}

@ -581,14 +581,25 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
}
}
}
observeEvent<Boolean>(Bus.TTS_NEXT) {
if (it) {
moveToNextChapter()
} else {
observeEvent<Int>(Bus.TTS_TURN_PAGE) {
when (it) {
1 -> {
viewModel.durPageIndex = viewModel.durPageIndex + 1
page_view.upContent()
viewModel.saveRead()
}
2 -> moveToNextChapter()
-1 -> {
if (viewModel.durPageIndex > 0) {
viewModel.durPageIndex = viewModel.durPageIndex - 1
page_view.upContent()
viewModel.saveRead()
} else {
moveToPrevChapter()
}
}
-2 -> moveToPrevChapter()
}
}
observeEvent<String>(Bus.REPLACE) {
toast(it)

@ -18,6 +18,7 @@ import io.legado.app.utils.*
import kotlinx.android.synthetic.main.activity_read_book.*
import kotlinx.android.synthetic.main.dialog_read_aloud.*
import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.sdk27.listeners.onLongClick
class ReadAloudDialog : DialogFragment() {
@ -119,7 +120,9 @@ class ReadAloudDialog : DialogFragment() {
iv_stop.onClick { ReadAloudService.stop(requireContext()); dismiss() }
iv_play_pause.onClick { postEvent(Bus.READ_ALOUD_BUTTON, true) }
iv_play_prev.onClick { ReadAloudService.prevParagraph(requireContext()) }
iv_play_prev.onLongClick { postEvent(Bus.TTS_TURN_PAGE, -2); true }
iv_play_next.onClick { ReadAloudService.nextParagraph(requireContext()) }
iv_play_next.onLongClick { postEvent(Bus.TTS_TURN_PAGE, 2); true }
}
private fun upPlayState(state: Int) {

Loading…
Cancel
Save