Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
821938089 committed Sep 15, 2024
1 parent c892436 commit 7af5771
Show file tree
Hide file tree
Showing 6 changed files with 226 additions and 205 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ import io.legado.app.utils.isAbsUrl
import io.legado.app.utils.isTrue
import io.legado.app.utils.launch
import io.legado.app.utils.navigationBarGravity
import io.legado.app.utils.navigationBarHeight
import io.legado.app.utils.observeEvent
import io.legado.app.utils.observeEventSticky
import io.legado.app.utils.postEvent
Expand Down Expand Up @@ -297,7 +296,7 @@ class ReadBookActivity : BaseReadBookActivity(),
if (!ReadBook.inBookshelf) {
viewModel.removeFromBookshelf(null)
}
viewModel.initData(intent ?: return)
viewModel.initData(intent)
}

override fun onWindowFocusChanged(hasFocus: Boolean) {
Expand Down Expand Up @@ -776,7 +775,7 @@ class ReadBookActivity : BaseReadBookActivity(),
override fun showTextActionMenu() {
val navigationBarHeight =
if (!ReadBookConfig.hideNavigationBar && navigationBarGravity == Gravity.BOTTOM)
navigationBarHeight else 0
binding.navigationBar.height else 0
textActionMenu.show(
binding.textMenuPosition,
binding.root.height + navigationBarHeight,
Expand Down Expand Up @@ -1341,7 +1340,7 @@ class ReadBookActivity : BaseReadBookActivity(),
}
val navigationBarHeight =
if (!ReadBookConfig.hideNavigationBar && navigationBarGravity == Gravity.BOTTOM)
navigationBarHeight else 0
binding.navigationBar.height else 0
popupAction.showAtLocation(
binding.readView, Gravity.BOTTOM or Gravity.LEFT, x.toInt(),
binding.root.height + navigationBarHeight - y.toInt()
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class ReadMenu @JvmOverloads constructor(
private val callBack: CallBack get() = activity as CallBack
private val binding = ViewReadMenuBinding.inflate(LayoutInflater.from(context), this, true)
private var confirmSkipToChapter: Boolean = false
private var isMenuOutAnimating = false
private val menuTopIn: Animation by lazy {
loadAnimation(context, R.anim.anim_readbook_top_in)
}
Expand Down Expand Up @@ -151,6 +152,7 @@ class ReadMenu @JvmOverloads constructor(
}
private val menuOutListener = object : Animation.AnimationListener {
override fun onAnimationStart(animation: Animation) {
isMenuOutAnimating = true
binding.vwMenuBg.setOnClickListener(null)
}

Expand All @@ -159,6 +161,7 @@ class ReadMenu @JvmOverloads constructor(
binding.titleBar.invisible()
binding.bottomMenu.invisible()
canShowMenu = false
isMenuOutAnimating = false
onMenuOutEnd?.invoke()
callBack.upSystemUiVisibility()
}
Expand Down Expand Up @@ -309,6 +312,9 @@ class ReadMenu @JvmOverloads constructor(
}

fun runMenuOut(anim: Boolean = !AppConfig.isEInkMode, onMenuOutEnd: (() -> Unit)? = null) {
if (isMenuOutAnimating) {
return
}
callBack.onMenuHide()
this.onMenuOutEnd = onMenuOutEnd
if (this.isVisible) {
Expand Down
18 changes: 10 additions & 8 deletions app/src/main/java/io/legado/app/ui/book/read/SearchMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class SearchMenu @JvmOverloads constructor(
Selector.colorBuild().setDefaultColor(bgColor)
.setPressedColor(ColorUtils.darkenColor(bgColor)).create()
private var onMenuOutEnd: (() -> Unit)? = null
private var isMenuOutAnimating = false

private val searchResultList: MutableList<SearchResult> = mutableListOf()
private var currentSearchResultIndex: Int = -1
Expand Down Expand Up @@ -94,18 +95,18 @@ class SearchMenu @JvmOverloads constructor(

fun runMenuIn() {
this.visible()
binding.llSearchBaseInfo.visible()
binding.llBottomBg.visible()
binding.llBottomMenu.visible()
binding.vwMenuBg.visible()
binding.llSearchBaseInfo.startAnimation(menuBottomIn)
binding.llBottomBg.startAnimation(menuBottomIn)
binding.llBottomMenu.startAnimation(menuBottomIn)
}

fun runMenuOut(onMenuOutEnd: (() -> Unit)? = null) {
if (isMenuOutAnimating) {
return
}
this.onMenuOutEnd = onMenuOutEnd
if (this.isVisible) {
binding.llSearchBaseInfo.startAnimation(menuBottomOut)
binding.llBottomBg.startAnimation(menuBottomOut)
binding.llBottomMenu.startAnimation(menuBottomOut)
}
}

Expand Down Expand Up @@ -216,12 +217,13 @@ class SearchMenu @JvmOverloads constructor(
//隐藏菜单
menuBottomOut.setAnimationListener(object : Animation.AnimationListener {
override fun onAnimationStart(animation: Animation) {
isMenuOutAnimating = true
binding.vwMenuBg.setOnClickListener(null)
}

override fun onAnimationEnd(animation: Animation) {
binding.llSearchBaseInfo.invisible()
binding.llBottomBg.invisible()
isMenuOutAnimating = false
binding.llBottomMenu.invisible()
binding.vwMenuBg.invisible()
binding.vwMenuBg.setOnClickListener { runMenuOut() }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ class AutoReadDialog : BaseDialogFragment(R.layout.dialog_auto_read) {
}

override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) = binding.run {
(activity as ReadBookActivity).bottomDialog++
val bottomDialog = (activity as ReadBookActivity).bottomDialog++
if (bottomDialog > 0) {
dismiss()
return
}
val bg = requireContext().bottomBackground
val isLight = ColorUtils.isColorLight(bg)
val textColor = requireContext().getPrimaryTextColor(isLight)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ class ReadAloudDialog : BaseDialogFragment(R.layout.dialog_read_aloud) {
}

override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
(activity as ReadBookActivity).bottomDialog++
val bottomDialog = (activity as ReadBookActivity).bottomDialog++
if (bottomDialog > 0) {
dismiss()
return
}
val bg = requireContext().bottomBackground
val isLight = ColorUtils.isColorLight(bg)
val textColor = requireContext().getPrimaryTextColor(isLight)
Expand Down
Loading

0 comments on commit 7af5771

Please sign in to comment.