diff --git a/app/src/main/java/org/mozilla/fenix/search/SearchFragment.kt b/app/src/main/java/org/mozilla/fenix/search/SearchFragment.kt index f77317138b..01f92dc172 100644 --- a/app/src/main/java/org/mozilla/fenix/search/SearchFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/search/SearchFragment.kt @@ -81,13 +81,20 @@ class SearchFragment : Fragment(), BackHandler { requireComponents.search.provider.getDefaultEngine(requireContext()) ) + val showSearchSuggestions = if ((activity as HomeActivity).browsingModeManager.mode.isPrivate) { + requireContext().settings().shouldShowSearchSuggestions && + requireContext().settings().shouldShowSearchSuggestionsInPrivate + } else { + requireContext().settings().shouldShowSearchSuggestions + } + searchStore = StoreProvider.get(this) { SearchFragmentStore( SearchFragmentState( query = url, searchEngineSource = currentSearchEngine, defaultEngineSource = currentSearchEngine, - showSearchSuggestions = requireContext().settings().shouldShowSearchSuggestions, + showSearchSuggestions = showSearchSuggestions, showSearchShortcuts = requireContext().settings().shouldShowSearchShortcuts && url.isEmpty(), showClipboardSuggestions = requireContext().settings().shouldShowClipboardSuggestions, showHistorySuggestions = requireContext().settings().shouldShowHistorySuggestions, diff --git a/app/src/main/java/org/mozilla/fenix/settings/search/SearchEngineFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/search/SearchEngineFragment.kt index 52d06c6f20..95f0574a2c 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/search/SearchEngineFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/search/SearchEngineFragment.kt @@ -8,6 +8,7 @@ import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import androidx.navigation.fragment.findNavController import androidx.preference.Preference +import androidx.preference.CheckBoxPreference import androidx.preference.PreferenceFragmentCompat import androidx.preference.SwitchPreference import org.mozilla.fenix.R @@ -31,6 +32,12 @@ class SearchEngineFragment : PreferenceFragmentCompat() { isChecked = context.settings().shouldShowSearchSuggestions } + val searchSuggestionsInPrivatePreference = + findPreference(getPreferenceKey(R.string.pref_key_show_search_suggestions_in_private)) + ?.apply { + isChecked = context.settings().shouldShowSearchSuggestionsInPrivate + } + val showSearchShortcuts = findPreference(getPreferenceKey(R.string.pref_key_show_search_shortcuts))?.apply { isChecked = context.settings().shouldShowSearchShortcuts @@ -60,6 +67,15 @@ class SearchEngineFragment : PreferenceFragmentCompat() { showHistorySuggestions?.onPreferenceChangeListener = SharedPreferenceUpdater() showBookmarkSuggestions?.onPreferenceChangeListener = SharedPreferenceUpdater() showClipboardSuggestions?.onPreferenceChangeListener = SharedPreferenceUpdater() + searchSuggestionsInPrivatePreference?.onPreferenceChangeListener = SharedPreferenceUpdater() + + searchSuggestionsPreference?.setOnPreferenceClickListener { + if (!searchSuggestionsPreference.isChecked) { + searchSuggestionsInPrivatePreference?.isChecked = false + searchSuggestionsInPrivatePreference?.callChangeListener(false) + } + true + } } override fun onPreferenceTreeClick(preference: Preference): Boolean { diff --git a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt index 269a165554..5b8653e186 100644 --- a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt +++ b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt @@ -263,6 +263,11 @@ class Settings private constructor( default = true ) + val shouldShowSearchSuggestionsInPrivate by booleanPreference( + appContext.getPreferenceKey(R.string.pref_key_show_search_suggestions_in_private), + default = false + ) + @VisibleForTesting(otherwise = PRIVATE) internal val trackingProtectionOnboardingCount by intPreference( appContext.getPreferenceKey(R.string.pref_key_tracking_protection_onboarding), diff --git a/app/src/main/res/layout/checkbox_left_preference.xml b/app/src/main/res/layout/checkbox_left_preference.xml index fcc2cd5b8f..e1bdea9d22 100644 --- a/app/src/main/res/layout/checkbox_left_preference.xml +++ b/app/src/main/res/layout/checkbox_left_preference.xml @@ -11,7 +11,6 @@ android:clickable="true" android:focusable="true" android:gravity="center_vertical" - android:minHeight="?android:attr/listPreferredItemHeight" android:paddingStart="8dp" android:paddingEnd="?android:attr/scrollbarSize"> diff --git a/app/src/main/res/values/preference_keys.xml b/app/src/main/res/values/preference_keys.xml index 4077fe6ebe..2c2a8a498f 100644 --- a/app/src/main/res/values/preference_keys.xml +++ b/app/src/main/res/values/preference_keys.xml @@ -74,6 +74,8 @@ pref_key_show_clipboard_suggestions pref_key_search_browsing_history pref_key_search_bookmarks + pref_key_show_search_suggestions_in_private + pref_key_optimize diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7cd63124c7..aca542e986 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -134,6 +134,8 @@ Default search engine Search + + Address bar Help @@ -191,6 +193,8 @@ Show search shortcuts Show search suggestions + + Show in private sessions Show clipboard suggestions diff --git a/app/src/main/res/xml/search_preferences.xml b/app/src/main/res/xml/search_preferences.xml index b0d79fe52e..30ed1f7d29 100644 --- a/app/src/main/res/xml/search_preferences.xml +++ b/app/src/main/res/xml/search_preferences.xml @@ -12,16 +12,17 @@ + + + + - + +