pull/2208/head
kunfei 2 years ago
parent 2950d8f6d8
commit ca90ff24db
  1. 167
      app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt
  2. 6
      app/src/main/java/io/legado/app/ui/book/read/SearchMenu.kt
  3. 15
      app/src/main/java/io/legado/app/utils/AnimationExtensions.kt
  4. 17
      app/src/main/java/io/legado/app/utils/AnimationUtilsSupport.kt

@ -43,10 +43,18 @@ class ReadMenu @JvmOverloads constructor(
var cnaShowMenu: Boolean = false var cnaShowMenu: Boolean = false
private val callBack: CallBack get() = activity as CallBack private val callBack: CallBack get() = activity as CallBack
private val binding = ViewReadMenuBinding.inflate(LayoutInflater.from(context), this, true) private val binding = ViewReadMenuBinding.inflate(LayoutInflater.from(context), this, true)
private lateinit var menuTopIn: Animation private val menuTopIn: Animation by lazy {
private lateinit var menuTopOut: Animation loadAnimation(context, R.anim.anim_readbook_top_in)
private lateinit var menuBottomIn: Animation }
private lateinit var menuBottomOut: Animation private val menuTopOut: Animation by lazy {
loadAnimation(context, R.anim.anim_readbook_top_out)
}
private val menuBottomIn: Animation by lazy {
loadAnimation(context, R.anim.anim_readbook_bottom_in)
}
private val menuBottomOut: Animation by lazy {
loadAnimation(context, R.anim.anim_readbook_bottom_out)
}
private val bgColor: Int = context.bottomBackground private val bgColor: Int = context.bottomBackground
private val textColor: Int = context.getPrimaryTextColor(ColorUtils.isColorLight(bgColor)) private val textColor: Int = context.getPrimaryTextColor(ColorUtils.isColorLight(bgColor))
private val bottomBackgroundList: ColorStateList = Selector.colorBuild() private val bottomBackgroundList: ColorStateList = Selector.colorBuild()
@ -71,6 +79,58 @@ class ReadMenu @JvmOverloads constructor(
} }
} }
} }
private val menuInListener = object : Animation.AnimationListener {
override fun onAnimationStart(animation: Animation) {
binding.tvSourceAction.isGone = ReadBook.isLocalBook
binding.tvLogin.isGone = ReadBook.bookSource?.loginUrl.isNullOrEmpty()
binding.tvPay.isGone = ReadBook.bookSource?.loginUrl.isNullOrEmpty()
|| ReadBook.curTextChapter?.isVip != true
|| ReadBook.curTextChapter?.isPay == true
callBack.upSystemUiVisibility()
binding.llBrightness.visible(showBrightnessView)
}
@SuppressLint("RtlHardcoded")
override fun onAnimationEnd(animation: Animation) {
val navigationBarHeight =
if (ReadBookConfig.hideNavigationBar) {
activity?.navigationBarHeight ?: 0
} else {
0
}
binding.run {
vwMenuBg.setOnClickListener { runMenuOut() }
root.padding = 0
when (activity?.navigationBarGravity) {
Gravity.BOTTOM -> root.bottomPadding = navigationBarHeight
Gravity.LEFT -> root.leftPadding = navigationBarHeight
Gravity.RIGHT -> root.rightPadding = navigationBarHeight
}
}
callBack.upSystemUiVisibility()
if (!LocalConfig.readMenuHelpVersionIsLast) {
callBack.showReadMenuHelp()
}
}
override fun onAnimationRepeat(animation: Animation) = Unit
}
private val menuOutListener = object : Animation.AnimationListener {
override fun onAnimationStart(animation: Animation) {
binding.vwMenuBg.setOnClickListener(null)
}
override fun onAnimationEnd(animation: Animation) {
this@ReadMenu.invisible()
binding.titleBar.invisible()
binding.bottomMenu.invisible()
cnaShowMenu = false
onMenuOutEnd?.invoke()
callBack.upSystemUiVisibility()
}
override fun onAnimationRepeat(animation: Animation) = Unit
}
init { init {
initView() initView()
@ -141,19 +201,29 @@ class ReadMenu @JvmOverloads constructor(
activity?.window?.attributes = params activity?.window?.attributes = params
} }
fun runMenuIn() { fun runMenuIn(anim: Boolean = AppConfig.isEInkMode) {
this.visible() this.visible()
binding.titleBar.visible() binding.titleBar.visible()
binding.bottomMenu.visible() binding.bottomMenu.visible()
if (anim) {
binding.titleBar.startAnimation(menuTopIn) binding.titleBar.startAnimation(menuTopIn)
binding.bottomMenu.startAnimation(menuBottomIn) binding.bottomMenu.startAnimation(menuBottomIn)
} else {
menuInListener.onAnimationStart(menuBottomIn)
menuInListener.onAnimationEnd(menuBottomIn)
}
} }
fun runMenuOut(onMenuOutEnd: (() -> Unit)? = null) { fun runMenuOut(anim: Boolean = AppConfig.isEInkMode, onMenuOutEnd: (() -> Unit)? = null) {
this.onMenuOutEnd = onMenuOutEnd this.onMenuOutEnd = onMenuOutEnd
if (this.isVisible) { if (this.isVisible) {
if (anim) {
binding.titleBar.startAnimation(menuTopOut) binding.titleBar.startAnimation(menuTopOut)
binding.bottomMenu.startAnimation(menuBottomOut) binding.bottomMenu.startAnimation(menuBottomOut)
} else {
menuOutListener.onAnimationStart(menuBottomOut)
menuOutListener.onAnimationEnd(menuBottomOut)
}
} }
} }
@ -247,9 +317,6 @@ class ReadMenu @JvmOverloads constructor(
//搜索 //搜索
fabSearch.setOnClickListener { fabSearch.setOnClickListener {
if(AppConfig.isEInkMode)
callBack.openSearchActivity(null)
else
runMenuOut { runMenuOut {
callBack.openSearchActivity(null) callBack.openSearchActivity(null)
} }
@ -257,9 +324,6 @@ class ReadMenu @JvmOverloads constructor(
//自动翻页 //自动翻页
fabAutoPage.setOnClickListener { fabAutoPage.setOnClickListener {
if(AppConfig.isEInkMode)
callBack.autoPage()
else
runMenuOut { runMenuOut {
callBack.autoPage() callBack.autoPage()
} }
@ -282,9 +346,6 @@ class ReadMenu @JvmOverloads constructor(
//目录 //目录
llCatalog.setOnClickListener { llCatalog.setOnClickListener {
if(AppConfig.isEInkMode)
callBack.openChapterList()
else
runMenuOut { runMenuOut {
callBack.openChapterList() callBack.openChapterList()
} }
@ -292,24 +353,17 @@ class ReadMenu @JvmOverloads constructor(
//朗读 //朗读
llReadAloud.setOnClickListener { llReadAloud.setOnClickListener {
if(AppConfig.isEInkMode)
callBack.onClickReadAloud()
else
runMenuOut { runMenuOut {
callBack.onClickReadAloud() callBack.onClickReadAloud()
} }
} }
llReadAloud.onLongClick { llReadAloud.onLongClick {
if(AppConfig.isEInkMode) runMenuOut {
callBack.showReadAloudDialog() callBack.showReadAloudDialog()
else }
runMenuOut { callBack.showReadAloudDialog() }
} }
//界面 //界面
llFont.setOnClickListener { llFont.setOnClickListener {
if(AppConfig.isEInkMode)
callBack.showReadStyle()
else
runMenuOut { runMenuOut {
callBack.showReadStyle() callBack.showReadStyle()
} }
@ -317,9 +371,6 @@ class ReadMenu @JvmOverloads constructor(
//设置 //设置
llSetting.setOnClickListener { llSetting.setOnClickListener {
if(AppConfig.isEInkMode)
callBack.showMoreSetting()
else
runMenuOut { runMenuOut {
callBack.showMoreSetting() callBack.showMoreSetting()
} }
@ -327,66 +378,8 @@ class ReadMenu @JvmOverloads constructor(
} }
private fun initAnimation() { private fun initAnimation() {
//显示菜单 menuTopIn.setAnimationListener(menuInListener)
menuTopIn = AnimationUtilsSupport.loadAnimation(context, R.anim.anim_readbook_top_in) menuTopOut.setAnimationListener(menuOutListener)
menuBottomIn = AnimationUtilsSupport.loadAnimation(context, R.anim.anim_readbook_bottom_in)
menuTopIn.setAnimationListener(object : Animation.AnimationListener {
override fun onAnimationStart(animation: Animation) {
binding.tvSourceAction.isGone = ReadBook.isLocalBook
binding.tvLogin.isGone = ReadBook.bookSource?.loginUrl.isNullOrEmpty()
binding.tvPay.isGone = ReadBook.bookSource?.loginUrl.isNullOrEmpty()
|| ReadBook.curTextChapter?.isVip != true
|| ReadBook.curTextChapter?.isPay == true
callBack.upSystemUiVisibility()
binding.llBrightness.visible(showBrightnessView)
}
@SuppressLint("RtlHardcoded")
override fun onAnimationEnd(animation: Animation) {
val navigationBarHeight =
if (ReadBookConfig.hideNavigationBar) {
activity?.navigationBarHeight ?: 0
} else {
0
}
binding.run {
vwMenuBg.setOnClickListener { runMenuOut() }
root.padding = 0
when (activity?.navigationBarGravity) {
Gravity.BOTTOM -> root.bottomPadding = navigationBarHeight
Gravity.LEFT -> root.leftPadding = navigationBarHeight
Gravity.RIGHT -> root.rightPadding = navigationBarHeight
}
}
callBack.upSystemUiVisibility()
if (!LocalConfig.readMenuHelpVersionIsLast) {
callBack.showReadMenuHelp()
}
}
override fun onAnimationRepeat(animation: Animation) = Unit
})
//隐藏菜单
menuTopOut = AnimationUtilsSupport.loadAnimation(context, R.anim.anim_readbook_top_out)
menuBottomOut =
AnimationUtilsSupport.loadAnimation(context, R.anim.anim_readbook_bottom_out)
menuTopOut.setAnimationListener(object : Animation.AnimationListener {
override fun onAnimationStart(animation: Animation) {
binding.vwMenuBg.setOnClickListener(null)
}
override fun onAnimationEnd(animation: Animation) {
this@ReadMenu.invisible()
binding.titleBar.invisible()
binding.bottomMenu.invisible()
cnaShowMenu = false
onMenuOutEnd?.invoke()
callBack.upSystemUiVisibility()
}
override fun onAnimationRepeat(animation: Animation) = Unit
})
} }
fun upBookView() { fun upBookView() {

@ -33,10 +33,8 @@ class SearchMenu @JvmOverloads constructor(
private val callBack: CallBack get() = activity as CallBack private val callBack: CallBack get() = activity as CallBack
private val binding = ViewSearchMenuBinding.inflate(LayoutInflater.from(context), this, true) private val binding = ViewSearchMenuBinding.inflate(LayoutInflater.from(context), this, true)
private val menuBottomIn: Animation = private val menuBottomIn: Animation = loadAnimation(context, R.anim.anim_readbook_bottom_in)
AnimationUtilsSupport.loadAnimation(context, R.anim.anim_readbook_bottom_in) private val menuBottomOut: Animation = loadAnimation(context, R.anim.anim_readbook_bottom_out)
private val menuBottomOut: Animation =
AnimationUtilsSupport.loadAnimation(context, R.anim.anim_readbook_bottom_out)
private val bgColor: Int = context.bottomBackground private val bgColor: Int = context.bottomBackground
private val textColor: Int = context.getPrimaryTextColor(ColorUtils.isColorLight(bgColor)) private val textColor: Int = context.getPrimaryTextColor(ColorUtils.isColorLight(bgColor))
private val bottomBackgroundList: ColorStateList = private val bottomBackgroundList: ColorStateList =

@ -0,0 +1,15 @@
package io.legado.app.utils
import android.content.Context
import android.view.animation.Animation
import android.view.animation.AnimationUtils
import androidx.annotation.AnimRes
import io.legado.app.help.config.AppConfig
fun loadAnimation(context: Context, @AnimRes id: Int): Animation {
val animation = AnimationUtils.loadAnimation(context, id)
if (AppConfig.isEInkMode) {
animation.duration = 0
}
return animation
}

@ -1,17 +0,0 @@
package io.legado.app.utils
import android.content.Context
import android.view.animation.Animation
import android.view.animation.AnimationUtils
import androidx.annotation.AnimRes
import io.legado.app.help.config.AppConfig
object AnimationUtilsSupport {
fun loadAnimation(context: Context, @AnimRes id: Int): Animation {
val animation = AnimationUtils.loadAnimation(context, id)
if (AppConfig.isEInkMode) {
animation.duration = 0
}
return animation
}
}
Loading…
Cancel
Save