|
|
@ -158,6 +158,9 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea |
|
|
|
return super.onCompatCreateOptionsMenu(menu) |
|
|
|
return super.onCompatCreateOptionsMenu(menu) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 菜单 |
|
|
|
|
|
|
|
*/ |
|
|
|
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { |
|
|
|
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { |
|
|
|
when (item.itemId) { |
|
|
|
when (item.itemId) { |
|
|
|
R.id.menu_change_source -> { |
|
|
|
R.id.menu_change_source -> { |
|
|
@ -173,26 +176,30 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea |
|
|
|
return super.onCompatOptionsItemSelected(item) |
|
|
|
return super.onCompatOptionsItemSelected(item) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 按键拦截,显示菜单 |
|
|
|
|
|
|
|
*/ |
|
|
|
override fun dispatchKeyEvent(event: KeyEvent?): Boolean { |
|
|
|
override fun dispatchKeyEvent(event: KeyEvent?): Boolean { |
|
|
|
val keyCode = event?.keyCode |
|
|
|
val keyCode = event?.keyCode |
|
|
|
val action = event?.action |
|
|
|
val action = event?.action |
|
|
|
val isDown = action == 0 |
|
|
|
val isDown = action == 0 |
|
|
|
|
|
|
|
|
|
|
|
if (keyCode == KeyEvent.KEYCODE_MENU) { |
|
|
|
if (keyCode == KeyEvent.KEYCODE_MENU) { |
|
|
|
if (isDown && !read_menu.menuBarShow) { |
|
|
|
if (isDown && !read_menu.cnaShowMenu) { |
|
|
|
read_menu.runMenuIn() |
|
|
|
read_menu.runMenuIn() |
|
|
|
return true |
|
|
|
return true |
|
|
|
} |
|
|
|
} |
|
|
|
if (!isDown && !read_menu.menuBarShow) { |
|
|
|
if (!isDown && !read_menu.cnaShowMenu) { |
|
|
|
read_menu.menuBarShow = true |
|
|
|
read_menu.cnaShowMenu = true |
|
|
|
return true |
|
|
|
return true |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return super.dispatchKeyEvent(event) |
|
|
|
return super.dispatchKeyEvent(event) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 书籍加载完成,开始加载章节内容 |
|
|
|
|
|
|
|
*/ |
|
|
|
private fun bookLoadFinish() { |
|
|
|
private fun bookLoadFinish() { |
|
|
|
viewModel.bookData.value?.let { |
|
|
|
viewModel.bookData.value?.let { |
|
|
|
viewModel.loadContent(it, viewModel.durChapterIndex) |
|
|
|
viewModel.loadContent(it, viewModel.durChapterIndex) |
|
|
@ -201,12 +208,18 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun loadChapter(index: Int) { |
|
|
|
/** |
|
|
|
|
|
|
|
* 加载章节内容 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
override fun loadContent(index: Int) { |
|
|
|
viewModel.bookData.value?.let { |
|
|
|
viewModel.bookData.value?.let { |
|
|
|
viewModel.loadContent(it, index) |
|
|
|
viewModel.loadContent(it, index) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 内容加载完成 |
|
|
|
|
|
|
|
*/ |
|
|
|
override fun contentLoadFinish(bookChapter: BookChapter, content: String) { |
|
|
|
override fun contentLoadFinish(bookChapter: BookChapter, content: String) { |
|
|
|
launch { |
|
|
|
launch { |
|
|
|
when (bookChapter.index) { |
|
|
|
when (bookChapter.index) { |
|
|
@ -291,6 +304,9 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 朗读按钮 |
|
|
|
|
|
|
|
*/ |
|
|
|
private fun onClickReadAloud() { |
|
|
|
private fun onClickReadAloud() { |
|
|
|
if (!ReadAloudService.isRun) { |
|
|
|
if (!ReadAloudService.isRun) { |
|
|
|
readAloudStatus = Status.STOP |
|
|
|
readAloudStatus = Status.STOP |
|
|
@ -303,6 +319,9 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 朗读 |
|
|
|
|
|
|
|
*/ |
|
|
|
private fun readAloud() { |
|
|
|
private fun readAloud() { |
|
|
|
val book = viewModel.bookData.value |
|
|
|
val book = viewModel.bookData.value |
|
|
|
val textChapter = viewModel.curTextChapter |
|
|
|
val textChapter = viewModel.curTextChapter |
|
|
@ -319,6 +338,9 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 设置屏幕亮度 |
|
|
|
|
|
|
|
*/ |
|
|
|
private fun setScreenBrightness(value: Int) { |
|
|
|
private fun setScreenBrightness(value: Int) { |
|
|
|
var brightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE |
|
|
|
var brightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE |
|
|
|
if (this.getPrefBoolean("brightnessAuto").not()) { |
|
|
|
if (this.getPrefBoolean("brightnessAuto").not()) { |
|
|
@ -364,8 +386,6 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea |
|
|
|
override fun observeLiveBus() { |
|
|
|
override fun observeLiveBus() { |
|
|
|
super.observeLiveBus() |
|
|
|
super.observeLiveBus() |
|
|
|
observeEvent<Int>(Bus.ALOUD_STATE) { readAloudStatus = it } |
|
|
|
observeEvent<Int>(Bus.ALOUD_STATE) { readAloudStatus = it } |
|
|
|
observeEvent<Int>(Bus.TTS_START) {} |
|
|
|
|
|
|
|
observeEvent<Int>(Bus.TTS_RANGE_START) {} |
|
|
|
|
|
|
|
observeEvent<String>(Bus.TIME_CHANGED) { page_view.upTime() } |
|
|
|
observeEvent<String>(Bus.TIME_CHANGED) { page_view.upTime() } |
|
|
|
observeEvent<Int>(Bus.BATTERY_CHANGED) { page_view.upBattery(it) } |
|
|
|
observeEvent<Int>(Bus.BATTERY_CHANGED) { page_view.upBattery(it) } |
|
|
|
observeEvent<BookChapter>(Bus.OPEN_CHAPTER) { viewModel.openChapter(it) } |
|
|
|
observeEvent<BookChapter>(Bus.OPEN_CHAPTER) { viewModel.openChapter(it) } |
|
|
@ -376,6 +396,16 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea |
|
|
|
content_view.upStyle() |
|
|
|
content_view.upStyle() |
|
|
|
page_view.upStyle() |
|
|
|
page_view.upStyle() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
observeEvent<Int>(Bus.TTS_START) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
observeEvent<Boolean>(Bus.TTS_NEXT) { |
|
|
|
|
|
|
|
if (it) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |