diff --git a/app/src/main/java/org/mozilla/fenix/search/SearchDialogController.kt b/app/src/main/java/org/mozilla/fenix/search/SearchDialogController.kt index 0a23482c88..6e87cf2cc4 100644 --- a/app/src/main/java/org/mozilla/fenix/search/SearchDialogController.kt +++ b/app/src/main/java/org/mozilla/fenix/search/SearchDialogController.kt @@ -12,10 +12,9 @@ import android.text.SpannableString import androidx.annotation.VisibleForTesting import androidx.appcompat.app.AlertDialog import androidx.navigation.NavController -import mozilla.components.browser.session.Session -import mozilla.components.browser.session.SessionManager import mozilla.components.browser.state.search.SearchEngine import mozilla.components.browser.state.store.BrowserStore +import mozilla.components.feature.tabs.TabsUseCases import mozilla.components.support.ktx.kotlin.isUrl import org.mozilla.fenix.BrowserDirection import org.mozilla.fenix.HomeActivity @@ -40,7 +39,6 @@ interface SearchController { fun handleSearchTermsTapped(searchTerms: String) fun handleSearchShortcutEngineSelected(searchEngine: SearchEngine) fun handleClickSearchEngineSettings() - fun handleExistingSessionSelected(session: Session) fun handleExistingSessionSelected(tabId: String) fun handleSearchShortcutsButtonClicked() fun handleCameraPermissionsNeeded() @@ -49,8 +47,8 @@ interface SearchController { @Suppress("TooManyFunctions", "LongParameterList") class SearchDialogController( private val activity: HomeActivity, - private val sessionManager: SessionManager, private val store: BrowserStore, + private val tabsUseCases: TabsUseCases, private val fragmentStore: SearchFragmentStore, private val navController: NavController, private val settings: Settings, @@ -199,21 +197,16 @@ class SearchDialogController( navController.navigateSafe(R.id.searchDialogFragment, directions) } - override fun handleExistingSessionSelected(session: Session) { + override fun handleExistingSessionSelected(tabId: String) { clearToolbarFocus() - sessionManager.select(session) + + tabsUseCases.selectTab(tabId) + activity.openToBrowser( from = BrowserDirection.FromSearchDialog ) } - override fun handleExistingSessionSelected(tabId: String) { - val session = sessionManager.findSessionById(tabId) - if (session != null) { - handleExistingSessionSelected(session) - } - } - /** * Creates and shows an [AlertDialog] when camera permissions are needed. * diff --git a/app/src/main/java/org/mozilla/fenix/search/SearchDialogFragment.kt b/app/src/main/java/org/mozilla/fenix/search/SearchDialogFragment.kt index 8ef26cde88..4707a67c49 100644 --- a/app/src/main/java/org/mozilla/fenix/search/SearchDialogFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/search/SearchDialogFragment.kt @@ -141,8 +141,8 @@ class SearchDialogFragment : AppCompatDialogFragment(), UserInteractionHandler { interactor = SearchDialogInteractor( SearchDialogController( activity = activity, - sessionManager = requireComponents.core.sessionManager, store = requireComponents.core.store, + tabsUseCases = requireComponents.useCases.tabsUseCases, fragmentStore = store, navController = findNavController(), settings = requireContext().settings(), diff --git a/app/src/main/java/org/mozilla/fenix/search/SearchDialogInteractor.kt b/app/src/main/java/org/mozilla/fenix/search/SearchDialogInteractor.kt index cb7385ec76..9f82379d93 100644 --- a/app/src/main/java/org/mozilla/fenix/search/SearchDialogInteractor.kt +++ b/app/src/main/java/org/mozilla/fenix/search/SearchDialogInteractor.kt @@ -4,7 +4,6 @@ package org.mozilla.fenix.search -import mozilla.components.browser.session.Session import mozilla.components.browser.state.search.SearchEngine import org.mozilla.fenix.search.awesomebar.AwesomeBarInteractor import org.mozilla.fenix.search.toolbar.ToolbarInteractor @@ -50,10 +49,6 @@ class SearchDialogInteractor( searchController.handleClickSearchEngineSettings() } - override fun onExistingSessionSelected(session: Session) { - searchController.handleExistingSessionSelected(session) - } - override fun onExistingSessionSelected(tabId: String) { searchController.handleExistingSessionSelected(tabId) } diff --git a/app/src/main/java/org/mozilla/fenix/search/awesomebar/AwesomeBarInteractor.kt b/app/src/main/java/org/mozilla/fenix/search/awesomebar/AwesomeBarInteractor.kt index e8f18cb7e0..bb0c62a62a 100644 --- a/app/src/main/java/org/mozilla/fenix/search/awesomebar/AwesomeBarInteractor.kt +++ b/app/src/main/java/org/mozilla/fenix/search/awesomebar/AwesomeBarInteractor.kt @@ -4,7 +4,6 @@ package org.mozilla.fenix.search.awesomebar -import mozilla.components.browser.session.Session import mozilla.components.browser.state.search.SearchEngine /** @@ -36,11 +35,6 @@ interface AwesomeBarInteractor { */ fun onClickSearchEngineSettings() - /** - * Called whenever an existing session is selected from the sessionSuggestionProvider - */ - fun onExistingSessionSelected(session: Session) - /** * Called whenever an existing session is selected from the sessionSuggestionProvider */ diff --git a/app/src/main/java/org/mozilla/fenix/search/awesomebar/AwesomeBarView.kt b/app/src/main/java/org/mozilla/fenix/search/awesomebar/AwesomeBarView.kt index 541711b357..7d97dea8fb 100644 --- a/app/src/main/java/org/mozilla/fenix/search/awesomebar/AwesomeBarView.kt +++ b/app/src/main/java/org/mozilla/fenix/search/awesomebar/AwesomeBarView.kt @@ -86,7 +86,7 @@ class AwesomeBarView( private val selectTabUseCase = object : TabsUseCases.SelectTabUseCase { override fun invoke(session: Session) { - interactor.onExistingSessionSelected(session) + interactor.onExistingSessionSelected(session.id) } override fun invoke(tabId: String) { diff --git a/app/src/test/java/org/mozilla/fenix/search/SearchDialogControllerTest.kt b/app/src/test/java/org/mozilla/fenix/search/SearchDialogControllerTest.kt index 52cbea14a1..f8b79a0520 100644 --- a/app/src/test/java/org/mozilla/fenix/search/SearchDialogControllerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/search/SearchDialogControllerTest.kt @@ -23,6 +23,7 @@ import mozilla.components.browser.session.Session import mozilla.components.browser.session.SessionManager import mozilla.components.browser.state.search.SearchEngine import mozilla.components.browser.state.store.BrowserStore +import mozilla.components.feature.tabs.TabsUseCases import org.junit.After import org.junit.Before import org.junit.Test @@ -68,10 +69,12 @@ class SearchDialogControllerTest { } every { MetricsUtils.createSearchEvent(searchEngine, browserStore, any()) } returns null + val tabsUseCases = TabsUseCases(browserStore, sessionManager) + controller = SearchDialogController( activity = activity, - sessionManager = sessionManager, store = browserStore, + tabsUseCases = tabsUseCases, fragmentStore = store, navController = navController, settings = settings, @@ -324,7 +327,9 @@ class SearchDialogControllerTest { fun handleExistingSessionSelected() { val session = mockk() - controller.handleExistingSessionSelected(session) + every { sessionManager.findSessionById("selected") } returns session + + controller.handleExistingSessionSelected("selected") verify { sessionManager.select(session) } verify { activity.openToBrowser(from = BrowserDirection.FromSearchDialog) } @@ -337,7 +342,7 @@ class SearchDialogControllerTest { controller.handleExistingSessionSelected("tab-id") verify(inverse = true) { sessionManager.select(any()) } - verify(inverse = true) { activity.openToBrowser(from = BrowserDirection.FromSearchDialog) } + verify { activity.openToBrowser(from = BrowserDirection.FromSearchDialog) } } @Test diff --git a/app/src/test/java/org/mozilla/fenix/search/SearchDialogInteractorTest.kt b/app/src/test/java/org/mozilla/fenix/search/SearchDialogInteractorTest.kt index 53a224c191..77014b1c2e 100644 --- a/app/src/test/java/org/mozilla/fenix/search/SearchDialogInteractorTest.kt +++ b/app/src/test/java/org/mozilla/fenix/search/SearchDialogInteractorTest.kt @@ -100,10 +100,10 @@ class SearchDialogInteractorTest { fun onExistingSessionSelected() { val session = Session("http://mozilla.org", false) - interactor.onExistingSessionSelected(session) + interactor.onExistingSessionSelected(session.id) verify { - searchController.handleExistingSessionSelected(session) + searchController.handleExistingSessionSelected(session.id) } }