1
0
Fork 0

For #2052: Fix BrowserToolbar overlapping web content

master
Jonathan Almeida 2019-05-30 19:21:52 -04:00 committed by Jonathan Almeida
parent 209b50016e
commit ab39a5088a
5 changed files with 44 additions and 43 deletions

View File

@ -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"
}

View File

@ -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 {

View File

@ -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"

View File

@ -14,7 +14,8 @@
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipeRefresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:layout_marginBottom="@dimen/toolbar_and_qab_height">
<mozilla.components.concept.engine.EngineView
android:id="@+id/engineView"
android:layout_width="match_parent"

View File

@ -38,4 +38,8 @@
<!-- Bottom Sheet Fragment card -->
<dimen name="bottom_sheet_corner_radius">16dp</dimen>
<dimen name="bottom_sheet_top_padding">8dp</dimen>
<!-- Browser Toolbar -->
<dimen name="browser_toolbar_height">56dp</dimen>
<dimen name="toolbar_and_qab_height">67dp</dimen>
</resources>