From fb18aa399d73866760e2f1dc36bd57c8dd5e742f Mon Sep 17 00:00:00 2001 From: indu Date: Mon, 25 Apr 2022 11:00:05 +0530 Subject: [PATCH] For #24040 - Open search page in portrait mode When the search event is from the search widget, the search fragment opens after the screen is unlocked. This avoids the issue of the search page opening in landscape mode --- .../java/org/mozilla/fenix/HomeActivity.kt | 2 +- .../org/mozilla/fenix/browser/BrowserStore.kt | 26 ++++++++++ .../home/intent/StartSearchIntentProcessor.kt | 47 ++++++++++++------- 3 files changed, 58 insertions(+), 17 deletions(-) create mode 100644 app/src/main/java/org/mozilla/fenix/browser/BrowserStore.kt diff --git a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt index 84d9d70796d4..72b46fc577d2 100644 --- a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt +++ b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt @@ -173,7 +173,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity { listOf( HomeDeepLinkIntentProcessor(this), SpeechProcessingIntentProcessor(this, components.core.store, components.analytics.metrics), - StartSearchIntentProcessor(components.analytics.metrics), + StartSearchIntentProcessor(components.analytics.metrics,components.core.store), OpenBrowserIntentProcessor(this, ::getIntentSessionId), OpenSpecificTabIntentProcessor(this), DefaultBrowserIntentProcessor(this) diff --git a/app/src/main/java/org/mozilla/fenix/browser/BrowserStore.kt b/app/src/main/java/org/mozilla/fenix/browser/BrowserStore.kt new file mode 100644 index 000000000000..dfb592401f5b --- /dev/null +++ b/app/src/main/java/org/mozilla/fenix/browser/BrowserStore.kt @@ -0,0 +1,26 @@ +package org.mozilla.fenix.browser + +import mozilla.components.browser.state.action.BrowserAction +import mozilla.components.browser.state.state.BrowserState +import mozilla.components.browser.state.store.BrowserStore +import mozilla.components.feature.media.ext.findActiveMediaTab +import mozilla.components.lib.state.Store + +fun BrowserStore.waitForPIPToClose( + block: () -> Unit +) { + + if (state.findActiveMediaTab() == null || !state.findActiveMediaTab()?.mediaSessionState?.fullscreen!!) { + block() + return + } + + var subscription: Store.Subscription? = null + subscription = observeManually { state -> + if (state.findActiveMediaTab() == null || !state.findActiveMediaTab()?.mediaSessionState?.fullscreen!!) { + block() + subscription!!.unsubscribe() + } + } + subscription.resume() +} \ No newline at end of file diff --git a/app/src/main/java/org/mozilla/fenix/home/intent/StartSearchIntentProcessor.kt b/app/src/main/java/org/mozilla/fenix/home/intent/StartSearchIntentProcessor.kt index 580f6dd58e62..4013ce5f638d 100644 --- a/app/src/main/java/org/mozilla/fenix/home/intent/StartSearchIntentProcessor.kt +++ b/app/src/main/java/org/mozilla/fenix/home/intent/StartSearchIntentProcessor.kt @@ -7,41 +7,58 @@ package org.mozilla.fenix.home.intent import android.content.Intent import androidx.navigation.NavController import androidx.navigation.navOptions +import mozilla.components.browser.state.store.BrowserStore import mozilla.components.service.glean.private.NoExtras import org.mozilla.fenix.GleanMetrics.SearchWidget import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.NavGraphDirections import org.mozilla.fenix.R +import org.mozilla.fenix.browser.waitForPIPToClose import org.mozilla.fenix.components.metrics.MetricController import org.mozilla.fenix.components.metrics.MetricsUtils import org.mozilla.fenix.ext.nav +import org.mozilla.gecko.util.ThreadUtils.runOnUiThread /** * When the search widget is tapped, Fenix should open to the search fragment. * Tapping the private browsing mode launcher icon should also open to the search fragment. */ class StartSearchIntentProcessor( - private val metrics: MetricController + private val metrics: MetricController, + private val store: BrowserStore ) : HomeIntentProcessor { override fun process(intent: Intent, navController: NavController, out: Intent): Boolean { val event = intent.extras?.getString(HomeActivity.OPEN_TO_SEARCH) + var processed = false + return if (event != null) { - val source = when (event) { - SEARCH_WIDGET -> { - SearchWidget.newTabButton.record(NoExtras()) - MetricsUtils.Source.WIDGET - } - STATIC_SHORTCUT_NEW_TAB, - STATIC_SHORTCUT_NEW_PRIVATE_TAB, - PRIVATE_BROWSING_PINNED_SHORTCUT -> { - MetricsUtils.Source.SHORTCUT - } - else -> null + store.waitForPIPToClose { + processed = openSearch(event,navController,out) } + return processed + } else { + false + } + } - out.removeExtra(HomeActivity.OPEN_TO_SEARCH) + private fun openSearch(event: String,navController: NavController,out: Intent): Boolean{ + val source = when (event) { + SEARCH_WIDGET -> { + SearchWidget.newTabButton.record(NoExtras()) + MetricsUtils.Source.WIDGET + } + STATIC_SHORTCUT_NEW_TAB, + STATIC_SHORTCUT_NEW_PRIVATE_TAB, + PRIVATE_BROWSING_PINNED_SHORTCUT -> { + MetricsUtils.Source.SHORTCUT + } + else -> null + } + out.removeExtra(HomeActivity.OPEN_TO_SEARCH) + + runOnUiThread { val directions = source?.let { NavGraphDirections.actionGlobalSearchDialog( sessionId = null, @@ -54,10 +71,8 @@ class StartSearchIntentProcessor( } navController.nav(null, it, options) } - true - } else { - false } + return true } companion object {