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

View File

@ -39,83 +39,87 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/bottomBarShadow"
android:layout_width="0dp"
android:layout_height="1dp"
android:background="@color/bottom_bar_shadow"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="@id/bottom_bar" />
<View
android:id="@+id/bottom_bar"
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/toolbarLayout"
android:layout_width="0dp"
android:layout_height="56dp"
android:elevation="5dp"
android:layout_height="wrap_content"
android:background="?bottomBarBackground"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
app:layout_constraintStart_toStartOf="parent">
<org.mozilla.fenix.home.SearchView
android:id="@+id/toolbar_wrapper"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="0dp"
android:background="@drawable/home_search_background_normal"
android:clickable="true"
android:contentDescription="@string/search_hint"
android:focusable="true"
android:transitionName="toolbar_wrapper_transition"
app:layout_constraintBottom_toBottomOf="@id/bottom_bar"
app:layout_constraintEnd_toStartOf="@+id/add_tab_button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/bottom_bar">
<View
android:id="@+id/bottom_bar"
android:layout_width="0dp"
android:layout_height="56dp"
android:background="?bottomBarBackground"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent"/>
<ImageView
android:id="@+id/search_engine_icon"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="start|center_vertical"
<org.mozilla.fenix.home.SearchView
android:id="@+id/toolbar_wrapper"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_marginStart="8dp"
android:clickable="false"
android:focusable="false"
android:importantForAccessibility="no" />
android:layout_marginEnd="0dp"
android:background="@drawable/home_search_background_normal"
android:clickable="true"
android:contentDescription="@string/search_hint"
android:focusable="true"
android:transitionName="toolbar_wrapper_transition"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/add_tab_button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/toolbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start|center_vertical"
android:layout_marginStart="44dp"
android:clickable="false"
android:ellipsize="end"
android:focusable="false"
android:importantForAccessibility="no"
android:lines="1"
android:text="@string/search_hint"
android:textColor="?primaryText"
android:textSize="15sp" />
</org.mozilla.fenix.home.SearchView>
<ImageView
android:id="@+id/search_engine_icon"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="start|center_vertical"
android:layout_marginStart="8dp"
android:clickable="false"
android:focusable="false"
android:importantForAccessibility="no" />
<ImageButton
android:id="@+id/add_tab_button"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/add_tab"
app:srcCompat="@drawable/ic_new"
app:layout_constraintTop_toTopOf="@id/bottom_bar"
app:layout_constraintBottom_toBottomOf="@id/bottom_bar"
app:layout_constraintEnd_toStartOf="@+id/menuButton"
app:layout_constraintStart_toEndOf="@id/toolbar_wrapper"/>
<mozilla.components.browser.menu.view.MenuButton
android:id="@+id/menuButton"
android:layout_width="36dp"
android:layout_height="48dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/bottom_bar"
app:layout_constraintBottom_toBottomOf="@id/bottom_bar"/>
<TextView
android:id="@+id/toolbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start|center_vertical"
android:layout_marginStart="44dp"
android:clickable="false"
android:ellipsize="end"
android:focusable="false"
android:importantForAccessibility="no"
android:lines="1"
android:text="@string/search_hint"
android:textColor="?primaryText"
android:textSize="15sp" />
</org.mozilla.fenix.home.SearchView>
<ImageButton
android:id="@+id/add_tab_button"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/add_tab"
app:srcCompat="@drawable/ic_new"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/menuButton"
app:layout_constraintStart_toEndOf="@id/toolbar_wrapper"/>
<mozilla.components.browser.menu.view.MenuButton
android:id="@+id/menuButton"
android:layout_width="36dp"
android:layout_height="48dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.motion.widget.MotionLayout>