Skip to content

Commit

Permalink
For mozilla-mobile#16807 - Make sure there's only one instance of sea…
Browse files Browse the repository at this point in the history
…rch dialog
  • Loading branch information
ekager authored and pkirakosyan committed Aug 4, 2021
1 parent e7a39f1 commit 8031f63
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ package org.mozilla.fenix.home.intent

import android.content.Intent
import androidx.navigation.NavController
import androidx.navigation.navOptions
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.NavGraphDirections
import org.mozilla.fenix.R
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.metrics.MetricController
import org.mozilla.fenix.ext.nav
Expand All @@ -22,25 +24,25 @@ class StartSearchIntentProcessor(

override fun process(intent: Intent, navController: NavController, out: Intent): Boolean {
val event = intent.extras?.getString(HomeActivity.OPEN_TO_SEARCH)
var source: Event.PerformedSearch.SearchAccessPoint? = null
return if (event != null) {
when (event) {
val source = when (event) {
SEARCH_WIDGET -> {
metrics.track(Event.SearchWidgetNewTabPressed)
source = Event.PerformedSearch.SearchAccessPoint.WIDGET
Event.PerformedSearch.SearchAccessPoint.WIDGET
}
STATIC_SHORTCUT_NEW_TAB -> {
metrics.track(Event.PrivateBrowsingStaticShortcutTab)
source = Event.PerformedSearch.SearchAccessPoint.SHORTCUT
Event.PerformedSearch.SearchAccessPoint.SHORTCUT
}
STATIC_SHORTCUT_NEW_PRIVATE_TAB -> {
metrics.track(Event.PrivateBrowsingStaticShortcutPrivateTab)
source = Event.PerformedSearch.SearchAccessPoint.SHORTCUT
Event.PerformedSearch.SearchAccessPoint.SHORTCUT
}
PRIVATE_BROWSING_PINNED_SHORTCUT -> {
metrics.track(Event.PrivateBrowsingPinnedShortcutPrivateTab)
source = Event.PerformedSearch.SearchAccessPoint.SHORTCUT
Event.PerformedSearch.SearchAccessPoint.SHORTCUT
}
else -> null
}

out.removeExtra(HomeActivity.OPEN_TO_SEARCH)
Expand All @@ -51,7 +53,12 @@ class StartSearchIntentProcessor(
searchAccessPoint = it
)
}
directions?.let { navController.nav(null, it) }
directions?.let {
val options = navOptions {
popUpTo = R.id.homeFragment
}
navController.nav(null, it, options)
}
true
} else {
false
Expand Down
11 changes: 6 additions & 5 deletions app/src/main/res/navigation/nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@

<action
android:id="@+id/action_global_search_dialog"
app:destination="@id/searchDialogFragment" />
app:destination="@id/searchDialogFragment"
app:popUpTo="@id/searchDialogFragment"
app:popUpToInclusive="true"/>

<action
android:id="@+id/action_global_recently_closed"
Expand Down Expand Up @@ -103,7 +105,9 @@
app:destination="@id/quickSettingsSheetDialogFragment" />
<action
android:id="@+id/action_global_tabTrayDialogFragment"
app:destination="@id/tabTrayDialogFragment" />
app:destination="@id/tabTrayDialogFragment"
app:popUpTo="@id/tabTrayDialogFragment"
app:popUpToInclusive="true"/>
<action
android:id="@+id/action_global_savedLoginsAuthFragment"
app:destination="@id/savedLoginsAuthFragment" />
Expand Down Expand Up @@ -198,9 +202,6 @@
<action
android:id="@+id/action_browserFragment_to_trackingProtectionPanelDialogFragment"
app:destination="@id/trackingProtectionPanelDialogFragment" />
<action
android:id="@+id/action_browserFragment_to_tabsTrayFragment"
app:destination="@+id/tabTrayFragment" />
</fragment>

<fragment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ package org.mozilla.fenix.home.intent

import android.content.Intent
import androidx.navigation.NavController
import androidx.navigation.navOptions
import io.mockk.Called
import io.mockk.mockk
import io.mockk.verify
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.NavGraphDirections
import org.mozilla.fenix.R
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.metrics.MetricController
import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner

@RunWith(FenixRobolectricTestRunner::class)
Expand Down Expand Up @@ -51,15 +54,19 @@ class StartSearchIntentProcessorTest {
putExtra(HomeActivity.OPEN_TO_SEARCH, StartSearchIntentProcessor.SEARCH_WIDGET)
}
StartSearchIntentProcessor(metrics).process(intent, navController, out)
val options = navOptions {
popUpTo = R.id.homeFragment
}

verify { metrics.track(Event.SearchWidgetNewTabPressed) }
verify {
navController.navigate(
navController.nav(
null,
NavGraphDirections.actionGlobalSearchDialog(
sessionId = null,
searchAccessPoint = Event.PerformedSearch.SearchAccessPoint.WIDGET
),
null
options
)
}
verify { out.removeExtra(HomeActivity.OPEN_TO_SEARCH) }
Expand Down

0 comments on commit 8031f63

Please sign in to comment.