Unverified Commit 31edbc92 authored by Tiger Oakes's avatar Tiger Oakes Committed by GitHub
Browse files

Fixes #9056 - Start Fenix activity on search in external app (#10932)

parent 4b064afb
Loading
Loading
Loading
Loading
+10 −4
Original line number Diff line number Diff line
@@ -32,10 +32,13 @@ import mozilla.components.browser.search.SearchEngine
import mozilla.components.browser.session.Session
import mozilla.components.browser.session.SessionManager
import mozilla.components.browser.state.state.WebExtensionState
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.browser.tabstray.BrowserTabsTray
import mozilla.components.concept.engine.EngineView
import mozilla.components.concept.tabstray.TabsTray
import mozilla.components.feature.contextmenu.ext.DefaultSelectionActionDelegate
import mozilla.components.feature.contextmenu.DefaultSelectionActionDelegate
import mozilla.components.feature.search.BrowserStoreSearchAdapter
import mozilla.components.feature.search.SearchAdapter
import mozilla.components.service.fxa.sync.SyncReason
import mozilla.components.support.base.feature.UserInteractionHandler
import mozilla.components.support.ktx.android.arch.lifecycle.addObservers
@@ -63,6 +66,7 @@ import org.mozilla.fenix.home.HomeFragmentDirections
import org.mozilla.fenix.home.intent.CrashReporterIntentProcessor
import org.mozilla.fenix.home.intent.DeepLinkIntentProcessor
import org.mozilla.fenix.home.intent.OpenBrowserIntentProcessor
import org.mozilla.fenix.home.intent.OpenSpecificTabIntentProcessor
import org.mozilla.fenix.home.intent.SpeechProcessingIntentProcessor
import org.mozilla.fenix.home.intent.StartSearchIntentProcessor
import org.mozilla.fenix.library.bookmarks.BookmarkFragmentDirections
@@ -83,7 +87,6 @@ import org.mozilla.fenix.theme.DefaultThemeManager
import org.mozilla.fenix.theme.ThemeManager
import org.mozilla.fenix.utils.BrowsersCache
import org.mozilla.fenix.utils.RunWhenReadyQueue
import org.mozilla.fenix.home.intent.OpenSpecificTabIntentProcessor

/**
 * The main activity of the application. The application is primarily a single Activity (this one)
@@ -226,8 +229,8 @@ open class HomeActivity : LocaleAwareAppCompatActivity() {
    ): View? = when (name) {
        EngineView::class.java.name -> components.core.engine.createView(context, attrs).apply {
            selectionActionDelegate = DefaultSelectionActionDelegate(
                store = components.core.store,
                context = context,
                getSearchAdapter(components.core.store),
                resources = context.resources,
                appName = getString(R.string.app_name)
            ) {
                share(it)
@@ -269,6 +272,9 @@ open class HomeActivity : LocaleAwareAppCompatActivity() {
        super.onUserLeaveHint()
    }

    protected open fun getSearchAdapter(store: BrowserStore): SearchAdapter =
        BrowserStoreSearchAdapter(store)

    protected open fun getBreadcrumbMessage(destination: NavDestination): String {
        val fragmentName = resources.getResourceEntryName(destination.id)
        return "Changing to fragment $fragmentName, isCustomTab: false"
+23 −0
Original line number Diff line number Diff line
@@ -4,15 +4,19 @@

package org.mozilla.fenix.customtabs

import android.content.Intent
import androidx.navigation.NavDestination
import androidx.navigation.NavDirections
import mozilla.components.browser.session.runWithSession
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.concept.engine.manifest.WebAppManifestParser
import mozilla.components.feature.intent.ext.getSessionId
import mozilla.components.feature.pwa.ext.getWebAppManifest
import mozilla.components.feature.search.SearchAdapter
import mozilla.components.support.utils.SafeIntent
import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.IntentReceiverActivity
import org.mozilla.fenix.NavGraphDirections
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.components
@@ -24,6 +28,12 @@ import java.security.InvalidParameterException
 */
open class ExternalAppBrowserActivity : HomeActivity() {

    private val openInFenixIntent by lazy {
        Intent(this, IntentReceiverActivity::class.java).apply {
            action = Intent.ACTION_VIEW
        }
    }

    final override fun getBreadcrumbMessage(destination: NavDestination): String {
        val fragmentName = resources.getResourceEntryName(destination.id)
        return "Changing to fragment $fragmentName, isCustomTab: true"
@@ -57,6 +67,19 @@ open class ExternalAppBrowserActivity : HomeActivity() {
        }
    }

    override fun getSearchAdapter(store: BrowserStore): SearchAdapter {
        val baseAdapter = super.getSearchAdapter(store)
        return object : SearchAdapter {

            override fun sendSearch(isPrivate: Boolean, text: String) {
                baseAdapter.sendSearch(isPrivate, text)
                startActivity(openInFenixIntent)
            }

            override fun isPrivateSession() = baseAdapter.isPrivateSession()
        }
    }

    override fun onDestroy() {
        super.onDestroy()