mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-19 09:25:34 +00:00
[fenix] Issue https://github.com/mozilla-mobile/fenix/issues/24301: Add Bookmarks to the search engine menu
This commit is contained in:
parent
54f5cd82aa
commit
bd2263d32d
@ -33,8 +33,8 @@ messaging:
|
||||
type: string
|
||||
description: What should be displayed when a control message is selected.
|
||||
enum:
|
||||
- show-next-message
|
||||
- show-none
|
||||
- show-next-message
|
||||
styles:
|
||||
type: json
|
||||
description: "A map of styles to configure message appearance.\n"
|
||||
|
@ -199,12 +199,18 @@ class Core(
|
||||
|
||||
val applicationSearchEngines: List<SearchEngine> by lazyMonitored {
|
||||
listOf(
|
||||
createApplicationSearchEngine(
|
||||
id = BOOKMARKS_SEARCH_ENGINE_ID,
|
||||
name = context.getString(R.string.library_bookmarks),
|
||||
url = "",
|
||||
icon = getDrawable(context, R.drawable.ic_bookmarks_search)?.toBitmap()!!,
|
||||
),
|
||||
createApplicationSearchEngine(
|
||||
id = HISTORY_SEARCH_ENGINE_ID,
|
||||
name = context.getString(R.string.library_history),
|
||||
url = "",
|
||||
icon = getDrawable(context, R.drawable.ic_history_search)?.toBitmap()!!,
|
||||
)
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@ -514,6 +520,7 @@ class Core(
|
||||
const val HISTORY_METADATA_MAX_AGE_IN_MS = 14 * 24 * 60 * 60 * 1000 // 14 days
|
||||
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"
|
||||
|
||||
// Maximum number of suggestions returned from the history search engine source.
|
||||
const val METADATA_HISTORY_SUGGESTION_LIMIT = 100
|
||||
|
@ -201,6 +201,10 @@ class SearchDialogController(
|
||||
searchEngine.type == SearchEngine.Type.APPLICATION && searchEngine.id == Core.HISTORY_SEARCH_ENGINE_ID -> {
|
||||
fragmentStore.dispatch(SearchFragmentAction.SearchHistoryEngineSelected(searchEngine))
|
||||
}
|
||||
searchEngine.type == SearchEngine.Type.APPLICATION
|
||||
&& searchEngine.id == Core.BOOKMARKS_SEARCH_ENGINE_ID -> {
|
||||
fragmentStore.dispatch(SearchFragmentAction.SearchBookmarksEngineSelected(searchEngine))
|
||||
}
|
||||
searchEngine == store.state.search.selectedOrDefaultSearchEngine -> {
|
||||
fragmentStore.dispatch(SearchFragmentAction.SearchDefaultEngineSelected(searchEngine, settings))
|
||||
}
|
||||
|
@ -56,6 +56,11 @@ sealed class SearchEngineSource {
|
||||
* Search engine for history
|
||||
*/
|
||||
data class History(override val searchEngine: SearchEngine) : SearchEngineSource()
|
||||
|
||||
/**
|
||||
* Search engine for bookmarks
|
||||
*/
|
||||
data class Bookmarks(override val searchEngine: SearchEngine) : SearchEngineSource()
|
||||
}
|
||||
|
||||
/**
|
||||
@ -170,6 +175,11 @@ sealed class SearchFragmentAction : Action {
|
||||
*/
|
||||
data class SearchHistoryEngineSelected(val engine: SearchEngine) : SearchFragmentAction()
|
||||
|
||||
/**
|
||||
* Action when bookmarks search engine is selected.
|
||||
*/
|
||||
data class SearchBookmarksEngineSelected(val engine: SearchEngine) : SearchFragmentAction()
|
||||
|
||||
/**
|
||||
* Action when search engine picker is selected.
|
||||
*/
|
||||
@ -250,6 +260,17 @@ private fun searchStateReducer(state: SearchFragmentState, action: SearchFragmen
|
||||
showSyncedTabsSuggestions = false,
|
||||
showSessionSuggestions = false,
|
||||
)
|
||||
is SearchFragmentAction.SearchBookmarksEngineSelected ->
|
||||
state.copy(
|
||||
searchEngineSource = SearchEngineSource.Bookmarks(action.engine),
|
||||
showSearchSuggestions = false,
|
||||
showSearchShortcuts = false,
|
||||
showClipboardSuggestions = false,
|
||||
showHistorySuggestions = false,
|
||||
showBookmarkSuggestions = true,
|
||||
showSyncedTabsSuggestions = false,
|
||||
showSessionSuggestions = false,
|
||||
)
|
||||
is SearchFragmentAction.ShowSearchShortcutEnginePicker ->
|
||||
state.copy(showSearchShortcuts = action.show && state.areShortcutsAvailable)
|
||||
is SearchFragmentAction.UpdateQuery ->
|
||||
|
@ -284,6 +284,7 @@ class AwesomeBarView(
|
||||
state.searchEngineSource.searchEngine
|
||||
)
|
||||
is SearchEngineSource.History -> emptyList()
|
||||
is SearchEngineSource.Bookmarks -> emptyList()
|
||||
is SearchEngineSource.None -> emptyList()
|
||||
}
|
||||
}
|
||||
|
21
app/src/main/res/drawable/ic_bookmarks_search.xml
Normal file
21
app/src/main/res/drawable/ic_bookmarks_search.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<?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="m7.225,11.324 l-2.86,-2.375a1.207,1.207 0,0 1,-0.378 -1.309,1.205 1.205,0 0,1 1.074,-0.835l3.697,-0.239 0.501,-0.375 1.364,-3.427A1.209,1.209 0,0 1,11.75 2c0.499,0 0.941,0.3 1.127,0.763v0.001l1.364,3.427 0.501,0.375 3.697,0.239c0.498,0.032 0.92,0.36 1.074,0.835 0.155,0.476 0.006,0.99 -0.378,1.309L16.28,11.32l-0.18,0.592 0.91,3.575c0.123,0.485 -0.059,0.986 -0.463,1.279a1.202,1.202 0,0 1,-1.359 0.046l-3.127,-1.977h-0.621l-3.126,1.977c-0.426,0.266 -0.96,0.247 -1.361,-0.045a1.205,1.205 0,0 1,-0.463 -1.279l0.908,-3.566 -0.173,-0.598z"
|
||||
android:fillColor="@color/photonBlack"/>
|
||||
<path
|
||||
android:pathData="m5.782,20.5 l-0.8,-0.8v-1.95a0.75,0.75 0,0 0,-1.5 0v1.75a2.5,2.5 0,0 0,2.5 2.5h11.535a2.5,2.5 0,0 0,2.5 -2.5v-1.75a0.75,0.75 0,0 0,-1.5 0v1.95l-0.8,0.8H5.782z"
|
||||
android:fillColor="@color/photonBlack"/>
|
||||
</vector>
|
@ -382,6 +382,31 @@ class SearchDialogControllerTest {
|
||||
assertEquals("application", eventExtra["engine"])
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN bookmarks 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.BOOKMARKS_SEARCH_ENGINE_ID
|
||||
|
||||
var focusToolbarInvoked = false
|
||||
createController(
|
||||
focusToolbar = {
|
||||
focusToolbarInvoked = true
|
||||
}
|
||||
).handleSearchShortcutEngineSelected(searchEngine)
|
||||
|
||||
assertTrue(focusToolbarInvoked)
|
||||
verify { store.dispatch(SearchFragmentAction.SearchBookmarksEngineSelected(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()
|
||||
|
@ -175,6 +175,16 @@ class SearchFragmentStoreTest {
|
||||
assertEquals(SearchEngineSource.History(searchEngine), store.state.searchEngineSource)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN bookmarks engine selected action dispatched THEN update search engine source`() = runTest {
|
||||
val initialState = emptyDefaultState()
|
||||
val store = SearchFragmentStore(initialState)
|
||||
|
||||
store.dispatch(SearchFragmentAction.SearchBookmarksEngineSelected(searchEngine)).join()
|
||||
assertNotSame(initialState, store.state)
|
||||
assertEquals(SearchEngineSource.Bookmarks(searchEngine), store.state.searchEngineSource)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun showSearchShortcutEnginePicker() = runTest {
|
||||
val initialState = emptyDefaultState()
|
||||
|
Loading…
Reference in New Issue
Block a user