diff --git a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt index 78baaa0f8..790dbd8b0 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt @@ -14,7 +14,6 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.appcompat.app.AppCompatActivity -import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.fragment.app.Fragment import androidx.lifecycle.ViewModelProviders import androidx.navigation.Navigation @@ -155,35 +154,6 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope { } ) - toolbarComponent.uiView.view.apply { - setBackgroundResource(R.drawable.toolbar_background) - - (layoutParams as CoordinatorLayout.LayoutParams).apply { - gravity = getAppropriateLayoutGravity() - - view.nestedScrollQuickAction.visibility = if (gravity == Gravity.TOP) { - View.GONE - } else { - View.VISIBLE - } - - height = (resources.displayMetrics.density * TOOLBAR_HEIGHT).toInt() - } - } - - view.swipeRefresh.apply { - val toolbarSize = - (resources.displayMetrics.density * TOOLBAR_HEIGHT).toInt() + - (if (customTabSessionId == null) QUICK_ACTION_SHEET_HANDLE_HEIGHT else 0) - (layoutParams as CoordinatorLayout.LayoutParams).apply { - setMargins( - 0, - if (customTabSessionId == null) 0 else toolbarSize, - 0, - if (customTabSessionId == null) toolbarSize else 0 - ) - } - } startPostponedEnterTransition() QuickActionComponent( @@ -210,14 +180,6 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope { return view } - private fun getAppropriateLayoutGravity(): Int { - if (customTabSessionId != null) { - return Gravity.TOP - } - - return Gravity.BOTTOM - } - @Suppress("LongMethod") override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) @@ -394,6 +356,8 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope { toolbar, it, activity, + view.nestedScrollQuickAction, + view.swipeRefresh, onItemTapped = { actionEmitter.onNext(SearchAction.ToolbarMenuItemTapped(it)) } ), owner = this, @@ -770,6 +734,12 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope { } } + private fun getAppropriateLayoutGravity() = if (customTabSessionId != null) { + Gravity.TOP + } else { + Gravity.BOTTOM + } + private fun Session.copyUrl(context: Context) { val clipBoard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager clipBoard.primaryClip = ClipData.newPlainText(url, url) @@ -836,8 +806,6 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope { private const val REQUEST_CODE_DOWNLOAD_PERMISSIONS = 1 private const val REQUEST_CODE_PROMPT_PERMISSIONS = 2 private const val REQUEST_CODE_APP_PERMISSIONS = 3 - private const val TOOLBAR_HEIGHT = 56f - private const val QUICK_ACTION_SHEET_HANDLE_HEIGHT = 36 const val REPORT_SITE_ISSUE_URL = "https://webcompat.com/issues/new?url=%s&label=browser-fenix" } diff --git a/app/src/main/java/org/mozilla/fenix/customtabs/CustomTabsIntegration.kt b/app/src/main/java/org/mozilla/fenix/customtabs/CustomTabsIntegration.kt index 8ee5afff1..b87f3d2d6 100644 --- a/app/src/main/java/org/mozilla/fenix/customtabs/CustomTabsIntegration.kt +++ b/app/src/main/java/org/mozilla/fenix/customtabs/CustomTabsIntegration.kt @@ -6,24 +6,50 @@ package org.mozilla.fenix.customtabs import android.app.Activity import android.content.Context +import android.view.Gravity +import android.view.View +import androidx.coordinatorlayout.widget.CoordinatorLayout +import androidx.core.widget.NestedScrollView import mozilla.components.browser.session.SessionManager import mozilla.components.browser.toolbar.BrowserToolbar import mozilla.components.feature.customtabs.CustomTabsToolbarFeature import mozilla.components.support.base.feature.BackHandler import mozilla.components.support.base.feature.LifecycleAwareFeature +import org.mozilla.fenix.R import org.mozilla.fenix.components.toolbar.ToolbarMenu class CustomTabsIntegration( context: Context, sessionManager: SessionManager, - val toolbar: BrowserToolbar, + toolbar: BrowserToolbar, sessionId: String, activity: Activity?, + quickActionbar: NestedScrollView, + engineLayout: View, onItemTapped: (ToolbarMenu.Item) -> Unit = {} ) : LifecycleAwareFeature, BackHandler { init { + // Remove toolbar shadow toolbar.elevation = 0f + + // Reduce margin height of EngineView from the top for the toolbar + engineLayout.run { + (layoutParams as CoordinatorLayout.LayoutParams).apply { + val toolbarHeight = resources.getDimension(R.dimen.browser_toolbar_height).toInt() + setMargins(0, toolbarHeight, 0, 0) + } + } + + // Make the toolbar go to the top. + toolbar.run { + (layoutParams as CoordinatorLayout.LayoutParams).apply { + gravity = Gravity.TOP + } + } + + // Hide the Quick Action Bar. + quickActionbar.visibility = View.GONE } private val customTabToolbarMenu by lazy { diff --git a/app/src/main/res/layout/component_search.xml b/app/src/main/res/layout/component_search.xml index d9db4f6f6..9069609f8 100644 --- a/app/src/main/res/layout/component_search.xml +++ b/app/src/main/res/layout/component_search.xml @@ -6,10 +6,12 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/toolbar" android:layout_width="match_parent" - android:layout_height="match_parent" + android:layout_height="@dimen/browser_toolbar_height" android:clickable="true" android:focusable="true" android:focusableInTouchMode="true" + android:layout_gravity="bottom" + android:background="@drawable/toolbar_background" app:browserToolbarClearColor="?primaryText" app:browserToolbarInsecureColor="?primaryText" app:browserToolbarMenuColor="?primaryText" diff --git a/app/src/main/res/layout/fragment_browser.xml b/app/src/main/res/layout/fragment_browser.xml index a0b9a6426..f1b1a0f91 100644 --- a/app/src/main/res/layout/fragment_browser.xml +++ b/app/src/main/res/layout/fragment_browser.xml @@ -14,7 +14,8 @@ + android:layout_height="match_parent" + android:layout_marginBottom="@dimen/toolbar_and_qab_height"> 16dp 8dp + + + 56dp + 67dp \ No newline at end of file