1
0
Fork 0

Only use Context.settings() function (not getter) (#5335)

Remove unused String extensions
master
Tiger Oakes 2019-09-24 10:33:46 -07:00 committed by Sawyer Blatz
parent 10ed7e5177
commit 8c30200ced
41 changed files with 86 additions and 90 deletions

View File

@ -31,7 +31,7 @@ class AppRequestInterceptor(private val context: Context) : RequestInterceptor {
private fun adjustTrackingProtection(host: String, context: Context, session: EngineSession) {
val trackingProtectionException = ExceptionDomains(context).load().contains(host)
val trackingProtectionEnabled = context.settings.shouldUseTrackingProtection
val trackingProtectionEnabled = context.settings().shouldUseTrackingProtection
if (trackingProtectionException || !trackingProtectionEnabled) {
session.disableTrackingProtection()
} else {

View File

@ -80,7 +80,7 @@ open class FenixApplication : Application() {
experimentLoader = loadExperiments()
// Enable the service-experiments component
if (this.settings.isExperimentationEnabled) {
if (settings().isExperimentationEnabled) {
Experiments.initialize(
applicationContext,
mozilla.components.service.experiments.Configuration(
@ -100,7 +100,7 @@ open class FenixApplication : Application() {
}
setupLeakCanary()
if (this.settings.isTelemetryEnabled) {
if (settings().isTelemetryEnabled) {
components.analytics.metrics.start()
}
@ -234,7 +234,7 @@ open class FenixApplication : Application() {
@SuppressLint("WrongConstant")
// Suppressing erroneous lint warning about using MODE_NIGHT_AUTO_BATTERY, a likely library bug
private fun setDayNightTheme() {
val settings = this.settings
val settings = this.settings()
when {
settings.shouldUseLightTheme -> {
AppCompatDelegate.setDefaultNightMode(

View File

@ -95,7 +95,7 @@ open class HomeActivity : AppCompatActivity(), ShareFragment.TabsSharedCallback
setupToolbarAndNavigation()
if (settings.isTelemetryEnabled) {
if (settings().isTelemetryEnabled) {
lifecycle.addObserver(BreadcrumbsRecorder(components.analytics.crashReporter,
navHost.navController, ::getBreadcrumbMessage))
@ -178,7 +178,7 @@ open class HomeActivity : AppCompatActivity(), ShareFragment.TabsSharedCallback
intent?.toSafeIntent()?.let {
if (it.hasExtra(PRIVATE_BROWSING_MODE)) {
val startPrivateMode = it.getBooleanExtra(PRIVATE_BROWSING_MODE, false)
settings.usePrivateMode = startPrivateMode
settings().usePrivateMode = startPrivateMode
intent.removeExtra(PRIVATE_BROWSING_MODE)
}
}
@ -301,7 +301,7 @@ open class HomeActivity : AppCompatActivity(), ShareFragment.TabsSharedCallback
}
protected open fun createBrowsingModeManager(): BrowsingModeManager {
return DefaultBrowsingModeManager(settings) { mode ->
return DefaultBrowsingModeManager(settings()) { mode ->
themeManager.currentTheme = mode
}
}

View File

@ -532,7 +532,7 @@ abstract class BaseBrowserFragment : Fragment(), BackHandler, SessionManager.Obs
* Updates the site permissions rules based on user settings.
*/
private fun assignSitePermissionsRules() {
val settings = requireContext().settings
val settings = requireContext().settings()
val rules: SitePermissionsRules = settings.getSitePermissionsCustomSettingsRules()

View File

@ -395,12 +395,12 @@ class BrowserFragment : BaseBrowserFragment(), BackHandler {
val yOffset = -containerHeight - (browserToolbarView.view.height / THREE * 2)
trackingOnboarding.showAsDropDown(tpIcon, xOffset, yOffset)
it.settings.incrementTrackingProtectionOnboardingCount()
it.settings().incrementTrackingProtectionOnboardingCount()
}
}
private fun shouldShowTrackingProtectionOnboarding(session: Session) =
context?.settings?.shouldShowTrackingProtectionOnboarding ?: false &&
context?.settings()?.shouldShowTrackingProtectionOnboarding ?: false &&
session.trackerBlockingEnabled && session.trackersBlocked.isNotEmpty()
companion object {

View File

@ -81,7 +81,7 @@ class Analytics(
LeanplumMetricsService(context as Application),
AdjustMetricsService(context)
),
isTelemetryEnabled = { context.settings.isTelemetryEnabled }
isTelemetryEnabled = { context.settings().isTelemetryEnabled }
)
}
}

View File

@ -158,7 +158,7 @@ class BackgroundServices(
setOf("https://identity.mozilla.com/apps/oldsync")
).also { accountManager ->
// TODO this needs to change once we have a SyncManager
context.settings.fxaHasSyncedItems = syncConfig?.supportedEngines?.isNotEmpty() ?: false
context.settings().fxaHasSyncedItems = syncConfig?.supportedEngines?.isNotEmpty() ?: false
accountManager.registerForDeviceEvents(deviceEventObserver, ProcessLifecycleOwner.get(), false)
// Register a telemetry account observer to keep track of FxA auth metrics.
@ -244,13 +244,13 @@ class TelemetryAccountObserver(
metricController.track(Event.SyncAuthOtherExternal)
}
// Used by Leanplum as a context variable.
context.settings.fxaSignedIn = true
context.settings().fxaSignedIn = true
}
override fun onLoggedOut() {
metricController.track(Event.SyncAuthSignOut)
// Used by Leanplum as a context variable.
context.settings.fxaSignedIn = false
context.settings().fxaSignedIn = false
}
}

View File

@ -50,15 +50,15 @@ class Core(private val context: Context) {
val engine: Engine by lazy {
val defaultSettings = DefaultSettings(
requestInterceptor = AppRequestInterceptor(context),
remoteDebuggingEnabled = context.settings.isRemoteDebuggingEnabled,
remoteDebuggingEnabled = context.settings().isRemoteDebuggingEnabled,
testingModeEnabled = false,
trackingProtectionPolicy = createTrackingProtectionPolicy(),
historyTrackingDelegate = HistoryDelegate(historyStorage),
preferredColorScheme = getPreferredColorScheme(),
automaticFontSizeAdjustment = context.settings.shouldUseAutoSize,
fontInflationEnabled = context.settings.shouldUseAutoSize,
automaticFontSizeAdjustment = context.settings().shouldUseAutoSize,
fontInflationEnabled = context.settings().shouldUseAutoSize,
suspendMediaWhenInactive = !FeatureFlags.mediaIntegration,
allowAutoplayMedia = context.settings.isAutoPlayEnabled
allowAutoplayMedia = context.settings().isAutoPlayEnabled
)
GeckoEngine(context, defaultSettings, GeckoProvider.getOrCreateRuntime(context)).also {
@ -162,11 +162,11 @@ class Core(private val context: Context) {
* @return the constructed tracking protection policy based on preferences.
*/
fun createTrackingProtectionPolicy(
normalMode: Boolean = context.settings.shouldUseTrackingProtection,
normalMode: Boolean = context.settings().shouldUseTrackingProtection,
privateMode: Boolean = true
): TrackingProtectionPolicy {
val trackingProtectionPolicy =
if (context.settings.useStrictTrackingProtection) TrackingProtectionPolicy.strict() else
if (context.settings().useStrictTrackingProtection) TrackingProtectionPolicy.strict() else
TrackingProtectionPolicy.recommended()
return when {
@ -185,8 +185,8 @@ class Core(private val context: Context) {
(context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) ==
Configuration.UI_MODE_NIGHT_YES
return when {
context.settings.shouldUseDarkTheme -> PreferredColorScheme.Dark
context.settings.shouldUseLightTheme -> PreferredColorScheme.Light
context.settings().shouldUseDarkTheme -> PreferredColorScheme.Dark
context.settings().shouldUseLightTheme -> PreferredColorScheme.Light
inDark -> PreferredColorScheme.Dark
else -> PreferredColorScheme.Light
}

View File

@ -33,7 +33,7 @@ class Search(private val context: Context) {
GlobalScope.launch {
defaultSearchEngine = getDefaultSearchEngineAsync(
context,
context.settings.defaultSearchEngineName
context.settings().defaultSearchEngineName
)
}
}

View File

@ -77,9 +77,9 @@ class LeanplumMetricsService(private val application: Application) : MetricsServ
"fennec_installed" to installedApps.contains(MozillaProductDetector.MozillaProducts.FIREFOX.productName),
"focus_installed" to installedApps.contains(MozillaProductDetector.MozillaProducts.FOCUS.productName),
"klar_installed" to installedApps.contains(MozillaProductDetector.MozillaProducts.KLAR.productName),
"fxa_signed_in" to application.settings.fxaSignedIn,
"fxa_has_synced_items" to application.settings.fxaHasSyncedItems,
"search_widget_installed" to application.settings.searchWidgetInstalled
"fxa_signed_in" to application.settings().fxaSignedIn,
"fxa_has_synced_items" to application.settings().fxaHasSyncedItems,
"search_widget_installed" to application.settings().searchWidgetInstalled
))
}
@ -108,7 +108,7 @@ class LeanplumMetricsService(private val application: Application) : MetricsServ
}
override fun shouldTrack(event: Event): Boolean {
return application.settings.isTelemetryEnabled &&
return application.settings().isTelemetryEnabled &&
token.type != Token.Type.Invalid && !event.name.isNullOrEmpty()
}

View File

@ -66,9 +66,9 @@ class ToolbarIntegration(
val lottieDrawable = LottieDrawable()
lottieDrawable.composition = result
toolbar.displayTrackingProtectionIcon =
context.settings.shouldUseTrackingProtection && FeatureFlags.etpCategories
context.settings().shouldUseTrackingProtection && FeatureFlags.etpCategories
toolbar.displaySeparatorView =
context.settings.shouldUseTrackingProtection && FeatureFlags.etpCategories
context.settings().shouldUseTrackingProtection && FeatureFlags.etpCategories
toolbar.setTrackingProtectionIcons(
iconOnNoTrackersBlocked = AppCompatResources.getDrawable(
@ -120,7 +120,7 @@ class ToolbarIntegration(
ToolbarAutocompleteFeature(toolbar).apply {
addDomainProvider(domainAutocompleteProvider)
if (context.settings.shouldShowHistorySuggestions) {
if (context.settings().shouldShowHistorySuggestions) {
addHistoryStorageProvider(historyStorage)
}
}

View File

@ -42,7 +42,7 @@ class CrashReporterFragment : Fragment() {
session = requireComponents.core.sessionManager.selectedSession,
navController = findNavController(),
components = requireComponents,
settings = requireContext().settings
settings = requireContext().settings()
)
restoreTabButton.setOnClickListener {

View File

@ -64,7 +64,7 @@ class CustomTabsIntegration(
val lottieDrawable = LottieDrawable()
lottieDrawable.composition = result
toolbar.displayTrackingProtectionIcon =
activity.settings.shouldUseTrackingProtection && FeatureFlags.etpCategories
activity.settings().shouldUseTrackingProtection && FeatureFlags.etpCategories
toolbar.displaySeparatorView = false
toolbar.setTrackingProtectionIcons(

View File

@ -10,6 +10,9 @@ import android.view.WindowManager
/**
* Attempts to call immersive mode using the View to hide the status bar and navigation buttons.
*
* We don't use the equivalent function from Android Components because the stable flag messes
* with the toolbar. See #1998 and #3272.
*/
fun Activity.enterToImmersiveMode() {
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)

View File

@ -27,9 +27,9 @@ import org.mozilla.fenix.BuildConfig
import org.mozilla.fenix.Config
import org.mozilla.fenix.FenixApplication
import org.mozilla.fenix.R
import org.mozilla.fenix.theme.ThemeManager
import org.mozilla.fenix.components.Components
import org.mozilla.fenix.components.metrics.MetricController
import org.mozilla.fenix.theme.ThemeManager
import org.mozilla.fenix.utils.Settings
/**
@ -111,6 +111,3 @@ fun Context.getColorFromAttr(@AttrRes attr: Int) =
fun Context.settings(isCrashReportEnabledInBuild: Boolean = BuildConfig.CRASH_REPORTING && Config.channel.isReleased) =
Settings.getInstance(this, isCrashReportEnabledInBuild)
val Context.settings: Settings
get() = Settings.getInstance(this)

View File

@ -26,11 +26,11 @@ fun Resources.getSpannable(@StringRes id: Int, spanParts: List<Pair<Any, Iterabl
return resultCreator.toSpannableString()
}
@Suppress("Deprecation")
private fun getLocale(configuration: Configuration) =
if (SDK_INT >= Build.VERSION_CODES.N) {
configuration.locales[0]
} else {
@Suppress("Deprecation")
configuration.locale
}
@ -51,11 +51,11 @@ class SpannableStringCreator {
length += newText.length
}
fun toSpannableString() = SpannableString((parts.joinToString(""))).apply {
fun toSpannableString() = SpannableString(parts.joinToString("")).apply {
spanMap.forEach { entry ->
val range = entry.key
entry.value.forEach {
setSpan(it, range.start, range.endInclusive, SPAN_EXCLUSIVE_EXCLUSIVE)
setSpan(it, range.first, range.last, SPAN_EXCLUSIVE_EXCLUSIVE)
}
}
}

View File

@ -229,7 +229,7 @@ class HomeFragment : Fragment() {
val searchEngine = requireComponents.search.searchEngineManager.getDefaultSearchEngineAsync(
requireContext(),
requireContext().settings.defaultSearchEngineName
requireContext().settings().defaultSearchEngineName
)
val searchIcon = BitmapDrawable(resources, searchEngine.icon)
searchIcon.setBounds(0, 0, iconSize, iconSize)
@ -269,7 +269,7 @@ class HomeFragment : Fragment() {
invokePendingDeleteJobs()
if (newMode == BrowsingMode.Private) {
requireContext().settings.incrementNumTimesPrivateModeOpened()
requireContext().settings().incrementNumTimesPrivateModeOpened()
}
if (onboarding.userHasBeenOnboarded()) {
@ -325,7 +325,6 @@ class HomeFragment : Fragment() {
}
}
}, owner = this)
if (context.settings().showPrivateModeContextualFeatureRecommender &&
browsingModeManager.mode.isPrivate) {
recommendPrivateBrowsingShortcut()

View File

@ -68,7 +68,7 @@ class OnboardingThemePickerViewHolder(view: View) : RecyclerView.ViewHolder(view
}
}
with(view.context.settings) {
with(view.context.settings()) {
val radio = when {
this.shouldUseLightTheme -> radioLightTheme
this.shouldUseDarkTheme -> radioDarkTheme

View File

@ -23,7 +23,7 @@ class OnboardingTrackingProtectionViewHolder(view: View) : RecyclerView.ViewHold
)
view.tracking_protection_toggle.apply {
isChecked = view.context.settings.shouldUseTrackingProtection
isChecked = view.context.settings().shouldUseTrackingProtection
setOnCheckedChangeListener { _, isChecked ->
updateTrackingProtectionSetting(isChecked)
}
@ -31,7 +31,7 @@ class OnboardingTrackingProtectionViewHolder(view: View) : RecyclerView.ViewHold
}
private fun updateTrackingProtectionSetting(enabled: Boolean) {
itemView.context.settings.shouldUseTrackingProtection = enabled
itemView.context.settings().shouldUseTrackingProtection = enabled
with(itemView.context.components) {
val policy = core.createTrackingProtectionPolicy(enabled)
useCases.settingsUseCases.updateTrackingProtection.invoke(policy)

View File

@ -45,7 +45,7 @@ class OnboardingRadioButton(context: Context, attrs: AttributeSet) : AppCompatRa
private fun updateRadioValue(isChecked: Boolean) {
this.isChecked = isChecked
context.settings.preferences.edit {
context.settings().preferences.edit {
putBoolean(context.getString(key), isChecked)
}
}

View File

@ -64,7 +64,7 @@ class QuickActionSheet @JvmOverloads constructor(
}
fun bounceSheet() {
context.settings.incrementAutomaticBounceQuickActionSheetCount()
context.settings().incrementAutomaticBounceQuickActionSheetCount()
scope.launch(Dispatchers.Main) {
delay(BOUNCE_ANIMATION_DELAY_LENGTH)
quickActionSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED

View File

@ -130,7 +130,7 @@ class QuickActionSheetView(
}
)
if (quickActionSheetState.bounceNeeded && view.context.settings.shouldAutoBounceQuickActionSheet) {
if (quickActionSheetState.bounceNeeded && view.context.settings().shouldAutoBounceQuickActionSheet) {
quickActionSheet.bounceSheet()
}
@ -140,7 +140,7 @@ class QuickActionSheetView(
}
private fun notifyReaderModeButton(readable: Boolean) {
val settings = view.context.settings.preferences
val settings = view.context.settings().preferences
val shouldNotifyKey = view.context.getString(R.string.pref_key_reader_mode_notification)
@DrawableRes

View File

@ -96,10 +96,10 @@ class SearchFragment : Fragment(), BackHandler {
showShortcutEnginePicker = displayShortcutEnginePicker,
searchEngineSource = currentSearchEngine,
defaultEngineSource = currentSearchEngine,
showSearchSuggestions = requireContext().settings.shouldShowSearchSuggestions,
showClipboardSuggestions = requireContext().settings.shouldShowClipboardSuggestions,
showHistorySuggestions = requireContext().settings.shouldShowHistorySuggestions,
showBookmarkSuggestions = requireContext().settings.shouldShowBookmarkSuggestions,
showSearchSuggestions = requireContext().settings().shouldShowSearchSuggestions,
showClipboardSuggestions = requireContext().settings().shouldShowClipboardSuggestions,
showHistorySuggestions = requireContext().settings().shouldShowHistorySuggestions,
showBookmarkSuggestions = requireContext().settings().shouldShowBookmarkSuggestions,
session = session,
pastedText = pastedText
)
@ -230,7 +230,7 @@ class SearchFragment : Fragment(), BackHandler {
val currentDefaultEngine =
requireComponents.search.searchEngineManager.getDefaultSearchEngine(
requireContext(),
requireContext().settings.defaultSearchEngineName
requireContext().settings().defaultSearchEngineName
)
if (searchStore.state.defaultEngineSource.searchEngine != currentDefaultEngine) {
@ -322,7 +322,7 @@ class SearchFragment : Fragment(), BackHandler {
}
private fun historyStorageProvider(): HistoryStorage? {
return if (requireContext().settings.shouldShowHistorySuggestions) {
return if (requireContext().settings().shouldShowHistorySuggestions) {
requireComponents.core.historyStorage
} else null
}

View File

@ -29,7 +29,7 @@ class AccessibilityFragment : PreferenceFragmentCompat() {
getPreferenceKey(R.string.pref_key_accessibility_font_scale)
)
textSizePreference?.setOnPreferenceChangeListener<Int> { preference, newTextSize ->
val settings = preference.context.settings
val settings = preference.context.settings()
val components = preference.context.components
// Value is mapped from 0->30 in steps of 1 so let's convert to float in range 0.5->2.0
@ -43,12 +43,12 @@ class AccessibilityFragment : PreferenceFragmentCompat() {
components.useCases.sessionUseCases.reload()
true
}
textSizePreference?.isVisible = !requireContext().settings.shouldUseAutoSize
textSizePreference?.isVisible = !requireContext().settings().shouldUseAutoSize
val useAutoSizePreference =
findPreference<SwitchPreference>(getPreferenceKey(R.string.pref_key_accessibility_auto_size))
useAutoSizePreference?.setOnPreferenceChangeListener<Boolean> { preference, useAutoSize ->
val settings = preference.context.settings
val settings = preference.context.settings()
val components = preference.context.components
// Save the new setting value

View File

@ -23,7 +23,7 @@ class DataChoicesFragment : PreferenceFragmentCompat() {
SharedPreferences.OnSharedPreferenceChangeListener { sharedPreferences, key ->
when (key) {
getPreferenceKey(R.string.pref_key_telemetry) -> {
if (sharedPreferences.getBoolean(key, requireContext().settings.isTelemetryEnabled)) {
if (sharedPreferences.getBoolean(key, requireContext().settings().isTelemetryEnabled)) {
context?.components?.analytics?.metrics?.start()
} else {
context?.components?.analytics?.metrics?.stop()
@ -56,7 +56,7 @@ class DataChoicesFragment : PreferenceFragmentCompat() {
setPreferencesFromResource(R.xml.data_choices_preferences, rootKey)
findPreference<SwitchPreference>(getPreferenceKey(R.string.pref_key_telemetry))?.apply {
isChecked = context.settings.isTelemetryEnabled
isChecked = context.settings().isTelemetryEnabled
val appName = context.getString(R.string.app_name)
summary = context.getString(R.string.preferences_usage_data_description, appName)
@ -65,7 +65,7 @@ class DataChoicesFragment : PreferenceFragmentCompat() {
}
findPreference<SwitchPreference>(getPreferenceKey(R.string.pref_key_experimentation))?.apply {
isChecked = context.settings.isExperimentationEnabled
isChecked = context.settings().isExperimentationEnabled
onPreferenceChangeListener = SharedPreferenceUpdater()
}
}

View File

@ -95,13 +95,13 @@ open class RadioButtonPreference @JvmOverloads constructor(
private fun updateRadioValue(isChecked: Boolean) {
persistBoolean(isChecked)
radioButton?.isChecked = isChecked
context.settings.preferences.edit().putBoolean(key, isChecked)
context.settings().preferences.edit().putBoolean(key, isChecked)
.apply()
}
private fun bindRadioButton(holder: PreferenceViewHolder) {
radioButton = holder.findViewById(R.id.radio_button) as RadioButton
radioButton?.isChecked = context.settings.preferences.getBoolean(key, defaultValue)
radioButton?.isChecked = context.settings().preferences.getBoolean(key, defaultValue)
radioButton?.setStartCheckedIndicator()
}

View File

@ -131,7 +131,7 @@ class SettingsFragment : PreferenceFragmentCompat(), AccountObserver {
val trackingProtectionPreference =
findPreference<Preference>(getPreferenceKey(R.string.pref_key_tracking_protection_settings))
trackingProtectionPreference?.summary = context?.let {
if (it.settings.shouldUseTrackingProtection) {
if (it.settings().shouldUseTrackingProtection) {
getString(R.string.tracking_protection_on)
} else {
getString(R.string.tracking_protection_off)
@ -140,9 +140,7 @@ class SettingsFragment : PreferenceFragmentCompat(), AccountObserver {
val themesPreference =
findPreference<Preference>(getPreferenceKey(R.string.pref_key_theme))
themesPreference?.summary = context?.let {
it.settings.themeSettingString
}
themesPreference?.summary = context?.settings()?.themeSettingString
val aboutPreference = findPreference<Preference>(getPreferenceKey(R.string.pref_key_about))
val appName = getString(R.string.app_name)
@ -263,7 +261,7 @@ class SettingsFragment : PreferenceFragmentCompat(), AccountObserver {
val preferenceAlwaysOpenInPrivateMode = findPreference<SwitchPreference>(preferenceAlwaysOpenInPrivateModeKey)
preferenceAlwaysOpenInPrivateMode?.setOnPreferenceClickListener {
requireContext().settings.alwaysOpenInPrivateMode = !requireContext().settings.alwaysOpenInPrivateMode
requireContext().settings().alwaysOpenInPrivateMode = !requireContext().settings().alwaysOpenInPrivateMode
true
}
@ -278,7 +276,7 @@ class SettingsFragment : PreferenceFragmentCompat(), AccountObserver {
}
preferenceRemoteDebugging?.setOnPreferenceChangeListener { preference, newValue ->
preference.context.settings.preferences.edit()
preference.context.settings().preferences.edit()
.putBoolean(preference.key, newValue as Boolean).apply()
requireComponents.core.engine.settings.remoteDebuggingEnabled = newValue
true

View File

@ -12,7 +12,7 @@ open class SharedPreferenceUpdater : Preference.OnPreferenceChangeListener {
override fun onPreferenceChange(preference: Preference, newValue: Any?): Boolean {
val newBooleanValue = newValue as? Boolean ?: return false
preference.context.settings.preferences.edit {
preference.context.settings().preferences.edit {
putBoolean(preference.key, newBooleanValue)
}
return true

View File

@ -49,9 +49,9 @@ class TrackingProtectionFragment : PreferenceFragmentCompat() {
val trackingProtectionKey = getPreferenceKey(R.string.pref_key_tracking_protection)
val preferenceTP = findPreference<SwitchPreference>(trackingProtectionKey)
preferenceTP?.isChecked = context!!.settings.shouldUseTrackingProtection
preferenceTP?.isChecked = requireContext().settings().shouldUseTrackingProtection
preferenceTP?.setOnPreferenceChangeListener<Boolean> { preference, trackingProtectionOn ->
preference.context.settings.shouldUseTrackingProtection =
preference.context.settings().shouldUseTrackingProtection =
trackingProtectionOn
with(preference.context.components) {
val policy = core.createTrackingProtectionPolicy(trackingProtectionOn)

View File

@ -46,7 +46,7 @@ class QuickSettingsComponent(
): SitePermissions {
return if (sitePermissions == null) {
val settings = context.settings
val settings = context.settings()
val origin = requireNotNull(url.toUri().host)
var location =
settings.getSitePermissionsPhoneFeatureAction(PhoneFeature.LOCATION).toStatus()

View File

@ -46,7 +46,7 @@ class QuickSettingsUIView(
) {
private val blockedByAndroidPhoneFeatures = mutableListOf<PhoneFeature>()
private inline val context get() = view.context
private val settings: Settings = context.settings
private val settings: Settings = context.settings()
private val trackingProtectionSettingView = TrackingProtectionSettingView(view, actionEmitter)
private val labelAndActions = mapOf(
CAMERA to findLabelActionPair(R.id.camera_icon, R.id.camera_action_label),

View File

@ -39,7 +39,7 @@ class TrackingProtectionSettingView(
fun bind(isTrackingProtectionOn: Boolean) {
trackingProtectionSettingView.visibility =
if (FeatureFlags.etpCategories) View.GONE else View.VISIBLE
val globalTPSetting = trackingProtectionSwitch.context.settings.shouldUseTrackingProtection
val globalTPSetting = trackingProtectionSwitch.context.settings().shouldUseTrackingProtection
trackingProtectionAction.isVisible = !globalTPSetting
trackingProtectionAction.setOnClickListener(this)

View File

@ -26,6 +26,6 @@ class RadioSearchEngineListPreference @JvmOverloads constructor(
override fun onSearchEngineSelected(searchEngine: SearchEngine) {
context.components.search.searchEngineManager.defaultSearchEngine = searchEngine
context.settings.defaultSearchEngineName = searchEngine.name
context.settings().defaultSearchEngineName = searchEngine.name
}
}

View File

@ -26,24 +26,24 @@ class SearchEngineFragment : PreferenceFragmentCompat() {
val searchSuggestionsPreference =
findPreference<SwitchPreference>(getPreferenceKey(R.string.pref_key_show_search_suggestions))?.apply {
isChecked = context.settings.shouldShowSearchSuggestions
isChecked = context.settings().shouldShowSearchSuggestions
}
searchSuggestionsPreference?.onPreferenceChangeListener = SharedPreferenceUpdater()
val showHistorySuggestions =
findPreference<SwitchPreference>(getPreferenceKey(R.string.pref_key_search_browsing_history))?.apply {
isChecked = context.settings.shouldShowHistorySuggestions
isChecked = context.settings().shouldShowHistorySuggestions
}
val showBookmarkSuggestions =
findPreference<SwitchPreference>(getPreferenceKey(R.string.pref_key_search_bookmarks))?.apply {
isChecked = context.settings.shouldShowBookmarkSuggestions
isChecked = context.settings().shouldShowBookmarkSuggestions
}
val showClipboardSuggestions =
findPreference<SwitchPreference>(getPreferenceKey(R.string.pref_key_show_clipboard_suggestions))?.apply {
isChecked = context.settings.shouldShowClipboardSuggestions
isChecked = context.settings().shouldShowClipboardSuggestions
}
showHistorySuggestions?.onPreferenceChangeListener = SharedPreferenceUpdater()

View File

@ -69,7 +69,7 @@ abstract class SearchEngineListPreference @JvmOverloads constructor(
val selectedSearchEngine =
context.components.search.searchEngineManager.getDefaultSearchEngine(
context,
context.settings.defaultSearchEngineName
context.settings().defaultSearchEngineName
).identifier
searchEngineGroup!!.removeAllViews()

View File

@ -55,7 +55,7 @@ class SitePermissionsFragment : PreferenceFragmentCompat() {
private fun initPhoneFeature(phoneFeature: PhoneFeature) {
val context = requireContext()
val settings = context.settings
val settings = context.settings()
val summary = phoneFeature.getActionLabel(context, settings = settings)
val preferenceKey = phoneFeature.getPreferenceKey(context)

View File

@ -38,7 +38,7 @@ class SitePermissionsManageExceptionsPhoneFeatureFragment : Fragment() {
private lateinit var radioAllow: RadioButton
private lateinit var radioBlock: RadioButton
private lateinit var blockedByAndroidView: View
val settings by lazy { requireContext().settings }
val settings by lazy { requireContext().settings() }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

View File

@ -47,7 +47,7 @@ class SitePermissionsManagePhoneFeatureFragment : Fragment() {
(activity as AppCompatActivity).title = phoneFeature.getLabel(requireContext())
(activity as AppCompatActivity).supportActionBar?.show()
settings = requireContext().settings
settings = requireContext().settings()
}
override fun onCreateView(

View File

@ -29,11 +29,11 @@ import androidx.core.graphics.drawable.toBitmap
class SearchWidgetProvider : AppWidgetProvider() {
override fun onEnabled(context: Context) {
context.settings.addSearchWidgetInstalled(1)
context.settings().addSearchWidgetInstalled(1)
}
override fun onDeleted(context: Context, appWidgetIds: IntArray) {
context.settings.addSearchWidgetInstalled(-appWidgetIds.size)
context.settings().addSearchWidgetInstalled(-appWidgetIds.size)
}
override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) {

View File

@ -35,7 +35,7 @@ class IntentReceiverActivityTest {
@Test
fun `process intent with alwaysOpenInPrivateMode set to true`() {
runBlockingTest {
testContext.settings.alwaysOpenInPrivateMode = true
testContext.settings().alwaysOpenInPrivateMode = true
val intent = Intent()
`when`(testContext.components.intentProcessors.privateIntentProcessor.process(intent)).thenReturn(true)
@ -52,7 +52,7 @@ class IntentReceiverActivityTest {
@Test
fun `process intent with alwaysOpenInPrivateMode set to false`() {
runBlockingTest {
testContext.settings.alwaysOpenInPrivateMode = false
testContext.settings().alwaysOpenInPrivateMode = false
val intent = Intent()
`when`(testContext.components.intentProcessors.intentProcessor.process(intent)).thenReturn(true)

View File

@ -32,8 +32,7 @@ class SettingsTest {
@Before
fun setUp() {
settings = testContext.settings
.apply(Settings::clear)
settings = testContext.settings().apply(Settings::clear)
}
@Test