mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-19 09:25:34 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/24300 - Add Tabs to the search engine menu
This commit is contained in:
parent
9bdc88cfb3
commit
397f1ffbb2
@ -205,6 +205,12 @@ class Core(
|
||||
url = "",
|
||||
icon = getDrawable(context, R.drawable.ic_bookmarks_search)?.toBitmap()!!,
|
||||
),
|
||||
createApplicationSearchEngine(
|
||||
id = TABS_SEARCH_ENGINE_ID,
|
||||
name = context.getString(R.string.preferences_tabs),
|
||||
url = "",
|
||||
icon = getDrawable(context, R.drawable.ic_tabs_search)?.toBitmap()!!,
|
||||
),
|
||||
createApplicationSearchEngine(
|
||||
id = HISTORY_SEARCH_ENGINE_ID,
|
||||
name = context.getString(R.string.library_history),
|
||||
@ -521,6 +527,7 @@ class Core(
|
||||
private const val CONTILE_MAX_CACHE_AGE = 60L // 60 minutes
|
||||
const val HISTORY_SEARCH_ENGINE_ID = "history_search_engine_id"
|
||||
const val BOOKMARKS_SEARCH_ENGINE_ID = "bookmarks_search_engine_id"
|
||||
const val TABS_SEARCH_ENGINE_ID = "tabs_search_engine_id"
|
||||
|
||||
// Maximum number of suggestions returned from the history search engine source.
|
||||
const val METADATA_HISTORY_SUGGESTION_LIMIT = 100
|
||||
|
@ -205,6 +205,9 @@ class SearchDialogController(
|
||||
&& searchEngine.id == Core.BOOKMARKS_SEARCH_ENGINE_ID -> {
|
||||
fragmentStore.dispatch(SearchFragmentAction.SearchBookmarksEngineSelected(searchEngine))
|
||||
}
|
||||
searchEngine.type == SearchEngine.Type.APPLICATION && searchEngine.id == Core.TABS_SEARCH_ENGINE_ID -> {
|
||||
fragmentStore.dispatch(SearchFragmentAction.SearchTabsEngineSelected(searchEngine))
|
||||
}
|
||||
searchEngine == store.state.search.selectedOrDefaultSearchEngine -> {
|
||||
fragmentStore.dispatch(SearchFragmentAction.SearchDefaultEngineSelected(searchEngine, settings))
|
||||
}
|
||||
|
@ -61,6 +61,11 @@ sealed class SearchEngineSource {
|
||||
* Search engine for bookmarks
|
||||
*/
|
||||
data class Bookmarks(override val searchEngine: SearchEngine) : SearchEngineSource()
|
||||
|
||||
/**
|
||||
* Search engine for tabs
|
||||
*/
|
||||
data class Tabs(override val searchEngine: SearchEngine) : SearchEngineSource()
|
||||
}
|
||||
|
||||
/**
|
||||
@ -180,6 +185,11 @@ sealed class SearchFragmentAction : Action {
|
||||
*/
|
||||
data class SearchBookmarksEngineSelected(val engine: SearchEngine) : SearchFragmentAction()
|
||||
|
||||
/**
|
||||
* Action when tabs search engine is selected.
|
||||
*/
|
||||
data class SearchTabsEngineSelected(val engine: SearchEngine) : SearchFragmentAction()
|
||||
|
||||
/**
|
||||
* Action when search engine picker is selected.
|
||||
*/
|
||||
@ -271,6 +281,17 @@ private fun searchStateReducer(state: SearchFragmentState, action: SearchFragmen
|
||||
showSyncedTabsSuggestions = false,
|
||||
showSessionSuggestions = false,
|
||||
)
|
||||
is SearchFragmentAction.SearchTabsEngineSelected ->
|
||||
state.copy(
|
||||
searchEngineSource = SearchEngineSource.Tabs(action.engine),
|
||||
showSearchSuggestions = false,
|
||||
showSearchShortcuts = false,
|
||||
showClipboardSuggestions = false,
|
||||
showHistorySuggestions = false,
|
||||
showBookmarkSuggestions = false,
|
||||
showSyncedTabsSuggestions = true,
|
||||
showSessionSuggestions = true,
|
||||
)
|
||||
is SearchFragmentAction.ShowSearchShortcutEnginePicker ->
|
||||
state.copy(showSearchShortcuts = action.show && state.areShortcutsAvailable)
|
||||
is SearchFragmentAction.UpdateQuery ->
|
||||
|
@ -285,6 +285,7 @@ class AwesomeBarView(
|
||||
)
|
||||
is SearchEngineSource.History -> emptyList()
|
||||
is SearchEngineSource.Bookmarks -> emptyList()
|
||||
is SearchEngineSource.Tabs -> emptyList()
|
||||
is SearchEngineSource.None -> emptyList()
|
||||
}
|
||||
}
|
||||
|
18
app/src/main/res/drawable/ic_tabs_search.xml
Normal file
18
app/src/main/res/drawable/ic_tabs_search.xml
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:name="path"
|
||||
android:fillColor="@color/photonWhite"
|
||||
android:pathData="M 2 0 L 22 0 C 22.53 0 23.039 0.211 23.414 0.586 C 23.789 0.961 24 1.47 24 2 L 24 22 C 24 22.53 23.789 23.039 23.414 23.414 C 23.039 23.789 22.53 24 22 24 L 2 24 C 1.47 24 0.961 23.789 0.586 23.414 C 0.211 23.039 0 22.53 0 22 L 0 2 C 0 1.47 0.211 0.961 0.586 0.586 C 0.961 0.211 1.47 0 2 0"
|
||||
android:strokeWidth="1" />
|
||||
<path
|
||||
android:pathData="M4.5,4C3.119,4 2,5.119 2,6.5V17.5C2,18.881 3.119,20 4.5,20H19.5C20.881,20 22,18.881 22,17.5V6.5C22,5.119 20.881,4 19.5,4H4.5ZM20.5,17.7L19.7,18.5H4.3L3.5,17.7V6.3L4.3,5.5H19.7L20.5,6.3V17.7Z"
|
||||
android:fillColor="@color/photonBlack"/>
|
||||
</vector>
|
@ -407,6 +407,31 @@ class SearchDialogControllerTest {
|
||||
assertEquals("application", eventExtra["engine"])
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN tabs search engine is selected THEN dispatch correct action`() {
|
||||
val searchEngine: SearchEngine = mockk(relaxed = true)
|
||||
every { searchEngine.type } returns SearchEngine.Type.APPLICATION
|
||||
every { searchEngine.id } returns Core.TABS_SEARCH_ENGINE_ID
|
||||
|
||||
var focusToolbarInvoked = false
|
||||
createController(
|
||||
focusToolbar = {
|
||||
focusToolbarInvoked = true
|
||||
}
|
||||
).handleSearchShortcutEngineSelected(searchEngine)
|
||||
|
||||
assertTrue(focusToolbarInvoked)
|
||||
verify { store.dispatch(SearchFragmentAction.SearchTabsEngineSelected(searchEngine)) }
|
||||
|
||||
assertTrue(SearchShortcuts.selected.testHasValue())
|
||||
val recordedEvents = SearchShortcuts.selected.testGetValue()
|
||||
assertEquals(1, recordedEvents.size)
|
||||
val eventExtra = recordedEvents.single().extra
|
||||
assertNotNull(eventExtra)
|
||||
assertTrue(eventExtra!!.containsKey("engine"))
|
||||
assertEquals("application", eventExtra["engine"])
|
||||
}
|
||||
|
||||
@Test
|
||||
fun handleClickSearchEngineSettings() {
|
||||
val directions: NavDirections = actionGlobalSearchEngineFragment()
|
||||
|
@ -185,6 +185,16 @@ class SearchFragmentStoreTest {
|
||||
assertEquals(SearchEngineSource.Bookmarks(searchEngine), store.state.searchEngineSource)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN tabs engine selected action dispatched THEN update search engine source`() = runTest {
|
||||
val initialState = emptyDefaultState()
|
||||
val store = SearchFragmentStore(initialState)
|
||||
|
||||
store.dispatch(SearchFragmentAction.SearchTabsEngineSelected(searchEngine)).join()
|
||||
assertNotSame(initialState, store.state)
|
||||
assertEquals(SearchEngineSource.Tabs(searchEngine), store.state.searchEngineSource)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun showSearchShortcutEnginePicker() = runTest {
|
||||
val initialState = emptyDefaultState()
|
||||
|
Loading…
Reference in New Issue
Block a user