1
0
Fork 0

For #4066: Provide lazy inflation of Find In Page View

master
Colin Lee 2019-07-17 13:54:59 -05:00 committed by Jonathan Almeida
parent ecf9d17add
commit 519c3bde5d
3 changed files with 41 additions and 20 deletions

View File

@ -5,8 +5,11 @@
package org.mozilla.fenix.components
import android.content.Context
import android.os.Looper
import android.util.AttributeSet
import android.view.View
import android.view.ViewStub
import androidx.annotation.UiThread
import androidx.coordinatorlayout.widget.CoordinatorLayout
import mozilla.components.browser.session.SessionManager
import mozilla.components.browser.session.runWithSessionIdOrSelected
@ -19,40 +22,50 @@ import mozilla.components.support.base.feature.BackHandler
import mozilla.components.support.base.feature.LifecycleAwareFeature
import org.mozilla.fenix.test.Mockable
/**
* This class provides lazy loading of the Find in Page View.
* It should be launched on the app's UI thread.
*/
@Mockable
class FindInPageIntegration(
private val sessionManager: SessionManager,
private val sessionId: String? = null,
private val view: FindInPageView,
private val stub: ViewStub,
engineView: EngineView,
private val toolbar: BrowserToolbar
) : LifecycleAwareFeature, BackHandler {
private val feature = FindInPageFeature(sessionManager, view, engineView, ::onClose)
private var view: FindInPageView? = null
private val feature: FindInPageFeature by lazy(LazyThreadSafetyMode.NONE) {
view = stub.inflate() as FindInPageView
FindInPageFeature(sessionManager, view!!, engineView, ::onClose).also { it.start() }
}
override fun start() {
feature.start()
}
override fun stop() {
feature.stop()
if (view != null) feature.stop()
}
override fun onBackPressed(): Boolean {
return feature.onBackPressed()
return if (view != null) feature.onBackPressed() else false
}
private fun onClose() {
toolbar.visibility = View.VISIBLE
view.asView().visibility = View.GONE
view?.asView()?.visibility = View.GONE
}
@UiThread
fun launch() {
require(Looper.myLooper() == Looper.getMainLooper()) { "This method should be run on the main UI thread." }
sessionManager.runWithSessionIdOrSelected(sessionId) {
if (!it.isCustomTabSession()) {
toolbar.visibility = View.GONE
}
view.asView().visibility = View.VISIBLE
feature.bind(it)
view?.asView()?.visibility = View.VISIBLE
}
}
}

View File

@ -4,7 +4,6 @@
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:mozac="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/browserLayout"
android:layout_width="match_parent"
@ -31,18 +30,11 @@
app:behavior_peekHeight="12dp"
app:layout_behavior="org.mozilla.fenix.quickactionsheet.QuickActionSheetBehavior" />
<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="?foundation"
android:clickable="true"
android:visibility="gone"
android:elevation="5dp"
app:findInPageNoMatchesTextColor="?attr/destructive"
mozac:findInPageButtonsTint="?primaryText"
mozac:findInPageResultCountTextColor="?primaryText" />
<ViewStub
android:id="@+id/stub_find_in_page"
android:inflatedId="@+id/findInPageView"
android:layout="@layout/stub_find_in_page"
android:layout_gravity="bottom" />
<mozilla.components.feature.readerview.view.ReaderViewControlsBar
android:id="@+id/readerViewControlsBar"

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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/. -->
<mozilla.components.feature.findinpage.view.FindInPageBar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/findInPageView"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_gravity="bottom"
android:background="?foundation"
android:clickable="true"
android:focusable="true"
app:findInPageNoMatchesTextColor="?attr/destructive"
app:findInPageButtonsTint="?primaryText"
app:findInPageResultCountTextColor="?primaryText" />