1
0
Fork 0

Closes #146 & Closes #147: Integrates find in page

Co-authored-by: Sawyer Blatz <sdblatz@gmail.com>
master
Jeff Boek 2019-02-01 21:03:04 -08:00
parent 383f9197bf
commit a6004fea20
7 changed files with 128 additions and 9 deletions

View File

@ -124,10 +124,9 @@ dependencies {
implementation Deps.mozilla_feature_session
implementation Deps.mozilla_feature_toolbar
implementation Deps.mozilla_feature_tabs
implementation Deps.mozilla_service_fretboard
implementation Deps.mozilla_service_glean
implementation Deps.mozilla_feature_findinpage
implementation Deps.mozilla_support_ktx
implementation Deps.mozilla_lib_crash

View File

@ -16,7 +16,8 @@
android:theme="@style/LightAppTheme"
android:usesCleartextTraffic="true"
tools:ignore="UnusedAttribute">
<activity android:name=".HomeActivity">
<activity android:name=".HomeActivity"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
@ -53,4 +54,4 @@
android:theme="@style/SettingsAppTheme" />
</application>
</manifest>
</manifest>

View File

@ -28,11 +28,13 @@ import org.mozilla.fenix.components.toolbar.ToolbarIntegration
import org.mozilla.fenix.ext.requireComponents
import mozilla.components.feature.prompts.PromptFeature
import org.mozilla.fenix.BackHandler
import org.mozilla.fenix.components.FindInPageIntegration
class BrowserFragment : Fragment(), BackHandler {
private lateinit var contextMenuFeature: ContextMenuFeature
private lateinit var downloadsFeature: DownloadsFeature
private lateinit var findInPageIntegration: FindInPageIntegration
private lateinit var promptsFeature: PromptFeature
private lateinit var sessionFeature: SessionFeature
@ -88,6 +90,14 @@ class BrowserFragment : Fragment(), BackHandler {
engineView
)
findInPageIntegration = FindInPageIntegration(requireComponents.core.sessionManager, findInPageView)
val toolbarIntegration = ToolbarIntegration(
requireContext(),
toolbar,
requireComponents.toolbar.shippedDomainsProvider,
requireComponents.core.historyStorage
)
// Stop toolbar from collapsing if TalkBack is enabled
val accessibilityManager = context?.getSystemService(Context.ACCESSIBILITY_SERVICE) as AccessibilityManager
if (accessibilityManager.isEnabled) {
@ -98,12 +108,10 @@ class BrowserFragment : Fragment(), BackHandler {
lifecycle.addObservers(
contextMenuFeature,
downloadsFeature,
findInPageIntegration,
promptsFeature,
sessionFeature,
ToolbarIntegration(requireContext(),
toolbar,
requireComponents.toolbar.shippedDomainsProvider,
requireComponents.core.historyStorage)
toolbarIntegration
)
toolbar.onUrlClicked = {
@ -113,6 +121,7 @@ class BrowserFragment : Fragment(), BackHandler {
}
override fun onBackPressed(): Boolean {
if (findInPageIntegration.onBackPressed()) return true
if (sessionFeature.handleBackPressed()) return true
// We'll want to improve this when we add multitasking

View File

@ -0,0 +1,94 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.components
import android.content.Context
import android.util.AttributeSet
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent
import android.view.View
import androidx.coordinatorlayout.widget.CoordinatorLayout
import mozilla.components.browser.session.SessionManager
import mozilla.components.browser.toolbar.BrowserToolbar
import mozilla.components.feature.findinpage.FindInPageFeature
import mozilla.components.feature.findinpage.view.FindInPageBar
import mozilla.components.feature.findinpage.view.FindInPageView
class FindInPageIntegration(
private val sessionManager: SessionManager,
private val view: FindInPageView
) : LifecycleObserver {
private val feature = FindInPageFeature(sessionManager, view, ::onClose)
@OnLifecycleEvent(Lifecycle.Event.ON_START)
fun onStart() {
feature.start()
FindInPageIntegration.launch = this::launch
}
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
fun onStop() {
feature.stop()
FindInPageIntegration.launch = null
}
fun onBackPressed(): Boolean {
return feature.onBackPressed()
}
private fun onClose() {
view.asView().visibility = View.GONE
}
private fun launch() {
val session = sessionManager.selectedSession ?: return
view.asView().visibility = View.VISIBLE
feature.bind(session)
}
companion object {
// This is a workaround to let the menu item find this integration and active "Find in Page" mode. That's a bit
// ridiculous and there's no need that we create the toolbar menu items at app start time. Instead the
// ToolbarIntegration should create them and get the FindInPageIntegration injected as a dependency if the
// menu items need them.
var launch: (() -> Unit)? = null
private set
}
}
/**
* [CoordinatorLayout.Behavior] that will always position the [FindInPageBar] above the [BrowserToolbar] (including
* when the browser toolbar is scrolling or performing a snap animation).
*/
@Suppress("unused") // Referenced from XML
class FindInPageBarBehavior(
context: Context,
attrs: AttributeSet
) : CoordinatorLayout.Behavior<FindInPageBar>(context, attrs) {
override fun layoutDependsOn(parent: CoordinatorLayout, child: FindInPageBar, dependency: View): Boolean {
if (dependency is BrowserToolbar) {
return true
}
return super.layoutDependsOn(parent, child, dependency)
}
override fun onDependentViewChanged(parent: CoordinatorLayout, child: FindInPageBar, dependency: View): Boolean {
return if (dependency is BrowserToolbar) {
repositionFindInPageBar(child, dependency)
true
} else {
false
}
}
private fun repositionFindInPageBar(findInPageView: FindInPageBar, toolbar: BrowserToolbar) {
findInPageView.translationY = (toolbar.translationY + toolbar.height * -1.0).toFloat()
}
}

View File

@ -17,6 +17,7 @@ import mozilla.components.feature.session.SessionUseCases
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.share
import org.mozilla.fenix.settings.SettingsActivity
import org.mozilla.fenix.components.FindInPageIntegration
/**
* Component group for all functionality related to the browser toolbar.
@ -112,7 +113,9 @@ class Toolbar(
context.getString(R.string.browser_menu_find_in_page),
R.color.icons
) {
// TODO Find in Page
FindInPageIntegration.launch?.invoke()
}.apply {
visible = { sessionManager.selectedSession != null }
},
BrowserMenuImageText(

View File

@ -31,6 +31,17 @@
mozac:awesomeBarTitleTextColor="#ffffff" />
</FrameLayout>
<mozilla.components.feature.findinpage.view.FindInPageBar
android:id="@+id/findInPageView"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_gravity="bottom"
android:background="@color/offwhite"
mozac:findInPageResultCountTextColor="@color/colorPrimary"
mozac:findInPageButtonsTint="@color/colorPrimary"
android:visibility="gone"
app:layout_behavior="org.mozilla.fenix.components.FindInPageBarBehavior" />
<mozilla.components.browser.toolbar.BrowserToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
@ -43,4 +54,5 @@
android:transitionName="firstTransitionName"
app:layout_behavior="mozilla.components.browser.toolbar.behavior.BrowserToolbarBottomBehavior"
app:layout_scrollFlags="scroll|enterAlways|snap|exitUntilCollapsed" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -72,6 +72,7 @@ object Deps {
const val mozilla_feature_storage = "org.mozilla.components:feature-storage:${Versions.mozilla_android_components}"
const val mozilla_feature_prompts = "org.mozilla.components:feature-prompts:${Versions.mozilla_android_components}"
const val mozilla_feature_toolbar = "org.mozilla.components:feature-toolbar:${Versions.mozilla_android_components}"
const val mozilla_feature_findinpage = "org.mozilla.components:feature-findinpage:${Versions.mozilla_android_components}"
const val mozilla_service_fretboard = "org.mozilla.components:service-fretboard:${Versions.mozilla_android_components}"
const val mozilla_service_glean = "org.mozilla.components:service-glean:${Versions.mozilla_android_components}"