Closes #2635 - Save settings changes to new Shared Preferences file
parent
f912621bc3
commit
42d1491976
|
@ -48,8 +48,13 @@ class DataChoicesFragment : PreferenceFragmentCompat() {
|
|||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
setPreferencesFromResource(R.xml.data_choices_preferences, rootKey)
|
||||
|
||||
findPreference<SwitchPreference>(getString(R.string.pref_key_telemetry))?.apply {
|
||||
val telemetryPreference = findPreference<SwitchPreference>(getString(R.string.pref_key_telemetry))?.apply {
|
||||
isChecked = Settings.getInstance(context).isTelemetryEnabled
|
||||
}
|
||||
telemetryPreference?.setOnPreferenceChangeListener { preference, newValue ->
|
||||
Settings.getInstance(preference.context).preferences.edit().putBoolean(preference.key, newValue as Boolean)
|
||||
.apply()
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,18 +6,36 @@ package org.mozilla.fenix.settings
|
|||
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.utils.Settings
|
||||
|
||||
class SearchEngineFragment : PreferenceFragmentCompat() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
(activity as AppCompatActivity).title = getString(R.string.preferences_search_engine)
|
||||
(activity as AppCompatActivity).supportActionBar?.show()
|
||||
}
|
||||
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
setPreferencesFromResource(R.xml.search_engine_preferences, rootKey)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
(activity as AppCompatActivity).title = getString(R.string.preferences_search_engine)
|
||||
(activity as AppCompatActivity).supportActionBar?.show()
|
||||
|
||||
val searchSuggestionsPreference =
|
||||
findPreference<Preference>(getString(R.string.pref_key_show_search_suggestions))
|
||||
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))
|
||||
showVisitedSitesBookmarks?.setOnPreferenceChangeListener { preference, newValue ->
|
||||
Settings.getInstance(preference.context).preferences.edit().putBoolean(preference.key, newValue as Boolean)
|
||||
.apply()
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,35 +22,35 @@ import kotlinx.coroutines.launch
|
|||
import mozilla.components.concept.sync.AccountObserver
|
||||
import mozilla.components.concept.sync.OAuthAccount
|
||||
import mozilla.components.concept.sync.Profile
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
import mozilla.components.service.fxa.FxaUnauthorizedException
|
||||
import org.mozilla.fenix.FenixApplication
|
||||
import org.mozilla.fenix.HomeActivity
|
||||
import org.mozilla.fenix.BrowserDirection
|
||||
import org.mozilla.fenix.Config
|
||||
import org.mozilla.fenix.FenixApplication
|
||||
import org.mozilla.fenix.HomeActivity
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.ext.getPreferenceKey
|
||||
import org.mozilla.fenix.ext.requireComponents
|
||||
import org.mozilla.fenix.R.string.pref_key_leakcanary
|
||||
import org.mozilla.fenix.R.string.pref_key_about
|
||||
import org.mozilla.fenix.R.string.pref_key_accessibility
|
||||
import org.mozilla.fenix.R.string.pref_key_account
|
||||
import org.mozilla.fenix.R.string.pref_key_account_category
|
||||
import org.mozilla.fenix.R.string.pref_key_data_choices
|
||||
import org.mozilla.fenix.R.string.pref_key_feedback
|
||||
import org.mozilla.fenix.R.string.pref_key_help
|
||||
import org.mozilla.fenix.R.string.pref_key_language
|
||||
import org.mozilla.fenix.R.string.pref_key_leakcanary
|
||||
import org.mozilla.fenix.R.string.pref_key_make_default_browser
|
||||
import org.mozilla.fenix.R.string.pref_key_rate
|
||||
import org.mozilla.fenix.R.string.pref_key_remote_debugging
|
||||
import org.mozilla.fenix.R.string.pref_key_site_permissions
|
||||
import org.mozilla.fenix.R.string.pref_key_accessibility
|
||||
import org.mozilla.fenix.R.string.pref_key_language
|
||||
import org.mozilla.fenix.R.string.pref_key_data_choices
|
||||
import org.mozilla.fenix.R.string.pref_key_about
|
||||
import org.mozilla.fenix.R.string.pref_key_sign_in
|
||||
import org.mozilla.fenix.R.string.pref_key_theme
|
||||
import org.mozilla.fenix.R.string.pref_key_account
|
||||
import org.mozilla.fenix.R.string.pref_key_account_category
|
||||
import org.mozilla.fenix.R.string.pref_key_search_engine_settings
|
||||
import org.mozilla.fenix.R.string.pref_key_sign_in
|
||||
import org.mozilla.fenix.R.string.pref_key_site_permissions
|
||||
import org.mozilla.fenix.R.string.pref_key_theme
|
||||
import org.mozilla.fenix.R.string.pref_key_tracking_protection_settings
|
||||
import org.mozilla.fenix.components.metrics.Event
|
||||
import org.mozilla.fenix.ext.components
|
||||
import org.mozilla.fenix.ext.getPreferenceKey
|
||||
import org.mozilla.fenix.ext.requireComponents
|
||||
import org.mozilla.fenix.utils.ItsNotBrokenSnack
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
@SuppressWarnings("TooManyFunctions")
|
||||
class SettingsFragment : PreferenceFragmentCompat(), CoroutineScope, AccountObserver {
|
||||
|
@ -207,18 +207,18 @@ class SettingsFragment : PreferenceFragmentCompat(), CoroutineScope, AccountObse
|
|||
getClickListenerForMakeDefaultBrowser()
|
||||
|
||||
if (!Config.channel.isReleased) {
|
||||
preferenceLeakCanary?.onPreferenceChangeListener =
|
||||
Preference.OnPreferenceChangeListener { _, newValue ->
|
||||
(context?.applicationContext as FenixApplication).toggleLeakCanary(newValue as Boolean)
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
preferenceRemoteDebugging?.onPreferenceChangeListener =
|
||||
Preference.OnPreferenceChangeListener { _, newValue ->
|
||||
requireComponents.core.engine.settings.remoteDebuggingEnabled = newValue as Boolean
|
||||
preferenceLeakCanary?.setOnPreferenceChangeListener { _, newValue ->
|
||||
(context?.applicationContext as FenixApplication).toggleLeakCanary(newValue as Boolean)
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
preferenceRemoteDebugging?.setOnPreferenceChangeListener { preference, newValue ->
|
||||
org.mozilla.fenix.utils.Settings.getInstance(preference.context).preferences.edit()
|
||||
.putBoolean(preference.key, newValue as Boolean).apply()
|
||||
requireComponents.core.engine.settings.remoteDebuggingEnabled = newValue
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
private val defaultClickListener = OnPreferenceClickListener { preference ->
|
||||
|
|
Loading…
Reference in New Issue