diff --git a/app/src/main/java/io/legado/app/constant/Bus.kt b/app/src/main/java/io/legado/app/constant/Bus.kt index 17cad91ef..517bafc93 100644 --- a/app/src/main/java/io/legado/app/constant/Bus.kt +++ b/app/src/main/java/io/legado/app/constant/Bus.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" diff --git a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt index 30e7abae8..c2467c1eb 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -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) diff --git a/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt b/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt index 888afbc99..cdfd05581 100644 --- a/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt @@ -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) } } diff --git a/app/src/main/java/io/legado/app/service/help/ReadBook.kt b/app/src/main/java/io/legado/app/service/help/ReadBook.kt index d1b7f22e0..381d93849 100644 --- a/app/src/main/java/io/legado/app/service/help/ReadBook.kt +++ b/app/src/main/java/io/legado/app/service/help/ReadBook.kt @@ -49,6 +49,11 @@ object ReadBook { nextTextChapter = null } + fun moveToNextPage() { + durPageIndex++ + callBack?.upContent() + } + fun moveToNextChapter(upContent: Boolean): Boolean { if (durChapterIndex < chapterSize - 1) { durPageIndex = 0 diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 921d57aff..be1644ca0 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -508,32 +508,6 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo } } } - observeEvent(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(Bus.REPLACE) { ReplaceEditDialog().show(supportFragmentManager, "replaceEditDialog") } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt index f016c3e65..a1ff9df16 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt @@ -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() {