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

Commit

Permalink
For #3544 - Set SearchSuggestions preference value from settings
Browse files Browse the repository at this point in the history
  • Loading branch information
ekager authored and st3fan committed Jun 18, 2019
1 parent a80131f commit e70ef3c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class AwesomeBarUIView(
components.core.icons
)

if (Settings.getInstance(container.context).showSearchSuggestions()) {
if (Settings.getInstance(container.context).showSearchSuggestions) {
val searchDrawable = getDrawable(R.drawable.ic_search)
searchDrawable?.setColorFilter(
ContextCompat.getColor(
Expand Down Expand Up @@ -171,7 +171,7 @@ class AwesomeBarUIView(
}

private fun showSuggestionProviders() {
if (Settings.getInstance(container.context).showSearchSuggestions()) {
if (Settings.getInstance(container.context).showSearchSuggestions) {
view.addProviders(searchSuggestionProvider!!)
}

Expand All @@ -187,7 +187,7 @@ class AwesomeBarUIView(
}

private fun showSearchSuggestionProvider() {
if (Settings.getInstance(container.context).showSearchSuggestions()) {
if (Settings.getInstance(container.context).showSearchSuggestions) {
view.addProviders(searchSuggestionProvider!!)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ package org.mozilla.fenix.settings

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreference
import org.mozilla.fenix.R
import org.mozilla.fenix.utils.Settings

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

val searchSuggestionsPreference =
findPreference<Preference>(getString(R.string.pref_key_show_search_suggestions))
findPreference<SwitchPreference>(getString(R.string.pref_key_show_search_suggestions))?.apply {
isChecked = Settings.getInstance(context).showSearchSuggestions
}

searchSuggestionsPreference?.setOnPreferenceChangeListener { preference, newValue ->
Settings.getInstance(preference.context).preferences.edit().putBoolean(preference.key, newValue as Boolean)
.apply()
true
}

val showVisitedSitesBookmarks =
findPreference<Preference>(getString(R.string.pref_key_show_visited_sites_bookmarks))
findPreference<SwitchPreference>(getString(R.string.pref_key_show_visited_sites_bookmarks))?.apply {
isChecked = Settings.getInstance(context).shouldShowVisitedSitesBookmarks
}

showVisitedSitesBookmarks?.setOnPreferenceChangeListener { preference, newValue ->
Settings.getInstance(preference.context).preferences.edit().putBoolean(preference.key, newValue as Boolean)
.apply()
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/org/mozilla/fenix/utils/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ class Settings private constructor(context: Context) {
.apply()
}

fun showSearchSuggestions(): Boolean = preferences.getBoolean(
appContext.getPreferenceKey(R.string.pref_key_show_search_suggestions),
true
)
val showSearchSuggestions: Boolean
get() = preferences.getBoolean(
appContext.getPreferenceKey(R.string.pref_key_show_search_suggestions), true
)

fun setSitePermissionsPhoneFeatureCameraAction(action: SitePermissionsRules.Action) {
preferences.edit()
Expand Down

0 comments on commit e70ef3c

Please sign in to comment.