mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
More changes to the scrolling text
Making sure the text doesn't scroll when the menu is only temporarily visible (also renamed that field)
This commit is contained in:
parent
4667588d23
commit
63e372e092
1 changed files with 30 additions and 26 deletions
|
@ -182,7 +182,7 @@ class ReaderActivity : BaseActivity<ReaderActivityBinding>() {
|
||||||
/**
|
/**
|
||||||
* Whether the menu should stay visible.
|
* Whether the menu should stay visible.
|
||||||
*/
|
*/
|
||||||
private var menuStickyVisible = false
|
private var menuTemporarilyVisible = false
|
||||||
|
|
||||||
private var coroutine: Job? = null
|
private var coroutine: Job? = null
|
||||||
|
|
||||||
|
@ -1119,13 +1119,15 @@ class ReaderActivity : BaseActivity<ReaderActivityBinding>() {
|
||||||
window.navigationBarColor = Color.TRANSPARENT
|
window.navigationBarColor = Color.TRANSPARENT
|
||||||
}
|
}
|
||||||
if (animate && oldVisibility != menuVisible) {
|
if (animate && oldVisibility != menuVisible) {
|
||||||
if (!menuStickyVisible) {
|
if (!menuTemporarilyVisible) {
|
||||||
val toolbarAnimation = AnimationUtils.loadAnimation(this, R.anim.enter_from_top)
|
val toolbarAnimation = AnimationUtils.loadAnimation(this, R.anim.enter_from_top)
|
||||||
toolbarAnimation.doOnStart {
|
toolbarAnimation.doOnStart {
|
||||||
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
|
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
|
||||||
}
|
}
|
||||||
toolbarAnimation.doOnEnd { delayTitleScroll() }
|
toolbarAnimation.doOnEnd { delayTitleScroll() }
|
||||||
binding.appBar.startAnimation(toolbarAnimation)
|
binding.appBar.startAnimation(toolbarAnimation)
|
||||||
|
} else {
|
||||||
|
delayTitleScroll()
|
||||||
}
|
}
|
||||||
binding.chaptersSheet.chaptersBottomSheet.sheetBehavior?.collapse()
|
binding.chaptersSheet.chaptersBottomSheet.sheetBehavior?.collapse()
|
||||||
}
|
}
|
||||||
|
@ -1137,18 +1139,19 @@ class ReaderActivity : BaseActivity<ReaderActivityBinding>() {
|
||||||
|
|
||||||
if (animate && binding.appBar.isVisible) {
|
if (animate && binding.appBar.isVisible) {
|
||||||
val toolbarAnimation = AnimationUtils.loadAnimation(this, R.anim.exit_to_top)
|
val toolbarAnimation = AnimationUtils.loadAnimation(this, R.anim.exit_to_top)
|
||||||
toolbarAnimation.doOnEnd { binding.appBar.isVisible = false }
|
toolbarAnimation.doOnEnd {
|
||||||
|
binding.appBar.isVisible = false
|
||||||
|
stopTitleScroll()
|
||||||
|
}
|
||||||
binding.appBar.startAnimation(toolbarAnimation)
|
binding.appBar.startAnimation(toolbarAnimation)
|
||||||
binding.chaptersSheet.chaptersBottomSheet.sheetBehavior?.isHideable = true
|
binding.chaptersSheet.chaptersBottomSheet.sheetBehavior?.isHideable = true
|
||||||
binding.chaptersSheet.chaptersBottomSheet.sheetBehavior?.hide()
|
binding.chaptersSheet.chaptersBottomSheet.sheetBehavior?.hide()
|
||||||
} else if (!animate) {
|
} else if (!animate) {
|
||||||
binding.appBar.isVisible = false
|
binding.appBar.isVisible = false
|
||||||
}
|
stopTitleScroll()
|
||||||
listOfNotNull(getTitleTextView(), getSubtitleTextView()).forEach { textView ->
|
|
||||||
textView.isSelected = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
menuStickyVisible = false
|
menuTemporarilyVisible = false
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1349,17 +1352,6 @@ class ReaderActivity : BaseActivity<ReaderActivityBinding>() {
|
||||||
|
|
||||||
private fun getTitleTextView(): TextView? = getTextViewsWithText(binding.toolbar.title)
|
private fun getTitleTextView(): TextView? = getTextViewsWithText(binding.toolbar.title)
|
||||||
private fun getSubtitleTextView(): TextView? = getTextViewsWithText(binding.toolbar.subtitle)
|
private fun getSubtitleTextView(): TextView? = getTextViewsWithText(binding.toolbar.subtitle)
|
||||||
private fun delayTitleScroll() {
|
|
||||||
val list = listOfNotNull(getTitleTextView(), getSubtitleTextView())
|
|
||||||
if (list.isNotEmpty()) {
|
|
||||||
scope.launchUI {
|
|
||||||
delay(1000)
|
|
||||||
if (menuVisible || menuStickyVisible) {
|
|
||||||
list.forEach { it.isSelected = true }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getTextViewsWithText(text: CharSequence?): TextView? {
|
private fun getTextViewsWithText(text: CharSequence?): TextView? {
|
||||||
if (text.isNullOrBlank()) return null
|
if (text.isNullOrBlank()) return null
|
||||||
|
@ -1369,6 +1361,21 @@ class ReaderActivity : BaseActivity<ReaderActivityBinding>() {
|
||||||
return if (textViews.isEmpty()) null else Collections.max(textViews, viewTopComparator)
|
return if (textViews.isEmpty()) null else Collections.max(textViews, viewTopComparator)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun delayTitleScroll() {
|
||||||
|
val list = listOfNotNull(getTitleTextView(), getSubtitleTextView())
|
||||||
|
if (list.isNotEmpty()) {
|
||||||
|
scope.launchUI {
|
||||||
|
delay(1000)
|
||||||
|
if (menuVisible) {
|
||||||
|
list.forEach { it.isSelected = true }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun stopTitleScroll() =
|
||||||
|
listOfNotNull(getTitleTextView(), getSubtitleTextView()).forEach { it.isSelected = false }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called from the view model if the initial load couldn't load the pages of the chapter. In
|
* Called from the view model if the initial load couldn't load the pages of the chapter. In
|
||||||
* this case the activity is closed and a toast is shown to the user.
|
* this case the activity is closed and a toast is shown to the user.
|
||||||
|
@ -1738,12 +1745,12 @@ class ReaderActivity : BaseActivity<ReaderActivityBinding>() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onVisibilityChange(visible: Boolean) {
|
private fun onVisibilityChange(visible: Boolean) {
|
||||||
if (visible && !menuStickyVisible && !menuVisible && !binding.appBar.isVisible) {
|
if (visible && !menuTemporarilyVisible && !menuVisible && !binding.appBar.isVisible) {
|
||||||
menuStickyVisible = true
|
menuTemporarilyVisible = true
|
||||||
coroutine = scope.launchUI {
|
coroutine = scope.launchUI {
|
||||||
delay(2000)
|
delay(2000)
|
||||||
if (window.decorView.rootWindowInsetsCompat?.isVisible(statusBars()) == true) {
|
if (window.decorView.rootWindowInsetsCompat?.isVisible(statusBars()) == true) {
|
||||||
menuStickyVisible = false
|
menuTemporarilyVisible = false
|
||||||
setMenuVisibility(false)
|
setMenuVisibility(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1767,12 +1774,9 @@ class ReaderActivity : BaseActivity<ReaderActivityBinding>() {
|
||||||
toolbarAnimation.doOnStart {
|
toolbarAnimation.doOnStart {
|
||||||
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
|
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
|
||||||
}
|
}
|
||||||
toolbarAnimation.doOnEnd {
|
|
||||||
delayTitleScroll()
|
|
||||||
}
|
|
||||||
binding.appBar.startAnimation(toolbarAnimation)
|
binding.appBar.startAnimation(toolbarAnimation)
|
||||||
} else if (!visible && (menuStickyVisible || menuVisible)) {
|
} else if (!visible && (menuTemporarilyVisible || menuVisible)) {
|
||||||
if (menuStickyVisible && !menuVisible) {
|
if (menuTemporarilyVisible && !menuVisible) {
|
||||||
setMenuVisibility(false)
|
setMenuVisibility(false)
|
||||||
}
|
}
|
||||||
coroutine?.cancel()
|
coroutine?.cancel()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue