Skip to content
This repository was archived by the owner on Feb 20, 2023. It is now read-only.

Commit e70ef3c

Browse files
ekagerst3fan
authored andcommitted
For #3544 - Set SearchSuggestions preference value from settings
1 parent a80131f commit e70ef3c

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

app/src/main/java/org/mozilla/fenix/search/awesomebar/AwesomeBarUIView.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class AwesomeBarUIView(
128128
components.core.icons
129129
)
130130

131-
if (Settings.getInstance(container.context).showSearchSuggestions()) {
131+
if (Settings.getInstance(container.context).showSearchSuggestions) {
132132
val searchDrawable = getDrawable(R.drawable.ic_search)
133133
searchDrawable?.setColorFilter(
134134
ContextCompat.getColor(
@@ -171,7 +171,7 @@ class AwesomeBarUIView(
171171
}
172172

173173
private fun showSuggestionProviders() {
174-
if (Settings.getInstance(container.context).showSearchSuggestions()) {
174+
if (Settings.getInstance(container.context).showSearchSuggestions) {
175175
view.addProviders(searchSuggestionProvider!!)
176176
}
177177

@@ -187,7 +187,7 @@ class AwesomeBarUIView(
187187
}
188188

189189
private fun showSearchSuggestionProvider() {
190-
if (Settings.getInstance(container.context).showSearchSuggestions()) {
190+
if (Settings.getInstance(container.context).showSearchSuggestions) {
191191
view.addProviders(searchSuggestionProvider!!)
192192
}
193193
}

app/src/main/java/org/mozilla/fenix/settings/SearchEngineFragment.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ package org.mozilla.fenix.settings
66

77
import android.os.Bundle
88
import androidx.appcompat.app.AppCompatActivity
9-
import androidx.preference.Preference
109
import androidx.preference.PreferenceFragmentCompat
10+
import androidx.preference.SwitchPreference
1111
import org.mozilla.fenix.R
1212
import org.mozilla.fenix.utils.Settings
1313

@@ -23,15 +23,21 @@ class SearchEngineFragment : PreferenceFragmentCompat() {
2323
(activity as AppCompatActivity).supportActionBar?.show()
2424

2525
val searchSuggestionsPreference =
26-
findPreference<Preference>(getString(R.string.pref_key_show_search_suggestions))
26+
findPreference<SwitchPreference>(getString(R.string.pref_key_show_search_suggestions))?.apply {
27+
isChecked = Settings.getInstance(context).showSearchSuggestions
28+
}
29+
2730
searchSuggestionsPreference?.setOnPreferenceChangeListener { preference, newValue ->
2831
Settings.getInstance(preference.context).preferences.edit().putBoolean(preference.key, newValue as Boolean)
2932
.apply()
3033
true
3134
}
3235

3336
val showVisitedSitesBookmarks =
34-
findPreference<Preference>(getString(R.string.pref_key_show_visited_sites_bookmarks))
37+
findPreference<SwitchPreference>(getString(R.string.pref_key_show_visited_sites_bookmarks))?.apply {
38+
isChecked = Settings.getInstance(context).shouldShowVisitedSitesBookmarks
39+
}
40+
3541
showVisitedSitesBookmarks?.setOnPreferenceChangeListener { preference, newValue ->
3642
Settings.getInstance(preference.context).preferences.edit().putBoolean(preference.key, newValue as Boolean)
3743
.apply()

app/src/main/java/org/mozilla/fenix/utils/Settings.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,10 @@ class Settings private constructor(context: Context) {
168168
.apply()
169169
}
170170

171-
fun showSearchSuggestions(): Boolean = preferences.getBoolean(
172-
appContext.getPreferenceKey(R.string.pref_key_show_search_suggestions),
173-
true
174-
)
171+
val showSearchSuggestions: Boolean
172+
get() = preferences.getBoolean(
173+
appContext.getPreferenceKey(R.string.pref_key_show_search_suggestions), true
174+
)
175175

176176
fun setSitePermissionsPhoneFeatureCameraAction(action: SitePermissionsRules.Action) {
177177
preferences.edit()

0 commit comments

Comments
 (0)