pull/32/head
kunfei 5 years ago
parent 3b0d9ed5ad
commit e2d7351a40
  1. 2
      app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt
  2. 80
      app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt
  3. 75
      app/src/main/java/io/legado/app/ui/readbook/ReadMenu.kt

@ -51,7 +51,7 @@ class MediaButtonReceiver : BroadcastReceiver() {
context.startActivity<ReadBookActivity>()
}
}
postEvent(Bus.READ_ALOUD, "")
postEvent(Bus.READ_ALOUD, true)
}
}

@ -4,9 +4,6 @@ import android.os.Bundle
import android.view.KeyEvent
import android.view.Menu
import android.view.MenuItem
import android.view.animation.Animation
import android.view.animation.AnimationUtils
import androidx.core.view.isVisible
import androidx.lifecycle.Observer
import io.legado.app.App
import io.legado.app.R
@ -43,16 +40,10 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
private var changeSourceDialog: ChangeSourceDialog? = null
private var timeElectricityReceiver: TimeElectricityReceiver? = null
private var menuBarShow: Boolean = false
private lateinit var menuTopIn: Animation
private lateinit var menuTopOut: Animation
private lateinit var menuBottomIn: Animation
private lateinit var menuBottomOut: Animation
private var readAloudStatus = Status.STOP
override fun onActivityCreated(savedInstanceState: Bundle?) {
setSupportActionBar(toolbar)
initAnimation()
initView()
page_view.callback = this
viewModel.callBack = this
@ -78,43 +69,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
}
}
private fun initAnimation() {
menuTopIn = AnimationUtils.loadAnimation(this, R.anim.anim_readbook_top_in)
menuBottomIn = AnimationUtils.loadAnimation(this, R.anim.anim_readbook_bottom_in)
menuBottomIn.setAnimationListener(object : Animation.AnimationListener {
override fun onAnimationStart(animation: Animation) {
}
override fun onAnimationEnd(animation: Animation) {
vw_menu_bg.onClick { runMenuOut() }
}
override fun onAnimationRepeat(animation: Animation) {
}
})
//隐藏菜单
menuTopOut = AnimationUtils.loadAnimation(this, R.anim.anim_readbook_top_out)
menuBottomOut = AnimationUtils.loadAnimation(this, R.anim.anim_readbook_bottom_out)
menuBottomOut.setAnimationListener(object : Animation.AnimationListener {
override fun onAnimationStart(animation: Animation) {
vw_menu_bg.setOnClickListener(null)
}
override fun onAnimationEnd(animation: Animation) {
fl_menu.invisible()
title_bar.invisible()
bottom_menu.invisible()
menuBarShow = false
}
override fun onAnimationRepeat(animation: Animation) {
}
})
}
private fun initView() {
tv_chapter_name.onClick {
@ -128,10 +83,6 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
}
override fun clickReadAloud() {
onClickReadAloud()
}
override fun autoPage() {
}
@ -164,12 +115,12 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
}
override fun showReadStyle() {
runMenuOut()
fl_menu.runMenuOut()
ReadStyleDialog().show(supportFragmentManager, "readStyle")
}
override fun showMoreSetting() {
runMenuOut()
fl_menu.runMenuOut()
MoreConfigDialog().show(supportFragmentManager, "moreConfig")
}
@ -178,7 +129,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
}
override fun dismiss() {
runMenuOut()
fl_menu.runMenuOut()
}
})
@ -210,34 +161,19 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
val isDown = action == 0
if (keyCode == KeyEvent.KEYCODE_MENU) {
if (isDown && !menuBarShow) {
runMenuIn()
if (isDown && !fl_menu.menuBarShow) {
fl_menu.runMenuIn()
return true
}
if (!isDown && !menuBarShow) {
menuBarShow = true
if (!isDown && !fl_menu.menuBarShow) {
fl_menu.menuBarShow = true
return true
}
}
return super.dispatchKeyEvent(event)
}
private fun runMenuIn() {
fl_menu.visible()
title_bar.visible()
bottom_menu.visible()
title_bar.startAnimation(menuTopIn)
bottom_menu.startAnimation(menuBottomIn)
}
private fun runMenuOut() {
if (fl_menu.isVisible) {
if (bottom_menu.isVisible) {
title_bar.startAnimation(menuTopOut)
bottom_menu.startAnimation(menuBottomOut)
}
}
}
private fun bookLoadFinish() {
viewModel.bookData.value?.let {
@ -335,7 +271,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
observeEvent<String>(Bus.TIME_CHANGED) { page_view.upTime() }
observeEvent<Int>(Bus.BATTERY_CHANGED) { page_view.upBattery(it) }
observeEvent<BookChapter>(Bus.OPEN_CHAPTER) { viewModel.openChapter(it) }
observeEventSticky<String>(Bus.READ_ALOUD) { onClickReadAloud() }
observeEventSticky<Boolean>(Bus.READ_ALOUD) { onClickReadAloud() }
observeEventSticky<Int>(Bus.UP_CONFIG) {
when (it) {
0 -> {

@ -2,16 +2,28 @@ package io.legado.app.ui.readbook
import android.content.Context
import android.util.AttributeSet
import android.view.animation.Animation
import android.view.animation.AnimationUtils
import android.widget.FrameLayout
import android.widget.SeekBar
import androidx.core.view.isVisible
import io.legado.app.R
import io.legado.app.constant.Bus
import io.legado.app.utils.invisible
import io.legado.app.utils.isNightTheme
import io.legado.app.utils.postEvent
import io.legado.app.utils.visible
import kotlinx.android.synthetic.main.view_read_menu.view.*
import org.jetbrains.anko.sdk27.listeners.onClick
class ReadMenu : FrameLayout {
private var callback: Callback? = null
var menuBarShow: Boolean = false
private lateinit var menuTopIn: Animation
private lateinit var menuTopOut: Animation
private lateinit var menuBottomIn: Animation
private lateinit var menuBottomOut: Animation
constructor(context: Context) : super(context)
@ -30,6 +42,7 @@ class ReadMenu : FrameLayout {
} else {
fabNightTheme.setImageResource(R.drawable.ic_brightness)
}
initAnimation()
vw_bg.onClick { }
vwNavigationBar.onClick { }
}
@ -39,6 +52,61 @@ class ReadMenu : FrameLayout {
bindEvent()
}
private fun initAnimation() {
menuTopIn = AnimationUtils.loadAnimation(context, R.anim.anim_readbook_top_in)
menuBottomIn = AnimationUtils.loadAnimation(context, R.anim.anim_readbook_bottom_in)
menuBottomIn.setAnimationListener(object : Animation.AnimationListener {
override fun onAnimationStart(animation: Animation) {
}
override fun onAnimationEnd(animation: Animation) {
vw_menu_bg.onClick { runMenuOut() }
}
override fun onAnimationRepeat(animation: Animation) {
}
})
//隐藏菜单
menuTopOut = AnimationUtils.loadAnimation(context, R.anim.anim_readbook_top_out)
menuBottomOut = AnimationUtils.loadAnimation(context, R.anim.anim_readbook_bottom_out)
menuBottomOut.setAnimationListener(object : Animation.AnimationListener {
override fun onAnimationStart(animation: Animation) {
vw_menu_bg.setOnClickListener(null)
}
override fun onAnimationEnd(animation: Animation) {
this@ReadMenu.invisible()
title_bar.invisible()
bottom_menu.invisible()
menuBarShow = false
}
override fun onAnimationRepeat(animation: Animation) {
}
})
}
fun runMenuIn() {
this.visible()
title_bar.visible()
bottom_menu.visible()
title_bar.startAnimation(menuTopIn)
bottom_menu.startAnimation(menuBottomIn)
}
fun runMenuOut() {
if (this.isVisible) {
if (bottom_menu.isVisible) {
title_bar.startAnimation(menuTopOut)
bottom_menu.startAnimation(menuBottomOut)
}
}
}
private fun bindEvent() {
ll_floating_button.onClick { callback?.dismiss() }
@ -58,7 +126,10 @@ class ReadMenu : FrameLayout {
})
//朗读
fab_read_aloud.onClick { callback?.clickReadAloud() }
fab_read_aloud.onClick {
postEvent(Bus.READ_ALOUD, true)
callback?.dismiss()
}
//自动翻页
fabAutoPage.onClick { callback?.autoPage() }
@ -101,8 +172,6 @@ class ReadMenu : FrameLayout {
interface Callback {
fun skipToPage(page: Int)
fun clickReadAloud()
fun autoPage()
fun setNightTheme()

Loading…
Cancel
Save