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 2d7608626..e84d4b8c3 100644 --- a/app/src/main/java/io/legado/app/constant/Bus.kt +++ b/app/src/main/java/io/legado/app/constant/Bus.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_RANGE_START = "readAloudNumber" + const val TTS_NEXT = "ttsNextPage" const val BATTERY_CHANGED = "batteryChanged" const val TIME_CHANGED = "timeChanged" const val READ_ALOUD = "readAloud" diff --git a/app/src/main/java/io/legado/app/service/ReadAloudService.kt b/app/src/main/java/io/legado/app/service/ReadAloudService.kt index bcb6cd6ee..cb300d6e3 100644 --- a/app/src/main/java/io/legado/app/service/ReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/ReadAloudService.kt @@ -282,20 +282,25 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, AudioManage override fun onStart(s: String) { postEvent(Bus.TTS_START, readAloudNumber + 1) - postEvent(Bus.TTS_RANGE_START, readAloudNumber + 1) } override fun onDone(s: String) { readAloudNumber += contentList[nowSpeak].length + 1 nowSpeak += 1 if (nowSpeak >= contentList.size) { - postEvent(Bus.ALOUD_STATE, Status.NEXT) + postEvent(Bus.TTS_NEXT, true) } } override fun onRangeStart(utteranceId: String?, start: Int, end: Int, frame: Int) { super.onRangeStart(utteranceId, start, end, frame) - postEvent(Bus.TTS_RANGE_START, readAloudNumber + start) + textChapter?.let { + if (readAloudNumber + start > it.getReadLength(pageIndex + 1)) { + pageIndex++ + postEvent(Bus.TTS_NEXT, false) + postEvent(Bus.TTS_START, readAloudNumber + start) + } + } } override fun onError(s: String) { diff --git a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt index 980055745..ff6e49e2d 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt @@ -158,6 +158,9 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea return super.onCompatCreateOptionsMenu(menu) } + /** + * 菜单 + */ override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { R.id.menu_change_source -> { @@ -173,26 +176,30 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea return super.onCompatOptionsItemSelected(item) } + /** + * 按键拦截,显示菜单 + */ override fun dispatchKeyEvent(event: KeyEvent?): Boolean { val keyCode = event?.keyCode val action = event?.action val isDown = action == 0 if (keyCode == KeyEvent.KEYCODE_MENU) { - if (isDown && !read_menu.menuBarShow) { + if (isDown && !read_menu.cnaShowMenu) { read_menu.runMenuIn() return true } - if (!isDown && !read_menu.menuBarShow) { - read_menu.menuBarShow = true + if (!isDown && !read_menu.cnaShowMenu) { + read_menu.cnaShowMenu = true return true } } return super.dispatchKeyEvent(event) } - - + /** + * 书籍加载完成,开始加载章节内容 + */ private fun bookLoadFinish() { viewModel.bookData.value?.let { viewModel.loadContent(it, viewModel.durChapterIndex) @@ -201,12 +208,18 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea } } - override fun loadChapter(index: Int) { + /** + * 加载章节内容 + */ + override fun loadContent(index: Int) { viewModel.bookData.value?.let { viewModel.loadContent(it, index) } } + /** + * 内容加载完成 + */ override fun contentLoadFinish(bookChapter: BookChapter, content: String) { launch { when (bookChapter.index) { @@ -291,6 +304,9 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea } } + /** + * 朗读按钮 + */ private fun onClickReadAloud() { if (!ReadAloudService.isRun) { readAloudStatus = Status.STOP @@ -303,6 +319,9 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea } } + /** + * 朗读 + */ private fun readAloud() { val book = viewModel.bookData.value val textChapter = viewModel.curTextChapter @@ -319,6 +338,9 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea } } + /** + * 设置屏幕亮度 + */ private fun setScreenBrightness(value: Int) { var brightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE if (this.getPrefBoolean("brightnessAuto").not()) { @@ -364,8 +386,6 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea override fun observeLiveBus() { super.observeLiveBus() observeEvent(Bus.ALOUD_STATE) { readAloudStatus = it } - observeEvent(Bus.TTS_START) {} - observeEvent(Bus.TTS_RANGE_START) {} observeEvent(Bus.TIME_CHANGED) { page_view.upTime() } observeEvent(Bus.BATTERY_CHANGED) { page_view.upBattery(it) } observeEvent(Bus.OPEN_CHAPTER) { viewModel.openChapter(it) } @@ -376,6 +396,16 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea content_view.upStyle() page_view.upStyle() } + observeEvent(Bus.TTS_START) { + + } + observeEvent(Bus.TTS_NEXT) { + if (it) { + + } else { + + } + } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/readbook/ReadMenu.kt b/app/src/main/java/io/legado/app/ui/readbook/ReadMenu.kt index ab45663f6..256e02cb3 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/ReadMenu.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/ReadMenu.kt @@ -19,7 +19,7 @@ import org.jetbrains.anko.sdk27.listeners.onClick class ReadMenu : FrameLayout { private var callback: Callback? = null - var menuBarShow: Boolean = false + var cnaShowMenu: Boolean = false private lateinit var menuTopIn: Animation private lateinit var menuTopOut: Animation private lateinit var menuBottomIn: Animation @@ -209,7 +209,7 @@ class ReadMenu : FrameLayout { this@ReadMenu.invisible() title_bar.invisible() bottom_menu.invisible() - menuBarShow = false + cnaShowMenu = false onMenuOutEnd?.invoke() callback?.menuHide() } diff --git a/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt b/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt index e29f5e83d..c1bbc54d4 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt @@ -220,7 +220,7 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att fun durChapterIndex(): Int fun durChapterPos(): Int fun textChapter(chapterOnDur: Int = 0): TextChapter? - fun loadChapter(index: Int) + fun loadContent(index: Int) fun moveToNextChapter() fun moveToPrevChapter() fun setPageIndex(pageIndex: Int)