pull/32/head
kunfei 5 years ago
parent b0492a2138
commit 3c79168697
  1. 94
      app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt
  2. 25
      app/src/main/java/io/legado/app/ui/readbook/ReadMenu.kt

@ -54,6 +54,7 @@ import org.jetbrains.anko.toast
class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_read_book), class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_read_book),
PageView.CallBack, PageView.CallBack,
ReadMenu.Callback,
ChangeSourceDialog.CallBack, ChangeSourceDialog.CallBack,
ReadBookViewModel.CallBack, ReadBookViewModel.CallBack,
ColorPickerDialogListener { ColorPickerDialogListener {
@ -87,12 +88,12 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
override fun onWindowFocusChanged(hasFocus: Boolean) { override fun onWindowFocusChanged(hasFocus: Boolean) {
super.onWindowFocusChanged(hasFocus) super.onWindowFocusChanged(hasFocus)
Help.upSystemUiVisibility(window, !read_menu.isVisible) upSystemUiVisibility()
} }
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
Help.upSystemUiVisibility(window, !read_menu.isVisible) upSystemUiVisibility()
timeElectricityReceiver = TimeElectricityReceiver.register(this) timeElectricityReceiver = TimeElectricityReceiver.register(this)
} }
@ -102,7 +103,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
unregisterReceiver(it) unregisterReceiver(it)
timeElectricityReceiver = null timeElectricityReceiver = null
} }
Help.upSystemUiVisibility(window, !read_menu.isVisible) upSystemUiVisibility()
} }
/** /**
@ -125,57 +126,6 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
startActivity(intent) startActivity(intent)
} }
} }
read_menu.setListener(object : ReadMenu.Callback {
override fun setScreenBrightness(value: Int) {
this@ReadBookActivity.setScreenBrightness(value)
}
override fun autoPage() {
}
override fun skipToPage(page: Int) {
viewModel.durPageIndex = page
page_view.upContent()
curPageChanged()
}
override fun skipPreChapter() {
moveToPrevChapter(false)
page_view.upContent()
}
override fun skipNextChapter() {
moveToNextChapter()
page_view.upContent()
}
override fun openReplaceRule() {
startActivity<ReplaceRuleActivity>()
}
override fun openChapterList() {
viewModel.bookData.value?.let {
startActivity<ChapterListActivity>(Pair("bookUrl", it.bookUrl))
}
}
override fun showReadStyle() {
ReadStyleDialog().show(supportFragmentManager, "readStyle")
}
override fun showMoreSetting() {
MoreConfigDialog().show(supportFragmentManager, "moreConfig")
}
override fun menuShow() {
Help.upSystemUiVisibility(window, !read_menu.isVisible)
}
override fun menuHide() {
Help.upSystemUiVisibility(window, !read_menu.isVisible)
}
})
} }
fun showPaddingConfig() { fun showPaddingConfig() {
@ -445,6 +395,38 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
} }
} }
override fun autoPage() {
}
override fun skipToPage(page: Int) {
viewModel.durPageIndex = page
page_view.upContent()
curPageChanged()
}
override fun openReplaceRule() {
startActivity<ReplaceRuleActivity>()
}
override fun openChapterList() {
viewModel.bookData.value?.let {
startActivity<ChapterListActivity>(Pair("bookUrl", it.bookUrl))
}
}
override fun showReadStyle() {
ReadStyleDialog().show(supportFragmentManager, "readStyle")
}
override fun showMoreSetting() {
MoreConfigDialog().show(supportFragmentManager, "moreConfig")
}
override fun upSystemUiVisibility() {
Help.upSystemUiVisibility(window, !read_menu.isVisible)
}
/** /**
* 朗读按钮 * 朗读按钮
*/ */
@ -479,7 +461,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
/** /**
* 设置屏幕亮度 * 设置屏幕亮度
*/ */
private fun setScreenBrightness(value: Int) { override 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()) {
brightness = value.toFloat() brightness = value.toFloat()
@ -560,7 +542,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
} }
} }
observeEvent<Boolean>(Bus.UP_CONFIG) { observeEvent<Boolean>(Bus.UP_CONFIG) {
Help.upSystemUiVisibility(window, !read_menu.isVisible) upSystemUiVisibility()
page_view.upBg() page_view.upBg()
content_view.upStyle() content_view.upStyle()
page_view.upStyle() page_view.upStyle()

@ -17,9 +17,8 @@ import kotlinx.android.synthetic.main.view_read_menu.view.*
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
class ReadMenu : FrameLayout { class ReadMenu : FrameLayout {
private var callback: Callback? = null
var cnaShowMenu: Boolean = false var cnaShowMenu: Boolean = false
private var callback: Callback? = null
private lateinit var menuTopIn: Animation private lateinit var menuTopIn: Animation
private lateinit var menuTopOut: Animation private lateinit var menuTopOut: Animation
private lateinit var menuBottomIn: Animation private lateinit var menuBottomIn: Animation
@ -37,6 +36,7 @@ class ReadMenu : FrameLayout {
) )
init { init {
callback = activity as? Callback
inflate(context, R.layout.view_read_menu, this) inflate(context, R.layout.view_read_menu, this)
if (context.isNightTheme) { if (context.isNightTheme) {
fabNightTheme.setImageResource(R.drawable.ic_daytime) fabNightTheme.setImageResource(R.drawable.ic_daytime)
@ -48,6 +48,7 @@ class ReadMenu : FrameLayout {
vwNavigationBar.onClick { } vwNavigationBar.onClick { }
seek_brightness.progress = context.getPrefInt("brightness", 100) seek_brightness.progress = context.getPrefInt("brightness", 100)
upBrightness() upBrightness()
bindEvent()
} }
private fun upBrightness() { private fun upBrightness() {
@ -61,11 +62,6 @@ class ReadMenu : FrameLayout {
callback?.setScreenBrightness(context.getPrefInt("brightness", 100)) callback?.setScreenBrightness(context.getPrefInt("brightness", 100))
} }
fun setListener(callback: Callback) {
this.callback = callback
bindEvent()
}
fun runMenuIn() { fun runMenuIn() {
this.visible() this.visible()
title_bar.visible() title_bar.visible()
@ -138,10 +134,10 @@ class ReadMenu : FrameLayout {
} }
//上一章 //上一章
tv_pre.onClick { callback?.skipPreChapter() } tv_pre.onClick { callback?.moveToPrevChapter(false) }
//下一章 //下一章
tv_next.onClick { callback?.skipNextChapter() } tv_next.onClick { callback?.moveToNextChapter() }
//目录 //目录
ll_catalog.onClick { ll_catalog.onClick {
@ -177,7 +173,7 @@ class ReadMenu : FrameLayout {
menuBottomIn = AnimationUtils.loadAnimation(context, R.anim.anim_readbook_bottom_in) menuBottomIn = AnimationUtils.loadAnimation(context, R.anim.anim_readbook_bottom_in)
menuTopIn.setAnimationListener(object : Animation.AnimationListener { menuTopIn.setAnimationListener(object : Animation.AnimationListener {
override fun onAnimationStart(animation: Animation) { override fun onAnimationStart(animation: Animation) {
callback?.menuShow() callback?.upSystemUiVisibility()
} }
override fun onAnimationEnd(animation: Animation) { override fun onAnimationEnd(animation: Animation) {
@ -211,7 +207,7 @@ class ReadMenu : FrameLayout {
bottom_menu.invisible() bottom_menu.invisible()
cnaShowMenu = false cnaShowMenu = false
onMenuOutEnd?.invoke() onMenuOutEnd?.invoke()
callback?.menuHide() callback?.upSystemUiVisibility()
} }
override fun onAnimationRepeat(animation: Animation) { override fun onAnimationRepeat(animation: Animation) {
@ -234,14 +230,13 @@ class ReadMenu : FrameLayout {
fun setScreenBrightness(value: Int) fun setScreenBrightness(value: Int)
fun autoPage() fun autoPage()
fun skipToPage(page: Int) fun skipToPage(page: Int)
fun skipPreChapter() fun moveToPrevChapter(last: Boolean)
fun skipNextChapter() fun moveToNextChapter()
fun openReplaceRule() fun openReplaceRule()
fun openChapterList() fun openChapterList()
fun showReadStyle() fun showReadStyle()
fun showMoreSetting() fun showMoreSetting()
fun menuShow() fun upSystemUiVisibility()
fun menuHide()
} }
} }

Loading…
Cancel
Save