2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-19 09:25:34 +00:00

[fenix] Fixes https://github.com/mozilla-mobile/fenix/issues/4354: Updated SearchFragment state after returning from SearchEngineFragment.

The user has the option to go to 'Shortcuts' -> 'Search engine settings' to
modify the default search engine. When returning from that settings screen we
need to update it to account for any changes.
For this we will check the current default engine against a previously stored
value in a newly added 'defaultEngineSource' property from SearchState class.
Also, I modified 'SearchStoreTest' by adding the new parameter to the
'SearchState' constructor.
This commit is contained in:
ValentinTimisica 2019-08-01 17:48:38 +03:00 committed by Jeff Boek
parent 260b91bc23
commit f65f57cfbb
3 changed files with 25 additions and 4 deletions

View File

@ -67,15 +67,17 @@ class SearchFragment : Fragment(), BackHandler {
val view = inflater.inflate(R.layout.fragment_search, container, false)
val url = session?.url ?: ""
val currentSearchEngine = SearchEngineSource.Default(
requireComponents.search.searchEngineManager.getDefaultSearchEngine(requireContext())
)
searchStore = StoreProvider.get(this) {
SearchStore(
SearchState(
query = url,
showShortcutEnginePicker = true,
searchEngineSource = SearchEngineSource.Default(
requireComponents.search.searchEngineManager.getDefaultSearchEngine(requireContext())
),
showShortcutEnginePicker = false,
searchEngineSource = currentSearchEngine,
defaultEngineSource = currentSearchEngine,
showSuggestions = Settings.getInstance(requireContext()).showSearchSuggestions,
showVisitedSitesBookmarks = Settings.getInstance(requireContext()).shouldShowVisitedSitesBookmarks,
session = session
@ -183,6 +185,16 @@ class SearchFragment : Fragment(), BackHandler {
override fun onResume() {
super.onResume()
// The user has the option to go to 'Shortcuts' -> 'Search engine settings' to modify the default search engine.
// When returning from that settings screen we need to update it to account for any changes.
val currentDefaultEngine = requireComponents.search.searchEngineManager.getDefaultSearchEngine(requireContext())
if (searchStore.state.defaultEngineSource.searchEngine != currentDefaultEngine) {
searchStore.dispatch(
SearchAction.SelectNewDefaultSearchEngine
(currentDefaultEngine)
)
}
if (!permissionDidUpdate) {
toolbarView.view.requestFocus()
}

View File

@ -35,6 +35,7 @@ sealed class SearchEngineSource {
* @property query The current search query string
* @property showShortcutEnginePicker Whether or not to show the available search engine view
* @property searchEngineSource The current selected search engine with the context of how it was selected
* @property defaultEngineSource The current default search engine source
* @property showSuggestions Whether or not to show search suggestions for the selected search engine in the AwesomeBar
* @property showVisitedSitesBookmarks Whether or not to show history and bookmark suggestions in the AwesomeBar
* @property session The current session if available
@ -43,6 +44,7 @@ data class SearchState(
val query: String,
val showShortcutEnginePicker: Boolean,
val searchEngineSource: SearchEngineSource,
val defaultEngineSource: SearchEngineSource.Default,
val showSuggestions: Boolean,
val showVisitedSitesBookmarks: Boolean,
val session: Session?
@ -53,6 +55,7 @@ data class SearchState(
*/
sealed class SearchAction : Action {
data class SearchShortcutEngineSelected(val engine: SearchEngine) : SearchAction()
data class SelectNewDefaultSearchEngine(val engine: SearchEngine) : SearchAction()
data class ShowSearchShortcutEnginePicker(val show: Boolean) : SearchAction()
data class UpdateQuery(val query: String) : SearchAction()
}
@ -71,5 +74,10 @@ fun searchStateReducer(state: SearchState, action: SearchAction): SearchState {
state.copy(showShortcutEnginePicker = action.show)
is SearchAction.UpdateQuery ->
state.copy(query = action.query)
is SearchAction.SelectNewDefaultSearchEngine ->
state.copy(
searchEngineSource = SearchEngineSource.Default(action.engine),
showShortcutEnginePicker = false
)
}
}

View File

@ -48,6 +48,7 @@ class SearchStoreTest {
private fun emptyDefaultState(): SearchState = SearchState(
query = "",
searchEngineSource = mockk(),
defaultEngineSource = mockk(),
showShortcutEnginePicker = false,
showSuggestions = false,
showVisitedSitesBookmarks = false,