1
0
Fork 0

For #6820: Updates background, shadow, & snackbars of toolbar

master
Sawyer Blatz 2020-01-31 16:55:02 +01:00 committed by Jeff Boek
parent 4b3effdfab
commit 9f342fca9e
2 changed files with 93 additions and 83 deletions

View File

@ -10,6 +10,7 @@ import android.content.DialogInterface
import android.graphics.Bitmap import android.graphics.Bitmap
import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.BitmapDrawable
import android.os.Bundle import android.os.Bundle
import android.util.Log
import android.view.Gravity import android.view.Gravity
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
@ -96,6 +97,15 @@ import kotlin.math.min
@ExperimentalCoroutinesApi @ExperimentalCoroutinesApi
@SuppressWarnings("TooManyFunctions", "LargeClass") @SuppressWarnings("TooManyFunctions", "LargeClass")
class HomeFragment : Fragment() { class HomeFragment : Fragment() {
private val snackbarAnchorView: View?
get() {
return if (requireContext().settings().shouldUseBottomToolbar) {
toolbarLayout
} else {
null
}
}
private val browsingModeManager get() = (activity as HomeActivity).browsingModeManager private val browsingModeManager get() = (activity as HomeActivity).browsingModeManager
private val singleSessionObserver = object : Session.Observer { private val singleSessionObserver = object : Session.Observer {
@ -210,24 +220,23 @@ class HomeFragment : Fragment() {
} }
private fun updateLayout(view: View) { private fun updateLayout(view: View) {
var shouldUseBottomToolbar = view.context.settings().shouldUseBottomToolbar val shouldUseBottomToolbar = view.context.settings().shouldUseBottomToolbar
ConstraintSet().apply { ConstraintSet().apply {
clone(view.homeLayout) clone(view.homeLayout)
if (shouldUseBottomToolbar) { if (shouldUseBottomToolbar) {
connect(sessionControlView.view.id, TOP, view.wordmark.id, BOTTOM) connect(sessionControlView.view.id, TOP, view.wordmark.id, BOTTOM)
connect(sessionControlView.view.id, BOTTOM, view.bottom_bar.id, TOP) connect(sessionControlView.view.id, BOTTOM, view.toolbarLayout.id, TOP)
connect(view.bottom_bar.id, BOTTOM, PARENT_ID, BOTTOM) connect(view.toolbarLayout.id, BOTTOM, PARENT_ID, BOTTOM)
connect(view.bottomBarShadow.id, BOTTOM, view.bottom_bar.id, TOP)
connect(view.privateBrowsingButton.id, TOP, PARENT_ID, TOP) connect(view.privateBrowsingButton.id, TOP, PARENT_ID, TOP)
} else { } else {
connect(sessionControlView.view.id, TOP, view.wordmark.id, TOP) connect(sessionControlView.view.id, TOP, view.wordmark.id, TOP)
connect(sessionControlView.view.id, BOTTOM, PARENT_ID, BOTTOM) connect(sessionControlView.view.id, BOTTOM, PARENT_ID, BOTTOM)
connect(view.bottomBarShadow.id, BOTTOM, view.bottom_bar.id, BOTTOM) connect(view.privateBrowsingButton.id, TOP, view.toolbarLayout.id, BOTTOM)
connect(view.privateBrowsingButton.id, TOP, view.bottomBarShadow.id, TOP)
} }
connect(sessionControlView.view.id, START, PARENT_ID, START) connect(sessionControlView.view.id, START, PARENT_ID, START)
connect(sessionControlView.view.id, END, PARENT_ID, END) connect(sessionControlView.view.id, END, PARENT_ID, END)
@ -235,8 +244,8 @@ class HomeFragment : Fragment() {
applyTo(view.homeLayout) applyTo(view.homeLayout)
} }
var headingsTopMargins = if (shouldUseBottomToolbar) { HEADER_MARGIN } else { TOP_TOOLBAR_HEADER_MARGIN } val headingsTopMargins = if (shouldUseBottomToolbar) { HEADER_MARGIN } else { TOP_TOOLBAR_HEADER_MARGIN }
var sessionControlViewTopMargin = if (shouldUseBottomToolbar) { val sessionControlViewTopMargin = if (shouldUseBottomToolbar) {
SESSION_CONTROL_VIEW_TOP_MARGIN SESSION_CONTROL_VIEW_TOP_MARGIN
} else { } else {
SESSION_CONTROL_VIEW_TOP_TOOLBAR_MARGIN SESSION_CONTROL_VIEW_TOP_TOOLBAR_MARGIN
@ -341,9 +350,6 @@ class HomeFragment : Fragment() {
HomeFragmentAction.ModeChange(Mode.fromBrowsingMode(newMode))) HomeFragmentAction.ModeChange(Mode.fromBrowsingMode(newMode)))
} }
} }
// We need the shadow to be above the components.
bottomBarShadow.bringToFront()
} }
override fun onStart() { override fun onStart() {
@ -368,7 +374,7 @@ class HomeFragment : Fragment() {
view?.let { view?.let {
FenixSnackbar.make(it, Snackbar.LENGTH_SHORT) FenixSnackbar.make(it, Snackbar.LENGTH_SHORT)
.setText(it.context.getString(R.string.onboarding_firefox_account_sync_is_on)) .setText(it.context.getString(R.string.onboarding_firefox_account_sync_is_on))
.setAnchorView(bottom_bar) .setAnchorView(toolbarLayout)
.show() .show()
} }
} }
@ -648,7 +654,7 @@ class HomeFragment : Fragment() {
emitSessionChanges() emitSessionChanges()
}, },
operation = deleteOperation, operation = deleteOperation,
anchorView = bottom_bar anchorView = snackbarAnchorView
) )
} }
@ -678,7 +684,7 @@ class HomeFragment : Fragment() {
emitSessionChanges() emitSessionChanges()
}, },
operation = deleteOperation, operation = deleteOperation,
anchorView = bottom_bar anchorView = snackbarAnchorView
) )
// Update the UI with the tab removed, but don't remove it from storage yet // Update the UI with the tab removed, but don't remove it from storage yet

View File

@ -39,14 +39,16 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/bottomBarShadow"
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/toolbarLayout"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="1dp" android:elevation="5dp"
android:background="@color/bottom_bar_shadow" android:layout_height="wrap_content"
android:background="?bottomBarBackground"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent">
app:layout_constraintBottom_toTopOf="@id/bottom_bar" />
<View <View
android:id="@+id/bottom_bar" android:id="@+id/bottom_bar"
@ -54,7 +56,8 @@
android:layout_height="56dp" android:layout_height="56dp"
android:background="?bottomBarBackground" android:background="?bottomBarBackground"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" /> app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent"/>
<org.mozilla.fenix.home.SearchView <org.mozilla.fenix.home.SearchView
android:id="@+id/toolbar_wrapper" android:id="@+id/toolbar_wrapper"
@ -67,10 +70,10 @@
android:contentDescription="@string/search_hint" android:contentDescription="@string/search_hint"
android:focusable="true" android:focusable="true"
android:transitionName="toolbar_wrapper_transition" android:transitionName="toolbar_wrapper_transition"
app:layout_constraintBottom_toBottomOf="@id/bottom_bar" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/add_tab_button" app:layout_constraintEnd_toStartOf="@+id/add_tab_button"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/bottom_bar"> app:layout_constraintTop_toTopOf="parent">
<ImageView <ImageView
android:id="@+id/search_engine_icon" android:id="@+id/search_engine_icon"
@ -105,8 +108,8 @@
android:background="?android:attr/selectableItemBackgroundBorderless" android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/add_tab" android:contentDescription="@string/add_tab"
app:srcCompat="@drawable/ic_new" app:srcCompat="@drawable/ic_new"
app:layout_constraintTop_toTopOf="@id/bottom_bar" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="@id/bottom_bar" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/menuButton" app:layout_constraintEnd_toStartOf="@+id/menuButton"
app:layout_constraintStart_toEndOf="@id/toolbar_wrapper"/> app:layout_constraintStart_toEndOf="@id/toolbar_wrapper"/>
@ -115,7 +118,8 @@
android:layout_width="36dp" android:layout_width="36dp"
android:layout_height="48dp" android:layout_height="48dp"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/bottom_bar" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="@id/bottom_bar"/> app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.motion.widget.MotionLayout> </androidx.constraintlayout.motion.widget.MotionLayout>