Skip to content

Commit

Permalink
Issue mozilla-mobile#24740: Use unified search bar in bookmark search
Browse files Browse the repository at this point in the history
  • Loading branch information
rocketsroger committed Jun 21, 2022
1 parent 4c140dc commit c517819
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import org.mozilla.fenix.ext.bookmarkStorage
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.ext.navigateSafe
import org.mozilla.fenix.utils.Settings

/**
* [BookmarkFragment] controller.
Expand Down Expand Up @@ -76,7 +77,8 @@ class DefaultBookmarkController(
private val showSnackbar: (String) -> Unit,
private val deleteBookmarkNodes: (Set<BookmarkNode>, BookmarkRemoveType) -> Unit,
private val deleteBookmarkFolder: (Set<BookmarkNode>) -> Unit,
private val showTabTray: () -> Unit
private val showTabTray: () -> Unit,
private val settings: Settings,
) : BookmarkController {

private val resources: Resources = activity.resources
Expand Down Expand Up @@ -195,8 +197,12 @@ class DefaultBookmarkController(
}

override fun handleSearch() {
val directions =
val directions = if (settings.showUnifiedSearchFeature) {
BookmarkFragmentDirections.actionGlobalSearchDialog(sessionId = null)
} else {
BookmarkFragmentDirections.actionBookmarkFragmentToBookmarkSearchDialogFragment()
}

navController.navigateSafe(R.id.bookmarkFragment, directions)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ class BookmarkFragment : LibraryPageFragment<BookmarkNode>(), UserInteractionHan
showSnackbar = ::showSnackBarWithText,
deleteBookmarkNodes = ::deleteMulti,
deleteBookmarkFolder = ::showRemoveFolderDialog,
showTabTray = ::showTabTray
showTabTray = ::showTabTray,
settings = requireComponents.settings,
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import org.mozilla.fenix.GleanMetrics.Awesomebar
import org.mozilla.fenix.GleanMetrics.VoiceSearch
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.components.Core.Companion.BOOKMARKS_SEARCH_ENGINE_ID
import org.mozilla.fenix.components.Core.Companion.HISTORY_SEARCH_ENGINE_ID
import org.mozilla.fenix.components.toolbar.ToolbarPosition
import org.mozilla.fenix.databinding.FragmentSearchDialogBinding
Expand Down Expand Up @@ -268,6 +269,13 @@ class SearchDialogFragment : AppCompatDialogFragment(), UserInteractionHandler {
store.dispatch(SearchFragmentAction.SearchHistoryEngineSelected(searchEngine))
}
}
R.id.bookmarkFragment -> {
requireComponents.core.store.state.search.searchEngines.firstOrNull { searchEngine ->
searchEngine.id == BOOKMARKS_SEARCH_ENGINE_ID
}?.let { searchEngine ->
store.dispatch(SearchFragmentAction.SearchBookmarksEngineSelected(searchEngine))
}
}
else -> {}
}

Expand Down Expand Up @@ -300,7 +308,7 @@ class SearchDialogFragment : AppCompatDialogFragment(), UserInteractionHandler {
false
}
}
R.id.historyFragment -> {
R.id.historyFragment, R.id.bookmarkFragment -> {
binding.searchWrapper.setOnTouchListener { _, _ ->
dismissAllowingStateLoss()
true
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/navigation/nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,11 @@
app:destination="@id/bookmarkSearchDialogFragment"
app:popUpTo="@id/bookmarkSearchDialogFragment"
app:popUpToInclusive="true" />
<action
android:id="@+id/action_global_search_dialog"
app:destination="@id/searchDialogFragment"
app:popUpTo="@id/searchDialogFragment"
app:popUpToInclusive="true" />
</fragment>

<dialog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import org.mozilla.fenix.browser.browsingmode.BrowsingMode
import org.mozilla.fenix.components.Services
import org.mozilla.fenix.ext.bookmarkStorage
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.utils.Settings

@Suppress("TooManyFunctions", "LargeClass")
class BookmarkControllerTest {
Expand All @@ -60,6 +61,7 @@ class BookmarkControllerTest {
private val addNewTabUseCase: TabsUseCases.AddNewTabUseCase = mockk(relaxed = true)
private val navBackStackEntry: NavBackStackEntry = mockk(relaxed = true)
private val navDestination: NavDestination = mockk(relaxed = true)
private val settings: Settings = mockk(relaxed = true)

private val item =
BookmarkNode(BookmarkNodeType.ITEM, "456", "123", 0u, "Mozilla", "http://mozilla.org", 0, null)
Expand Down Expand Up @@ -220,6 +222,17 @@ class BookmarkControllerTest {
}
}

@Test
fun `WHEN handling search THEN navigate to the search dialog fragment`() {
createController().handleSearch()

verify {
navController.navigate(
BookmarkFragmentDirections.actionBookmarkFragmentToBookmarkSearchDialogFragment()
)
}
}

@Test
fun `handleBookmarkSelected dispatches Select action when selecting a non-root folder`() {
createController().handleBookmarkSelected(item)
Expand Down Expand Up @@ -424,7 +437,8 @@ class BookmarkControllerTest {
showSnackbar = showSnackbar,
deleteBookmarkNodes = deleteBookmarkNodes,
deleteBookmarkFolder = deleteBookmarkFolder,
showTabTray = showTabTray
showTabTray = showTabTray,
settings = settings,
)
}
}

0 comments on commit c517819

Please sign in to comment.