1
0
Fork 0

For #3695: Make SessionSuggestionProvider link to existing tab (#4280)

master
Colin Lee 2019-07-26 09:49:25 -05:00 committed by GitHub
parent 1846a61475
commit 48aeb19db1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 55 additions and 4 deletions

View File

@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
### Added ### Added
- #3695 - Made search suggestions for other tabs clickable
## [1.1.0 and earlier] - 2019-07-23
### Added
- #2770 - Added ability to receive tabs from other FxA devices - #2770 - Added ability to receive tabs from other FxA devices
- #919 - Enabled bookmark synchronization - #919 - Enabled bookmark synchronization
- #916 - Added the ability to save and delete bookmarks - #916 - Added the ability to save and delete bookmarks

View File

@ -7,11 +7,15 @@ package org.mozilla.fenix.search
import android.content.Context import android.content.Context
import androidx.navigation.NavController import androidx.navigation.NavController
import mozilla.components.browser.search.SearchEngine import mozilla.components.browser.search.SearchEngine
import mozilla.components.browser.session.Session
import mozilla.components.support.ktx.kotlin.isUrl import mozilla.components.support.ktx.kotlin.isUrl
import org.mozilla.fenix.BrowserDirection import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.metrics import org.mozilla.fenix.ext.metrics
import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.ext.searchEngineManager import org.mozilla.fenix.ext.searchEngineManager
import org.mozilla.fenix.search.awesomebar.AwesomeBarInteractor import org.mozilla.fenix.search.awesomebar.AwesomeBarInteractor
import org.mozilla.fenix.search.toolbar.ToolbarInteractor import org.mozilla.fenix.search.toolbar.ToolbarInteractor
@ -25,6 +29,7 @@ class SearchInteractor(
private val navController: NavController, private val navController: NavController,
private val store: SearchStore private val store: SearchStore
) : AwesomeBarInteractor, ToolbarInteractor { ) : AwesomeBarInteractor, ToolbarInteractor {
override fun onUrlCommitted(url: String) { override fun onUrlCommitted(url: String) {
if (url.isNotBlank()) { if (url.isNotBlank()) {
(context as HomeActivity).openToBrowserAndLoad( (context as HomeActivity).openToBrowserAndLoad(
@ -85,6 +90,12 @@ class SearchInteractor(
navController.navigate(directions) navController.navigate(directions)
} }
override fun onExistingSessionSelected(session: Session) {
val directions = SearchFragmentDirections.actionSearchFragmentToBrowserFragment(null)
navController.nav(R.id.searchFragment, directions)
context.components.core.sessionManager.select(session)
}
private fun createSearchEvent(engine: SearchEngine, isSuggestion: Boolean): Event.PerformedSearch { private fun createSearchEvent(engine: SearchEngine, isSuggestion: Boolean): Event.PerformedSearch {
val isShortcut = engine != context.searchEngineManager.defaultSearchEngine val isShortcut = engine != context.searchEngineManager.defaultSearchEngine

View File

@ -13,14 +13,16 @@ import androidx.core.graphics.drawable.toBitmap
import kotlinx.android.extensions.LayoutContainer import kotlinx.android.extensions.LayoutContainer
import mozilla.components.browser.awesomebar.BrowserAwesomeBar import mozilla.components.browser.awesomebar.BrowserAwesomeBar
import mozilla.components.browser.search.SearchEngine import mozilla.components.browser.search.SearchEngine
import mozilla.components.browser.session.Session
import mozilla.components.concept.engine.EngineSession import mozilla.components.concept.engine.EngineSession
import mozilla.components.feature.awesomebar.provider.SearchSuggestionProvider import mozilla.components.feature.awesomebar.provider.BookmarksStorageSuggestionProvider
import mozilla.components.feature.awesomebar.provider.ClipboardSuggestionProvider import mozilla.components.feature.awesomebar.provider.ClipboardSuggestionProvider
import mozilla.components.feature.awesomebar.provider.HistoryStorageSuggestionProvider import mozilla.components.feature.awesomebar.provider.HistoryStorageSuggestionProvider
import mozilla.components.feature.awesomebar.provider.BookmarksStorageSuggestionProvider import mozilla.components.feature.awesomebar.provider.SearchSuggestionProvider
import mozilla.components.feature.awesomebar.provider.SessionSuggestionProvider import mozilla.components.feature.awesomebar.provider.SessionSuggestionProvider
import mozilla.components.feature.search.SearchUseCases import mozilla.components.feature.search.SearchUseCases
import mozilla.components.feature.session.SessionUseCases import mozilla.components.feature.session.SessionUseCases
import mozilla.components.feature.tabs.TabsUseCases
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.ThemeManager import org.mozilla.fenix.ThemeManager
import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.components
@ -55,6 +57,11 @@ interface AwesomeBarInteractor {
* Called whenever the "Search Engine Settings" item is tapped * Called whenever the "Search Engine Settings" item is tapped
*/ */
fun onClickSearchEngineSettings() fun onClickSearchEngineSettings()
/**
* Called whenever an existing session is selected from the sessionSuggestionProvider
*/
fun onExistingSessionSelected(session: Session)
} }
/** /**
@ -96,6 +103,12 @@ class AwesomeBarView(
} }
} }
private val selectTabUseCase = object : TabsUseCases.SelectTabUseCase {
override fun invoke(session: Session) {
interactor.onExistingSessionSelected(session)
}
}
init { init {
with(container.context) { with(container.context) {
val primaryTextColor = ContextCompat.getColor( val primaryTextColor = ContextCompat.getColor(
@ -116,8 +129,9 @@ class AwesomeBarView(
sessionProvider = sessionProvider =
SessionSuggestionProvider( SessionSuggestionProvider(
components.core.sessionManager, components.core.sessionManager,
components.useCases.tabsUseCases.selectTab, selectTabUseCase,
components.core.icons components.core.icons,
excludeSelectedSession = true
) )
historyStorageProvider = historyStorageProvider =

View File

@ -4,7 +4,9 @@
package org.mozilla.fenix.search package org.mozilla.fenix.search
import android.content.Context
import androidx.navigation.NavController import androidx.navigation.NavController
import androidx.navigation.NavDestination
import androidx.navigation.NavDirections import androidx.navigation.NavDirections
import io.mockk.Runs import io.mockk.Runs
import io.mockk.every import io.mockk.every
@ -13,9 +15,12 @@ import io.mockk.mockk
import io.mockk.verify import io.mockk.verify
import mozilla.components.browser.search.SearchEngine import mozilla.components.browser.search.SearchEngine
import mozilla.components.browser.search.SearchEngineManager import mozilla.components.browser.search.SearchEngineManager
import mozilla.components.browser.session.Session
import org.junit.Test import org.junit.Test
import org.mozilla.fenix.BrowserDirection import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.FenixApplication
import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.metrics import org.mozilla.fenix.ext.metrics
import org.mozilla.fenix.ext.searchEngineManager import org.mozilla.fenix.ext.searchEngineManager
@ -153,4 +158,21 @@ class SearchInteractorTest {
navController.navigate(SearchFragmentDirections.actionSearchFragmentToSearchEngineFragment()) navController.navigate(SearchFragmentDirections.actionSearchFragmentToSearchEngineFragment())
} }
} }
@Test
fun onExistingSessionSelected() {
val navController: NavController = mockk(relaxed = true)
every { navController.currentDestination } returns NavDestination("").apply { id = R.id.searchFragment }
val context: Context = mockk(relaxed = true)
val applicationContext: FenixApplication = mockk(relaxed = true)
every { context.applicationContext } returns applicationContext
val interactor = SearchInteractor(context, navController, mockk())
val session = Session("http://mozilla.org", false)
interactor.onExistingSessionSelected(session)
verify {
navController.navigate(SearchFragmentDirections.actionSearchFragmentToBrowserFragment(null))
}
}
} }