Less hacky way to make sure bottom action toolbar doesn't scroll down (#5871)
* Less hacky way to make sure bottom action toolbar doesn't scroll down * Fix action toolbar overlapping on landscape * Disable app bar transparency when ActionMode is present
This commit is contained in:
parent
52daf3d58c
commit
7b3c18bb97
4 changed files with 29 additions and 28 deletions
|
@ -169,7 +169,7 @@ class LibraryController(
|
|||
|
||||
binding.actionToolbar.applyInsetter {
|
||||
type(navigationBars = true) {
|
||||
margin(bottom = true)
|
||||
margin(bottom = true, horizontal = true)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -216,8 +216,6 @@ class LibraryController(
|
|||
)
|
||||
}
|
||||
.launchIn(viewScope)
|
||||
|
||||
(activity as? MainActivity)?.fixViewToBottom(binding.actionToolbar)
|
||||
}
|
||||
|
||||
override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) {
|
||||
|
@ -230,7 +228,6 @@ class LibraryController(
|
|||
|
||||
override fun onDestroyView(view: View) {
|
||||
destroyActionModeIfNeeded()
|
||||
(activity as? MainActivity)?.clearFixViewToBottom(binding.actionToolbar)
|
||||
binding.actionToolbar.destroy()
|
||||
adapter?.onDestroy()
|
||||
adapter = null
|
||||
|
|
|
@ -7,9 +7,9 @@ import android.graphics.Color
|
|||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.view.Gravity
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.view.ActionMode
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
import androidx.core.animation.doOnEnd
|
||||
import androidx.core.splashscreen.SplashScreen
|
||||
|
@ -91,8 +91,6 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
|
|||
private var isConfirmingExit: Boolean = false
|
||||
private var isHandlingShortcut: Boolean = false
|
||||
|
||||
private var fixedViewsToBottom = mutableMapOf<View, AppBarLayout.OnOffsetChangedListener>()
|
||||
|
||||
/**
|
||||
* App bar lift state for backstack
|
||||
*/
|
||||
|
@ -477,6 +475,24 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
|
|||
}
|
||||
}
|
||||
|
||||
override fun onSupportActionModeStarted(mode: ActionMode) {
|
||||
binding.appbar.apply {
|
||||
tag = isTransparentWhenNotLifted
|
||||
isTransparentWhenNotLifted = false
|
||||
}
|
||||
setToolbarScrolls(false)
|
||||
super.onSupportActionModeStarted(mode)
|
||||
}
|
||||
|
||||
override fun onSupportActionModeFinished(mode: ActionMode) {
|
||||
binding.appbar.apply {
|
||||
isTransparentWhenNotLifted = (tag as? Boolean) ?: false
|
||||
tag = null
|
||||
}
|
||||
setToolbarScrolls(true)
|
||||
super.onSupportActionModeFinished(mode)
|
||||
}
|
||||
|
||||
private suspend fun resetExitConfirmation() {
|
||||
isConfirmingExit = true
|
||||
val toast = toast(R.string.confirm_exit, Toast.LENGTH_LONG)
|
||||
|
@ -595,21 +611,15 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
|
|||
}
|
||||
|
||||
/**
|
||||
* Used to manually offset a view within the activity's child views that might be cut off due to
|
||||
* the collapsing AppBarLayout.
|
||||
* Sets toolbar CoordinatorLayout scroll flags
|
||||
*/
|
||||
fun fixViewToBottom(view: View) {
|
||||
val listener = AppBarLayout.OnOffsetChangedListener { appBarLayout, verticalOffset ->
|
||||
val maxAbsOffset = appBarLayout.measuredHeight - binding.tabs.measuredHeight
|
||||
view.translationY = -maxAbsOffset - verticalOffset.toFloat() + appBarLayout.paddingTop
|
||||
private fun setToolbarScrolls(enabled: Boolean) = binding.toolbar.updateLayoutParams<AppBarLayout.LayoutParams> {
|
||||
if (isTablet()) return@updateLayoutParams
|
||||
scrollFlags = if (enabled) {
|
||||
AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL or AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS
|
||||
} else {
|
||||
0
|
||||
}
|
||||
binding.appbar.addOnOffsetChangedListener(listener)
|
||||
fixedViewsToBottom[view] = listener
|
||||
}
|
||||
|
||||
fun clearFixViewToBottom(view: View) {
|
||||
val listener = fixedViewsToBottom.remove(view)
|
||||
binding.appbar.removeOnOffsetChangedListener(listener)
|
||||
}
|
||||
|
||||
private fun setBottomNavBehaviorOnScroll() {
|
||||
|
|
|
@ -235,7 +235,7 @@ class MangaController :
|
|||
}
|
||||
binding.actionToolbar.applyInsetter {
|
||||
type(navigationBars = true) {
|
||||
margin(bottom = true)
|
||||
margin(bottom = true, horizontal = true)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -329,8 +329,6 @@ class MangaController :
|
|||
}
|
||||
.launchIn(viewScope)
|
||||
|
||||
(activity as? MainActivity)?.fixViewToBottom(binding.actionToolbar)
|
||||
|
||||
settingsSheet = ChaptersSettingsSheet(router, presenter) { group ->
|
||||
if (group is ChaptersSettingsSheet.Filter.FilterGroup) {
|
||||
updateFilterIconState()
|
||||
|
@ -402,7 +400,6 @@ class MangaController :
|
|||
|
||||
override fun onDestroyView(view: View) {
|
||||
destroyActionModeIfNeeded()
|
||||
(activity as? MainActivity)?.clearFixViewToBottom(binding.actionToolbar)
|
||||
binding.actionToolbar.destroy()
|
||||
mangaInfoAdapter = null
|
||||
chaptersHeaderAdapter = null
|
||||
|
|
|
@ -82,7 +82,7 @@ class UpdatesController :
|
|||
}
|
||||
binding.actionToolbar.applyInsetter {
|
||||
type(navigationBars = true) {
|
||||
margin(bottom = true)
|
||||
margin(bottom = true, horizontal = true)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -113,13 +113,10 @@ class UpdatesController :
|
|||
binding.swipeRefresh.isRefreshing = false
|
||||
}
|
||||
.launchIn(viewScope)
|
||||
|
||||
(activity as? MainActivity)?.fixViewToBottom(binding.actionToolbar)
|
||||
}
|
||||
|
||||
override fun onDestroyView(view: View) {
|
||||
destroyActionModeIfNeeded()
|
||||
(activity as? MainActivity)?.clearFixViewToBottom(binding.actionToolbar)
|
||||
binding.actionToolbar.destroy()
|
||||
adapter = null
|
||||
super.onDestroyView(view)
|
||||
|
|
Reference in a new issue