From f473e46c929f9fae61e3ac0d70b40b079746f1ff Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Wed, 28 Apr 2021 00:24:46 -0400 Subject: [PATCH] Using a helper to get the toolbar height since there's 2, one of them might be hidden and have a height of 0 --- .../tachiyomi/ui/download/DownloadBottomSheet.kt | 4 ++-- .../eu/kanade/tachiyomi/ui/main/MainActivity.kt | 4 ++++ .../eu/kanade/tachiyomi/ui/main/OverflowDialog.kt | 3 +-- .../tachiyomi/ui/recents/RecentsController.kt | 3 ++- .../global_search/GlobalSearchController.kt | 5 ++--- .../tachiyomi/util/view/ControllerExtensions.kt | 15 +++++++++------ 6 files changed, 20 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadBottomSheet.kt index 555b16c85c..80e425b4cd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadBottomSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadBottomSheet.kt @@ -13,7 +13,6 @@ import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.databinding.DownloadBottomSheetBinding import eu.kanade.tachiyomi.ui.extension.ExtensionDividerItemDecoration import eu.kanade.tachiyomi.ui.recents.RecentsController -import eu.kanade.tachiyomi.util.view.activityBinding import eu.kanade.tachiyomi.util.view.collapse import eu.kanade.tachiyomi.util.view.doOnApplyWindowInsets import eu.kanade.tachiyomi.util.view.expand @@ -21,6 +20,7 @@ import eu.kanade.tachiyomi.util.view.hide import eu.kanade.tachiyomi.util.view.isCollapsed import eu.kanade.tachiyomi.util.view.isExpanded import eu.kanade.tachiyomi.util.view.isHidden +import eu.kanade.tachiyomi.util.view.toolbarHeight import eu.kanade.tachiyomi.util.view.updateLayoutParams class DownloadBottomSheet @JvmOverloads constructor( @@ -74,7 +74,7 @@ class DownloadBottomSheet @JvmOverloads constructor( binding.recyclerLayout.doOnApplyWindowInsets { v, windowInsets, _ -> v.updateLayoutParams { topMargin = windowInsets.systemWindowInsetTop + - (controller.activityBinding?.toolbar?.height ?: headerHeight) - + (controller.toolbarHeight ?: headerHeight) - binding.sheetLayout.height } } 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 ee4a26c8e9..863afa8804 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 @@ -90,6 +90,7 @@ import uy.kohesive.injekt.injectLazy import java.util.Date import java.util.concurrent.TimeUnit import kotlin.math.abs +import kotlin.math.max open class MainActivity : BaseActivity(), DownloadServiceListener { @@ -129,6 +130,9 @@ open class MainActivity : BaseActivity(), DownloadServiceLi extraViewForUndo = extraViewToCheck } + val toolbarHeight: Int + get() = max(binding.toolbar.height, binding.cardFrame.height) + override fun onCreate(savedInstanceState: Bundle?) { // Create a webview before extensions do or else they will break night mode theme // https://stackoverflow.com/questions/54191883 diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/OverflowDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/OverflowDialog.kt index a0ad5025b4..2953c0d5c8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/OverflowDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/OverflowDialog.kt @@ -15,7 +15,6 @@ import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.system.openInBrowser import eu.kanade.tachiyomi.util.view.updateLayoutParams import uy.kohesive.injekt.injectLazy -import kotlin.math.max class OverflowDialog(activity: MainActivity) : Dialog(activity, R.style.OverflowDialogTheme) { @@ -77,7 +76,7 @@ class OverflowDialog(activity: MainActivity) : Dialog(activity, R.style.Overflow } binding.overflowCardView.updateLayoutParams { - topMargin = max(activity.binding.toolbar.height, activity.binding.cardFrame.height) - 2.dpToPx + topMargin = activity.toolbarHeight - 2.dpToPx } window?.let { window -> window.navigationBarColor = Color.TRANSPARENT diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt index c5899617f3..34277893cc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt @@ -51,6 +51,7 @@ import eu.kanade.tachiyomi.util.view.setOnQueryTextChangeListener import eu.kanade.tachiyomi.util.view.setStyle import eu.kanade.tachiyomi.util.view.smoothScrollToTop import eu.kanade.tachiyomi.util.view.snack +import eu.kanade.tachiyomi.util.view.toolbarHeight import eu.kanade.tachiyomi.util.view.updateLayoutParams import eu.kanade.tachiyomi.util.view.updatePaddingRelative import eu.kanade.tachiyomi.util.view.withFadeTransaction @@ -151,7 +152,7 @@ class RecentsController(bundle: Bundle? = null) : afterInsets = { headerHeight = it.systemWindowInsetTop + appBarHeight + 48.dpToPx binding.fakeAppBar.updateLayoutParams { - height = it.systemWindowInsetTop + (activityBinding?.toolbar?.height ?: appBarHeight) + height = it.systemWindowInsetTop + (toolbarHeight ?: appBarHeight) } binding.recycler.updatePaddingRelative( bottom = activityBinding?.bottomNav?.height ?: 0 diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/global_search/GlobalSearchController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/global_search/GlobalSearchController.kt index 172e04b58d..8d4af2b2fd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/global_search/GlobalSearchController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/global_search/GlobalSearchController.kt @@ -21,13 +21,12 @@ import eu.kanade.tachiyomi.ui.main.SearchActivity import eu.kanade.tachiyomi.ui.manga.MangaDetailsController import eu.kanade.tachiyomi.ui.source.browse.BrowseSourceController import eu.kanade.tachiyomi.util.addOrRemoveToFavorites -import eu.kanade.tachiyomi.util.view.activityBinding import eu.kanade.tachiyomi.util.view.scrollViewWith import eu.kanade.tachiyomi.util.view.snack +import eu.kanade.tachiyomi.util.view.toolbarHeight import eu.kanade.tachiyomi.util.view.updatePaddingRelative import eu.kanade.tachiyomi.util.view.withFadeTransaction import uy.kohesive.injekt.injectLazy -import kotlin.math.max /** * This controller shows and manages the different search result in global search. @@ -182,7 +181,7 @@ open class GlobalSearchController( adapter = GlobalSearchAdapter(this) binding.recycler.updatePaddingRelative( - top = max(activityBinding?.toolbar?.height ?: 0, (activityBinding?.cardToolbar?.height ?: 0)) + + top = (toolbarHeight ?: 0) + (activity?.window?.decorView?.rootWindowInsets?.systemWindowInsetTop ?: 0) ) diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/view/ControllerExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/view/ControllerExtensions.kt index 073fcf6f02..06d003450b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/view/ControllerExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/view/ControllerExtensions.kt @@ -90,13 +90,13 @@ fun Controller.liftAppbarWith(recycler: RecyclerView, padView: Boolean = false) val attrsArray = intArrayOf(R.attr.actionBarSize) val array = recycler.context.obtainStyledAttributes(attrsArray) var appBarHeight = ( - if (activityBinding?.toolbar?.height ?: 0 > 0) activityBinding!!.toolbar.height + if (toolbarHeight ?: 0 > 0) toolbarHeight!! else array.getDimensionPixelSize(0, 0) ) array.recycle() activityBinding!!.toolbar.post { - if (activityBinding!!.toolbar.height > 0) { - appBarHeight = activityBinding!!.toolbar.height + if (toolbarHeight!! > 0) { + appBarHeight = toolbarHeight!! recycler.requestApplyInsets() } } @@ -174,14 +174,14 @@ fun Controller.scrollViewWith( val attrsArray = intArrayOf(R.attr.actionBarSize) val array = recycler.context.obtainStyledAttributes(attrsArray) var appBarHeight = ( - if (activityBinding?.toolbar?.height ?: 0 > 0) activityBinding!!.toolbar.height + if (toolbarHeight ?: 0 > 0) toolbarHeight!! else array.getDimensionPixelSize(0, 0) ) + if (includeTabView) tabBarHeight else 0 array.recycle() swipeRefreshLayout?.setDistanceToTriggerSync(150.dpToPx) activityBinding!!.toolbar.post { - if (activityBinding!!.toolbar.height > 0) { - appBarHeight = activityBinding!!.toolbar.height + if (includeTabView) tabBarHeight else 0 + if (toolbarHeight!! > 0) { + appBarHeight = toolbarHeight!! + if (includeTabView) tabBarHeight else 0 recycler.requestApplyInsets() } } @@ -460,3 +460,6 @@ fun Controller.openInBrowser(url: String) { val Controller.activityBinding: MainActivityBinding? get() = (activity as? MainActivity)?.binding + +val Controller.toolbarHeight: Int? + get() = (activity as? MainActivity)?.toolbarHeight