Skip to content

Commit

Permalink
For mozilla-mobile#24040 - Open search page in portrait mode
Browse files Browse the repository at this point in the history
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
  • Loading branch information
indurs committed Apr 25, 2022
1 parent 405f406 commit fb18aa3
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/org/mozilla/fenix/HomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 26 additions & 0 deletions app/src/main/java/org/mozilla/fenix/browser/BrowserStore.kt
Original file line number Diff line number Diff line change
@@ -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<BrowserState, BrowserAction>? = null
subscription = observeManually { state ->
if (state.findActiveMediaTab() == null || !state.findActiveMediaTab()?.mediaSessionState?.fullscreen!!) {
block()
subscription!!.unsubscribe()
}
}
subscription.resume()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -54,10 +71,8 @@ class StartSearchIntentProcessor(
}
navController.nav(null, it, options)
}
true
} else {
false
}
return true
}

companion object {
Expand Down

0 comments on commit fb18aa3

Please sign in to comment.