diff --git a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt index 707654108..2ec6795ba 100644 --- a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt @@ -202,23 +202,59 @@ class HomeFragment : Fragment() { sessionControlView = SessionControlView(homeFragmentStore, view.homeLayout, sessionControlInteractor) + updateLayout(view) + + activity.themeManager.applyStatusBarTheme(activity) + + return view + } + + private fun updateLayout(view: View) { + var shouldUseBottomToolbar = view.context.settings().shouldUseBottomToolbar + ConstraintSet().apply { clone(view.homeLayout) - connect(sessionControlView.view.id, TOP, view.wordmark.id, BOTTOM) + + if (shouldUseBottomToolbar) { + connect(sessionControlView.view.id, TOP, view.wordmark.id, BOTTOM) + connect(sessionControlView.view.id, BOTTOM, view.bottom_bar.id, TOP) + + connect(view.bottom_bar.id, BOTTOM, PARENT_ID, BOTTOM) + connect(view.bottomBarShadow.id, BOTTOM, view.bottom_bar.id, TOP) + connect(view.privateBrowsingButton.id, TOP, PARENT_ID, TOP) + } else { + connect(sessionControlView.view.id, TOP, view.wordmark.id, TOP) + connect(sessionControlView.view.id, BOTTOM, PARENT_ID, BOTTOM) + + connect(view.bottomBarShadow.id, BOTTOM, view.bottom_bar.id, BOTTOM) + connect(view.privateBrowsingButton.id, TOP, view.bottomBarShadow.id, TOP) + } connect(sessionControlView.view.id, START, PARENT_ID, START) connect(sessionControlView.view.id, END, PARENT_ID, END) - connect(sessionControlView.view.id, BOTTOM, view.bottom_bar.id, TOP) + applyTo(view.homeLayout) } - @Suppress("MagicNumber") // we need constants if we define layouts in code. - sessionControlView.view.updateLayoutParams { - topMargin = 32.dpToPx(resources.displayMetrics) + var headingsTopMargins = if (shouldUseBottomToolbar) { HEADER_MARGIN } else { TOP_TOOLBAR_HEADER_MARGIN } + var sessionControlViewTopMargin = if (shouldUseBottomToolbar) { + SESSION_CONTROL_VIEW_TOP_MARGIN + } else { + SESSION_CONTROL_VIEW_TOP_TOOLBAR_MARGIN } - activity.themeManager.applyStatusBarTheme(activity) + view.wordmark.updateLayoutParams { + topMargin = headingsTopMargins.dpToPx(resources.displayMetrics) + } - return view + sessionControlView.view.updateLayoutParams { + topMargin = sessionControlViewTopMargin.dpToPx(resources.displayMetrics) + } + + if (!shouldUseBottomToolbar) { + view.privateBrowsingButton.updateLayoutParams { + topMargin = PRIVATE_BROWSING_BUTTON_TOP_MARGIN.dpToPx(resources.displayMetrics) + } + } } @ExperimentalCoroutinesApi @@ -799,6 +835,13 @@ class HomeFragment : Fragment() { private const val SHARED_TRANSITION_MS = 200L private const val CFR_WIDTH_DIVIDER = 1.7 private const val CFR_Y_OFFSET = -20 + + // Layout + private const val HEADER_MARGIN = 60 + private const val TOP_TOOLBAR_HEADER_MARGIN = 120 + private const val SESSION_CONTROL_VIEW_TOP_MARGIN = 32 + private const val SESSION_CONTROL_VIEW_TOP_TOOLBAR_MARGIN = 64 + private const val PRIVATE_BROWSING_BUTTON_TOP_MARGIN = 40 } } diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index e8f67597c..1042b4dc5 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -22,15 +22,13 @@ android:contentDescription="@string/content_description_private_browsing_button" app:srcCompat="@drawable/private_browsing_button" app:layout_constraintBottom_toTopOf="@+id/wordmark" - app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintEnd_toEndOf="parent" />