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