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. 25
      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 UP_BOOK = "sourceDebugLog"
const val ALOUD_STATE = "aloud_state" const val ALOUD_STATE = "aloud_state"
const val TTS_START = "ttsStart" const val TTS_START = "ttsStart"
const val TTS_NEXT = "ttsNextPage" const val TTS_TURN_PAGE = "ttsTurnPage"
const val TTS_DS = "ttsDs" const val TTS_DS = "ttsDs"
const val BATTERY_CHANGED = "batteryChanged" const val BATTERY_CHANGED = "batteryChanged"
const val TIME_CHANGED = "timeChanged" const val TIME_CHANGED = "timeChanged"

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

@ -581,13 +581,24 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
} }
} }
} }
observeEvent<Boolean>(Bus.TTS_NEXT) { observeEvent<Int>(Bus.TTS_TURN_PAGE) {
if (it) { when (it) {
moveToNextChapter() 1 -> {
} else { viewModel.durPageIndex = viewModel.durPageIndex + 1
viewModel.durPageIndex = viewModel.durPageIndex + 1 page_view.upContent()
page_view.upContent() viewModel.saveRead()
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) { observeEvent<String>(Bus.REPLACE) {

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

Loading…
Cancel
Save