|
|
@ -5,8 +5,8 @@ package org.mozilla.fenix.utils
|
|
|
|
file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
import android.content.Context
|
|
|
|
|
|
|
|
import android.content.Context.MODE_PRIVATE
|
|
|
|
import android.content.SharedPreferences
|
|
|
|
import android.content.SharedPreferences
|
|
|
|
import android.preference.PreferenceManager
|
|
|
|
|
|
|
|
import mozilla.components.feature.sitepermissions.SitePermissionsRules
|
|
|
|
import mozilla.components.feature.sitepermissions.SitePermissionsRules
|
|
|
|
import org.mozilla.fenix.BuildConfig
|
|
|
|
import org.mozilla.fenix.BuildConfig
|
|
|
|
import org.mozilla.fenix.R
|
|
|
|
import org.mozilla.fenix.R
|
|
|
@ -21,6 +21,7 @@ class Settings private constructor(context: Context) {
|
|
|
|
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
companion object {
|
|
|
|
const val autoBounceMaximumCount = 2
|
|
|
|
const val autoBounceMaximumCount = 2
|
|
|
|
|
|
|
|
const val FENIX_PREFERENCES = "fenix_preferences"
|
|
|
|
|
|
|
|
|
|
|
|
var instance: Settings? = null
|
|
|
|
var instance: Settings? = null
|
|
|
|
|
|
|
|
|
|
|
@ -36,8 +37,15 @@ class Settings private constructor(context: Context) {
|
|
|
|
|
|
|
|
|
|
|
|
private val appContext = context.applicationContext
|
|
|
|
private val appContext = context.applicationContext
|
|
|
|
|
|
|
|
|
|
|
|
private val preferences: SharedPreferences =
|
|
|
|
val preferences: SharedPreferences =
|
|
|
|
PreferenceManager.getDefaultSharedPreferences(context)
|
|
|
|
appContext.getSharedPreferences(FENIX_PREFERENCES, MODE_PRIVATE)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val usePrivateMode: Boolean
|
|
|
|
|
|
|
|
get() = preferences.getBoolean(appContext.getPreferenceKey(R.string.pref_key_private_mode), false)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun setPrivateMode(newValue: Boolean) {
|
|
|
|
|
|
|
|
preferences.edit().putBoolean(appContext.getPreferenceKey(R.string.pref_key_private_mode), newValue).apply()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
val defaultSearchEngineName: String
|
|
|
|
val defaultSearchEngineName: String
|
|
|
|
get() = preferences.getString(appContext.getPreferenceKey(R.string.pref_key_search_engine), "") ?: ""
|
|
|
|
get() = preferences.getString(appContext.getPreferenceKey(R.string.pref_key_search_engine), "") ?: ""
|
|
|
@ -61,6 +69,13 @@ class Settings private constructor(context: Context) {
|
|
|
|
false
|
|
|
|
false
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun setLightTheme(newValue: Boolean) {
|
|
|
|
|
|
|
|
preferences.edit().putBoolean(
|
|
|
|
|
|
|
|
appContext.getPreferenceKey(R.string.pref_key_light_theme),
|
|
|
|
|
|
|
|
newValue
|
|
|
|
|
|
|
|
).apply()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
val shouldShowVisitedSitesBookmarks: Boolean
|
|
|
|
val shouldShowVisitedSitesBookmarks: Boolean
|
|
|
|
get() = preferences.getBoolean(
|
|
|
|
get() = preferences.getBoolean(
|
|
|
|
appContext.getPreferenceKey(R.string.pref_key_show_visited_sites_bookmarks),
|
|
|
|
appContext.getPreferenceKey(R.string.pref_key_show_visited_sites_bookmarks),
|
|
|
@ -79,12 +94,26 @@ class Settings private constructor(context: Context) {
|
|
|
|
false
|
|
|
|
false
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun setFollowDeviceTheme(newValue: Boolean) {
|
|
|
|
|
|
|
|
preferences.edit().putBoolean(
|
|
|
|
|
|
|
|
appContext.getPreferenceKey(R.string.pref_key_follow_device_theme),
|
|
|
|
|
|
|
|
newValue
|
|
|
|
|
|
|
|
).apply()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
val shouldUseTrackingProtection: Boolean
|
|
|
|
val shouldUseTrackingProtection: Boolean
|
|
|
|
get() = preferences.getBoolean(
|
|
|
|
get() = preferences.getBoolean(
|
|
|
|
appContext.getPreferenceKey(R.string.pref_key_tracking_protection),
|
|
|
|
appContext.getPreferenceKey(R.string.pref_key_tracking_protection),
|
|
|
|
true
|
|
|
|
true
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun setTrackingProtection(newValue: Boolean) {
|
|
|
|
|
|
|
|
preferences.edit().putBoolean(
|
|
|
|
|
|
|
|
appContext.getPreferenceKey(R.string.pref_key_tracking_protection),
|
|
|
|
|
|
|
|
newValue
|
|
|
|
|
|
|
|
).apply()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
val shouldUseAutoBatteryTheme: Boolean
|
|
|
|
val shouldUseAutoBatteryTheme: Boolean
|
|
|
|
get() = preferences.getBoolean(
|
|
|
|
get() = preferences.getBoolean(
|
|
|
|
appContext.getPreferenceKey(R.string.pref_key_auto_battery_theme),
|
|
|
|
appContext.getPreferenceKey(R.string.pref_key_auto_battery_theme),
|
|
|
@ -107,8 +136,10 @@ class Settings private constructor(context: Context) {
|
|
|
|
get() = (preferences.getInt(appContext.getPreferenceKey(R.string.pref_key_bounce_quick_action), 0))
|
|
|
|
get() = (preferences.getInt(appContext.getPreferenceKey(R.string.pref_key_bounce_quick_action), 0))
|
|
|
|
|
|
|
|
|
|
|
|
fun incrementAutomaticBounceQuickActionSheetCount() {
|
|
|
|
fun incrementAutomaticBounceQuickActionSheetCount() {
|
|
|
|
preferences.edit().putInt(appContext.getPreferenceKey(R.string.pref_key_bounce_quick_action),
|
|
|
|
preferences.edit().putInt(
|
|
|
|
autoBounceQuickActionSheetCount + 1).apply()
|
|
|
|
appContext.getPreferenceKey(R.string.pref_key_bounce_quick_action),
|
|
|
|
|
|
|
|
autoBounceQuickActionSheetCount + 1
|
|
|
|
|
|
|
|
).apply()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fun setDefaultSearchEngineByName(name: String) {
|
|
|
|
fun setDefaultSearchEngineByName(name: String) {
|
|
|
|