pull/49/head
kunfei 5 years ago
parent 026a283bfb
commit 4e845ab431
  1. 1
      app/src/main/java/io/legado/app/constant/Bus.kt
  2. 3
      app/src/main/java/io/legado/app/service/HttpReadAloudService.kt
  3. 5
      app/src/main/java/io/legado/app/service/TTSReadAloudService.kt
  4. 5
      app/src/main/java/io/legado/app/service/help/ReadBook.kt
  5. 26
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  6. 10
      app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt

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

@ -7,6 +7,7 @@ import io.legado.app.data.api.IHttpPostApi
import io.legado.app.help.FileHelp
import io.legado.app.help.IntentHelp
import io.legado.app.help.http.HttpHelper
import io.legado.app.service.help.ReadBook
import io.legado.app.utils.LogUtils
import io.legado.app.utils.getPrefInt
import io.legado.app.utils.getPrefString
@ -177,7 +178,7 @@ class HttpReadAloudService : BaseReadAloudService(),
textChapter?.let {
if (readAloudNumber + 1 > it.getReadLength(pageIndex + 1)) {
pageIndex++
postEvent(Bus.TTS_TURN_PAGE, 1)
ReadBook.moveToNextPage()
}
}
postEvent(Bus.TTS_START, readAloudNumber + 1)

@ -9,6 +9,7 @@ import io.legado.app.constant.AppConst
import io.legado.app.constant.Bus
import io.legado.app.help.IntentHelp
import io.legado.app.help.MediaHelp
import io.legado.app.service.help.ReadBook
import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.getPrefInt
import io.legado.app.utils.postEvent
@ -154,7 +155,7 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener
textChapter?.let {
if (readAloudNumber + 1 > it.getReadLength(pageIndex + 1)) {
pageIndex++
postEvent(Bus.TTS_TURN_PAGE, 1)
ReadBook.moveToNextPage()
}
}
postEvent(Bus.TTS_START, readAloudNumber + 1)
@ -173,7 +174,7 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener
textChapter?.let {
if (readAloudNumber + start > it.getReadLength(pageIndex + 1)) {
pageIndex++
postEvent(Bus.TTS_TURN_PAGE, 1)
ReadBook.moveToNextPage()
postEvent(Bus.TTS_START, readAloudNumber + start)
}
}

@ -49,6 +49,11 @@ object ReadBook {
nextTextChapter = null
}
fun moveToNextPage() {
durPageIndex++
callBack?.upContent()
}
fun moveToNextChapter(upContent: Boolean): Boolean {
if (durChapterIndex < chapterSize - 1) {
durPageIndex = 0

@ -508,32 +508,6 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
}
}
}
observeEvent<Int>(Bus.TTS_TURN_PAGE) {
when (it) {
1 -> {
if (page_view.isScrollDelegate) {
page_view.moveToNextPage()
} else {
ReadBook.durPageIndex = ReadBook.durPageIndex + 1
page_view.upContent()
ReadBook.saveRead()
}
}
-1 -> {
if (ReadBook.durPageIndex > 0) {
if (page_view.isScrollDelegate) {
page_view.moveToPrevPage()
} else {
ReadBook.durPageIndex = ReadBook.durPageIndex - 1
page_view.upContent()
ReadBook.saveRead()
}
} else {
moveToPrevChapter(true)
}
}
}
}
observeEvent<String>(Bus.REPLACE) {
ReplaceEditDialog().show(supportFragmentManager, "replaceEditDialog")
}

@ -12,6 +12,7 @@ import io.legado.app.R
import io.legado.app.constant.Bus
import io.legado.app.service.BaseReadAloudService
import io.legado.app.service.help.ReadAloud
import io.legado.app.service.help.ReadBook
import io.legado.app.ui.book.read.Help
import io.legado.app.utils.*
import kotlinx.android.synthetic.main.dialog_read_aloud.*
@ -109,9 +110,14 @@ class ReadAloudDialog : DialogFragment() {
iv_stop.onClick { ReadAloud.stop(requireContext()); dismiss() }
iv_play_pause.onClick { callBack?.onClickReadAloud() }
iv_play_prev.onClick { ReadAloud.prevParagraph(requireContext()) }
iv_play_prev.onLongClick { postEvent(Bus.TTS_TURN_PAGE, -2); true }
iv_play_prev.onLongClick {
ReadBook.moveToPrevChapter(
upContent = true,
toLast = false
); true
}
iv_play_next.onClick { ReadAloud.nextParagraph(requireContext()) }
iv_play_next.onLongClick { postEvent(Bus.TTS_TURN_PAGE, 2); true }
iv_play_next.onLongClick { ReadBook.moveToNextChapter(true); true }
}
private fun upPlayState() {

Loading…
Cancel
Save