From 7b3c18bb97e1ca6b8889d7aa271d715cfee684d4 Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Sat, 11 Sep 2021 21:22:01 +0700 Subject: [PATCH] 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 --- .../tachiyomi/ui/library/LibraryController.kt | 5 +-- .../kanade/tachiyomi/ui/main/MainActivity.kt | 42 ++++++++++++------- .../tachiyomi/ui/manga/MangaController.kt | 5 +-- .../ui/recent/updates/UpdatesController.kt | 5 +-- 4 files changed, 29 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index 2ca72ac980..d45c605857 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -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 diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index 0f397e6057..e261520e6c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -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() { private var isConfirmingExit: Boolean = false private var isHandlingShortcut: Boolean = false - private var fixedViewsToBottom = mutableMapOf() - /** * App bar lift state for backstack */ @@ -477,6 +475,24 @@ class MainActivity : BaseViewBindingActivity() { } } + 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() { } /** - * 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 { + 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() { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt index 4c1067ca45..838d8f91f0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt @@ -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 diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt index aa8827494b..620e10e725 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt @@ -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)