mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-19 09:25:34 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/4066: Provide lazy inflation of Find In Page View
This commit is contained in:
parent
81fb1389ed
commit
45ec0682f5
@ -5,8 +5,11 @@
|
|||||||
package org.mozilla.fenix.components
|
package org.mozilla.fenix.components
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.os.Looper
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.view.ViewStub
|
||||||
|
import androidx.annotation.UiThread
|
||||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
import mozilla.components.browser.session.SessionManager
|
import mozilla.components.browser.session.SessionManager
|
||||||
import mozilla.components.browser.session.runWithSessionIdOrSelected
|
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 mozilla.components.support.base.feature.LifecycleAwareFeature
|
||||||
import org.mozilla.fenix.test.Mockable
|
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
|
@Mockable
|
||||||
class FindInPageIntegration(
|
class FindInPageIntegration(
|
||||||
private val sessionManager: SessionManager,
|
private val sessionManager: SessionManager,
|
||||||
private val sessionId: String? = null,
|
private val sessionId: String? = null,
|
||||||
private val view: FindInPageView,
|
private val stub: ViewStub,
|
||||||
engineView: EngineView,
|
engineView: EngineView,
|
||||||
private val toolbar: BrowserToolbar
|
private val toolbar: BrowserToolbar
|
||||||
) : LifecycleAwareFeature, BackHandler {
|
) : 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() {
|
override fun start() {
|
||||||
feature.start()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun stop() {
|
override fun stop() {
|
||||||
feature.stop()
|
if (view != null) feature.stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBackPressed(): Boolean {
|
override fun onBackPressed(): Boolean {
|
||||||
return feature.onBackPressed()
|
return if (view != null) feature.onBackPressed() else false
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onClose() {
|
private fun onClose() {
|
||||||
toolbar.visibility = View.VISIBLE
|
toolbar.visibility = View.VISIBLE
|
||||||
view.asView().visibility = View.GONE
|
view?.asView()?.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UiThread
|
||||||
fun launch() {
|
fun launch() {
|
||||||
|
require(Looper.myLooper() == Looper.getMainLooper()) { "This method should be run on the main UI thread." }
|
||||||
sessionManager.runWithSessionIdOrSelected(sessionId) {
|
sessionManager.runWithSessionIdOrSelected(sessionId) {
|
||||||
if (!it.isCustomTabSession()) {
|
if (!it.isCustomTabSession()) {
|
||||||
toolbar.visibility = View.GONE
|
toolbar.visibility = View.GONE
|
||||||
}
|
}
|
||||||
view.asView().visibility = View.VISIBLE
|
|
||||||
feature.bind(it)
|
feature.bind(it)
|
||||||
|
view?.asView()?.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
- 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"
|
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
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"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/browserLayout"
|
android:id="@+id/browserLayout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -31,18 +30,11 @@
|
|||||||
app:behavior_peekHeight="12dp"
|
app:behavior_peekHeight="12dp"
|
||||||
app:layout_behavior="org.mozilla.fenix.quickactionsheet.QuickActionSheetBehavior" />
|
app:layout_behavior="org.mozilla.fenix.quickactionsheet.QuickActionSheetBehavior" />
|
||||||
|
|
||||||
<mozilla.components.feature.findinpage.view.FindInPageBar
|
<ViewStub
|
||||||
android:id="@+id/findInPageView"
|
android:id="@+id/stub_find_in_page"
|
||||||
android:layout_width="match_parent"
|
android:inflatedId="@+id/findInPageView"
|
||||||
android:layout_height="56dp"
|
android:layout="@layout/stub_find_in_page"
|
||||||
android:layout_gravity="bottom"
|
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" />
|
|
||||||
|
|
||||||
<mozilla.components.feature.readerview.view.ReaderViewControlsBar
|
<mozilla.components.feature.readerview.view.ReaderViewControlsBar
|
||||||
android:id="@+id/readerViewControlsBar"
|
android:id="@+id/readerViewControlsBar"
|
||||||
|
16
app/src/main/res/layout/stub_find_in_page.xml
Normal file
16
app/src/main/res/layout/stub_find_in_page.xml
Normal 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" />
|
Loading…
Reference in New Issue
Block a user