Using a helper to get the toolbar height

since there's 2, one of them might be hidden and have a height of 0
This commit is contained in:
Jays2Kings 2021-04-28 00:24:46 -04:00
parent 798c93b44b
commit f473e46c92
6 changed files with 20 additions and 14 deletions

View File

@ -13,7 +13,6 @@ import eu.kanade.tachiyomi.data.download.model.Download
import eu.kanade.tachiyomi.databinding.DownloadBottomSheetBinding import eu.kanade.tachiyomi.databinding.DownloadBottomSheetBinding
import eu.kanade.tachiyomi.ui.extension.ExtensionDividerItemDecoration import eu.kanade.tachiyomi.ui.extension.ExtensionDividerItemDecoration
import eu.kanade.tachiyomi.ui.recents.RecentsController 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.collapse
import eu.kanade.tachiyomi.util.view.doOnApplyWindowInsets import eu.kanade.tachiyomi.util.view.doOnApplyWindowInsets
import eu.kanade.tachiyomi.util.view.expand 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.isCollapsed
import eu.kanade.tachiyomi.util.view.isExpanded import eu.kanade.tachiyomi.util.view.isExpanded
import eu.kanade.tachiyomi.util.view.isHidden import eu.kanade.tachiyomi.util.view.isHidden
import eu.kanade.tachiyomi.util.view.toolbarHeight
import eu.kanade.tachiyomi.util.view.updateLayoutParams import eu.kanade.tachiyomi.util.view.updateLayoutParams
class DownloadBottomSheet @JvmOverloads constructor( class DownloadBottomSheet @JvmOverloads constructor(
@ -74,7 +74,7 @@ class DownloadBottomSheet @JvmOverloads constructor(
binding.recyclerLayout.doOnApplyWindowInsets { v, windowInsets, _ -> binding.recyclerLayout.doOnApplyWindowInsets { v, windowInsets, _ ->
v.updateLayoutParams<MarginLayoutParams> { v.updateLayoutParams<MarginLayoutParams> {
topMargin = windowInsets.systemWindowInsetTop + topMargin = windowInsets.systemWindowInsetTop +
(controller.activityBinding?.toolbar?.height ?: headerHeight) - (controller.toolbarHeight ?: headerHeight) -
binding.sheetLayout.height binding.sheetLayout.height
} }
} }

View File

@ -90,6 +90,7 @@ import uy.kohesive.injekt.injectLazy
import java.util.Date import java.util.Date
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import kotlin.math.abs import kotlin.math.abs
import kotlin.math.max
open class MainActivity : BaseActivity<MainActivityBinding>(), DownloadServiceListener { open class MainActivity : BaseActivity<MainActivityBinding>(), DownloadServiceListener {
@ -129,6 +130,9 @@ open class MainActivity : BaseActivity<MainActivityBinding>(), DownloadServiceLi
extraViewForUndo = extraViewToCheck extraViewForUndo = extraViewToCheck
} }
val toolbarHeight: Int
get() = max(binding.toolbar.height, binding.cardFrame.height)
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
// Create a webview before extensions do or else they will break night mode theme // Create a webview before extensions do or else they will break night mode theme
// https://stackoverflow.com/questions/54191883 // https://stackoverflow.com/questions/54191883

View File

@ -15,7 +15,6 @@ import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.system.openInBrowser import eu.kanade.tachiyomi.util.system.openInBrowser
import eu.kanade.tachiyomi.util.view.updateLayoutParams import eu.kanade.tachiyomi.util.view.updateLayoutParams
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
import kotlin.math.max
class OverflowDialog(activity: MainActivity) : Dialog(activity, R.style.OverflowDialogTheme) { 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<ViewGroup.MarginLayoutParams> { binding.overflowCardView.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = max(activity.binding.toolbar.height, activity.binding.cardFrame.height) - 2.dpToPx topMargin = activity.toolbarHeight - 2.dpToPx
} }
window?.let { window -> window?.let { window ->
window.navigationBarColor = Color.TRANSPARENT window.navigationBarColor = Color.TRANSPARENT

View File

@ -51,6 +51,7 @@ import eu.kanade.tachiyomi.util.view.setOnQueryTextChangeListener
import eu.kanade.tachiyomi.util.view.setStyle import eu.kanade.tachiyomi.util.view.setStyle
import eu.kanade.tachiyomi.util.view.smoothScrollToTop import eu.kanade.tachiyomi.util.view.smoothScrollToTop
import eu.kanade.tachiyomi.util.view.snack 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.updateLayoutParams
import eu.kanade.tachiyomi.util.view.updatePaddingRelative import eu.kanade.tachiyomi.util.view.updatePaddingRelative
import eu.kanade.tachiyomi.util.view.withFadeTransaction import eu.kanade.tachiyomi.util.view.withFadeTransaction
@ -151,7 +152,7 @@ class RecentsController(bundle: Bundle? = null) :
afterInsets = { afterInsets = {
headerHeight = it.systemWindowInsetTop + appBarHeight + 48.dpToPx headerHeight = it.systemWindowInsetTop + appBarHeight + 48.dpToPx
binding.fakeAppBar.updateLayoutParams<ViewGroup.MarginLayoutParams> { binding.fakeAppBar.updateLayoutParams<ViewGroup.MarginLayoutParams> {
height = it.systemWindowInsetTop + (activityBinding?.toolbar?.height ?: appBarHeight) height = it.systemWindowInsetTop + (toolbarHeight ?: appBarHeight)
} }
binding.recycler.updatePaddingRelative( binding.recycler.updatePaddingRelative(
bottom = activityBinding?.bottomNav?.height ?: 0 bottom = activityBinding?.bottomNav?.height ?: 0

View File

@ -21,13 +21,12 @@ import eu.kanade.tachiyomi.ui.main.SearchActivity
import eu.kanade.tachiyomi.ui.manga.MangaDetailsController import eu.kanade.tachiyomi.ui.manga.MangaDetailsController
import eu.kanade.tachiyomi.ui.source.browse.BrowseSourceController import eu.kanade.tachiyomi.ui.source.browse.BrowseSourceController
import eu.kanade.tachiyomi.util.addOrRemoveToFavorites 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.scrollViewWith
import eu.kanade.tachiyomi.util.view.snack 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.updatePaddingRelative
import eu.kanade.tachiyomi.util.view.withFadeTransaction import eu.kanade.tachiyomi.util.view.withFadeTransaction
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
import kotlin.math.max
/** /**
* This controller shows and manages the different search result in global search. * This controller shows and manages the different search result in global search.
@ -182,7 +181,7 @@ open class GlobalSearchController(
adapter = GlobalSearchAdapter(this) adapter = GlobalSearchAdapter(this)
binding.recycler.updatePaddingRelative( binding.recycler.updatePaddingRelative(
top = max(activityBinding?.toolbar?.height ?: 0, (activityBinding?.cardToolbar?.height ?: 0)) + top = (toolbarHeight ?: 0) +
(activity?.window?.decorView?.rootWindowInsets?.systemWindowInsetTop ?: 0) (activity?.window?.decorView?.rootWindowInsets?.systemWindowInsetTop ?: 0)
) )

View File

@ -90,13 +90,13 @@ fun Controller.liftAppbarWith(recycler: RecyclerView, padView: Boolean = false)
val attrsArray = intArrayOf(R.attr.actionBarSize) val attrsArray = intArrayOf(R.attr.actionBarSize)
val array = recycler.context.obtainStyledAttributes(attrsArray) val array = recycler.context.obtainStyledAttributes(attrsArray)
var appBarHeight = ( var appBarHeight = (
if (activityBinding?.toolbar?.height ?: 0 > 0) activityBinding!!.toolbar.height if (toolbarHeight ?: 0 > 0) toolbarHeight!!
else array.getDimensionPixelSize(0, 0) else array.getDimensionPixelSize(0, 0)
) )
array.recycle() array.recycle()
activityBinding!!.toolbar.post { activityBinding!!.toolbar.post {
if (activityBinding!!.toolbar.height > 0) { if (toolbarHeight!! > 0) {
appBarHeight = activityBinding!!.toolbar.height appBarHeight = toolbarHeight!!
recycler.requestApplyInsets() recycler.requestApplyInsets()
} }
} }
@ -174,14 +174,14 @@ fun Controller.scrollViewWith(
val attrsArray = intArrayOf(R.attr.actionBarSize) val attrsArray = intArrayOf(R.attr.actionBarSize)
val array = recycler.context.obtainStyledAttributes(attrsArray) val array = recycler.context.obtainStyledAttributes(attrsArray)
var appBarHeight = ( var appBarHeight = (
if (activityBinding?.toolbar?.height ?: 0 > 0) activityBinding!!.toolbar.height if (toolbarHeight ?: 0 > 0) toolbarHeight!!
else array.getDimensionPixelSize(0, 0) else array.getDimensionPixelSize(0, 0)
) + if (includeTabView) tabBarHeight else 0 ) + if (includeTabView) tabBarHeight else 0
array.recycle() array.recycle()
swipeRefreshLayout?.setDistanceToTriggerSync(150.dpToPx) swipeRefreshLayout?.setDistanceToTriggerSync(150.dpToPx)
activityBinding!!.toolbar.post { activityBinding!!.toolbar.post {
if (activityBinding!!.toolbar.height > 0) { if (toolbarHeight!! > 0) {
appBarHeight = activityBinding!!.toolbar.height + if (includeTabView) tabBarHeight else 0 appBarHeight = toolbarHeight!! + if (includeTabView) tabBarHeight else 0
recycler.requestApplyInsets() recycler.requestApplyInsets()
} }
} }
@ -460,3 +460,6 @@ fun Controller.openInBrowser(url: String) {
val Controller.activityBinding: MainActivityBinding? val Controller.activityBinding: MainActivityBinding?
get() = (activity as? MainActivity)?.binding get() = (activity as? MainActivity)?.binding
val Controller.toolbarHeight: Int?
get() = (activity as? MainActivity)?.toolbarHeight