1
0
Fork 0
fenix/app/src/main/java/org/mozilla/fenix/settings/search/SearchEngineFragment.kt

98 lines
4.2 KiB
Kotlin
Raw Normal View History

/* 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/. */
2019-09-14 06:29:11 +02:00
package org.mozilla.fenix.settings.search
import android.os.Bundle
Adds custom search engines (#6551) * For #5577 - Adds button to add a new search engine * For #5577 - Adds custom engine store * For #5577 - Creates a custom SearchEngineProvider * For #5577 - Gives the ability to delete search engines * For #5577 - Adds the UI to add a custom search engine * For #5577 - Adds form to create a custom search engine * For #5577 - Adds the ability to add a custom search engine * For #5577 - Adds the ability to delete custom search engines * For #5577 - Selects the first element on the add custom search engine screen * For #5577 - Prevents adding a search engine that already exists * For #5577 - Styles the add search engine preference * For #5577 - Makes the name check case-insensitive * For #5577 - Fix bug where home screen doesnt see new search engines * For #5577 - Moves Search URL validation to its own type * For #5577 - Fixes linting errors * For #5577 - Adds the ability to edit a custom search engine * For #5577 - Allows the user to edit a serach engine even when it is the last item in the list * For #5577 - Adds an undo snackbar when deleting a search engine * For #5577 - Moves all of the strings to be translated * For #5577 - Fixes bug when deleting your default search engine * For #5577 - Puts adding search engines behind a feature flag * For #5577 - Navigate to custom search engine SUMO article when tapping learn more * For #5577 - Fixes nits * For #5577 - Uses concept-fetch to validate search string * For #5577 - Adds string resources for the cannot reach error state
2019-11-20 01:30:56 +01:00
import androidx.navigation.fragment.findNavController
import androidx.preference.CheckBoxPreference
2020-02-06 17:14:32 +01:00
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreference
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.getPreferenceKey
import org.mozilla.fenix.ext.settings
2019-11-25 21:36:47 +01:00
import org.mozilla.fenix.ext.showToolbar
2019-09-14 06:29:11 +02:00
import org.mozilla.fenix.settings.SharedPreferenceUpdater
2020-06-15 20:24:14 +02:00
import org.mozilla.fenix.settings.requirePreference
class SearchEngineFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.search_preferences, rootKey)
}
override fun onResume() {
super.onResume()
2019-11-25 21:36:47 +01:00
showToolbar(getString(R.string.preferences_search))
val searchSuggestionsPreference =
2020-06-15 20:24:14 +02:00
requirePreference<SwitchPreference>(R.string.pref_key_show_search_suggestions).apply {
isChecked = context.settings().shouldShowSearchSuggestions
}
val searchSuggestionsInPrivatePreference =
2020-06-15 20:24:14 +02:00
requirePreference<CheckBoxPreference>(R.string.pref_key_show_search_suggestions_in_private).apply {
isChecked = context.settings().shouldShowSearchSuggestionsInPrivate
}
val showSearchShortcuts =
requirePreference<SwitchPreference>(R.string.pref_key_show_search_engine_shortcuts).apply {
isChecked = context.settings().shouldShowSearchShortcuts
}
val showHistorySuggestions =
2020-06-15 20:24:14 +02:00
requirePreference<SwitchPreference>(R.string.pref_key_search_browsing_history).apply {
isChecked = context.settings().shouldShowHistorySuggestions
}
val showBookmarkSuggestions =
2020-06-15 20:24:14 +02:00
requirePreference<SwitchPreference>(R.string.pref_key_search_bookmarks).apply {
isChecked = context.settings().shouldShowBookmarkSuggestions
}
val showClipboardSuggestions =
2020-06-15 20:24:14 +02:00
requirePreference<SwitchPreference>(R.string.pref_key_show_clipboard_suggestions).apply {
isChecked = context.settings().shouldShowClipboardSuggestions
}
Adds custom search engines (#6551) * For #5577 - Adds button to add a new search engine * For #5577 - Adds custom engine store * For #5577 - Creates a custom SearchEngineProvider * For #5577 - Gives the ability to delete search engines * For #5577 - Adds the UI to add a custom search engine * For #5577 - Adds form to create a custom search engine * For #5577 - Adds the ability to add a custom search engine * For #5577 - Adds the ability to delete custom search engines * For #5577 - Selects the first element on the add custom search engine screen * For #5577 - Prevents adding a search engine that already exists * For #5577 - Styles the add search engine preference * For #5577 - Makes the name check case-insensitive * For #5577 - Fix bug where home screen doesnt see new search engines * For #5577 - Moves Search URL validation to its own type * For #5577 - Fixes linting errors * For #5577 - Adds the ability to edit a custom search engine * For #5577 - Allows the user to edit a serach engine even when it is the last item in the list * For #5577 - Adds an undo snackbar when deleting a search engine * For #5577 - Moves all of the strings to be translated * For #5577 - Fixes bug when deleting your default search engine * For #5577 - Puts adding search engines behind a feature flag * For #5577 - Navigate to custom search engine SUMO article when tapping learn more * For #5577 - Fixes nits * For #5577 - Uses concept-fetch to validate search string * For #5577 - Adds string resources for the cannot reach error state
2019-11-20 01:30:56 +01:00
val searchEngineListPreference =
2020-06-15 20:24:14 +02:00
requirePreference<SearchEngineListPreference>(R.string.pref_key_search_engine_list)
Adds custom search engines (#6551) * For #5577 - Adds button to add a new search engine * For #5577 - Adds custom engine store * For #5577 - Creates a custom SearchEngineProvider * For #5577 - Gives the ability to delete search engines * For #5577 - Adds the UI to add a custom search engine * For #5577 - Adds form to create a custom search engine * For #5577 - Adds the ability to add a custom search engine * For #5577 - Adds the ability to delete custom search engines * For #5577 - Selects the first element on the add custom search engine screen * For #5577 - Prevents adding a search engine that already exists * For #5577 - Styles the add search engine preference * For #5577 - Makes the name check case-insensitive * For #5577 - Fix bug where home screen doesnt see new search engines * For #5577 - Moves Search URL validation to its own type * For #5577 - Fixes linting errors * For #5577 - Adds the ability to edit a custom search engine * For #5577 - Allows the user to edit a serach engine even when it is the last item in the list * For #5577 - Adds an undo snackbar when deleting a search engine * For #5577 - Moves all of the strings to be translated * For #5577 - Fixes bug when deleting your default search engine * For #5577 - Puts adding search engines behind a feature flag * For #5577 - Navigate to custom search engine SUMO article when tapping learn more * For #5577 - Fixes nits * For #5577 - Uses concept-fetch to validate search string * For #5577 - Adds string resources for the cannot reach error state
2019-11-20 01:30:56 +01:00
2020-05-14 19:47:13 +02:00
val showVoiceSearchPreference =
2020-06-15 20:24:14 +02:00
requirePreference<SwitchPreference>(R.string.pref_key_show_voice_search).apply {
2020-05-14 19:47:13 +02:00
isChecked = context.settings().shouldShowVoiceSearch
}
2020-06-15 20:24:14 +02:00
searchEngineListPreference.reload(requireContext())
searchSuggestionsPreference.onPreferenceChangeListener = SharedPreferenceUpdater()
showSearchShortcuts.onPreferenceChangeListener = SharedPreferenceUpdater()
showHistorySuggestions.onPreferenceChangeListener = SharedPreferenceUpdater()
showBookmarkSuggestions.onPreferenceChangeListener = SharedPreferenceUpdater()
showClipboardSuggestions.onPreferenceChangeListener = SharedPreferenceUpdater()
searchSuggestionsInPrivatePreference.onPreferenceChangeListener = SharedPreferenceUpdater()
showVoiceSearchPreference.onPreferenceChangeListener = SharedPreferenceUpdater()
2020-06-15 20:24:14 +02:00
searchSuggestionsPreference.setOnPreferenceClickListener {
if (!searchSuggestionsPreference.isChecked) {
2020-06-15 20:24:14 +02:00
searchSuggestionsInPrivatePreference.isChecked = false
searchSuggestionsInPrivatePreference.callChangeListener(false)
}
true
}
}
Adds custom search engines (#6551) * For #5577 - Adds button to add a new search engine * For #5577 - Adds custom engine store * For #5577 - Creates a custom SearchEngineProvider * For #5577 - Gives the ability to delete search engines * For #5577 - Adds the UI to add a custom search engine * For #5577 - Adds form to create a custom search engine * For #5577 - Adds the ability to add a custom search engine * For #5577 - Adds the ability to delete custom search engines * For #5577 - Selects the first element on the add custom search engine screen * For #5577 - Prevents adding a search engine that already exists * For #5577 - Styles the add search engine preference * For #5577 - Makes the name check case-insensitive * For #5577 - Fix bug where home screen doesnt see new search engines * For #5577 - Moves Search URL validation to its own type * For #5577 - Fixes linting errors * For #5577 - Adds the ability to edit a custom search engine * For #5577 - Allows the user to edit a serach engine even when it is the last item in the list * For #5577 - Adds an undo snackbar when deleting a search engine * For #5577 - Moves all of the strings to be translated * For #5577 - Fixes bug when deleting your default search engine * For #5577 - Puts adding search engines behind a feature flag * For #5577 - Navigate to custom search engine SUMO article when tapping learn more * For #5577 - Fixes nits * For #5577 - Uses concept-fetch to validate search string * For #5577 - Adds string resources for the cannot reach error state
2019-11-20 01:30:56 +01:00
override fun onPreferenceTreeClick(preference: Preference): Boolean {
when (preference.key) {
getPreferenceKey(R.string.pref_key_add_search_engine) -> {
val directions = SearchEngineFragmentDirections
.actionSearchEngineFragmentToAddSearchEngineFragment()
findNavController().navigate(directions)
}
}
return super.onPreferenceTreeClick(preference)
}
}