Commit 70764ec7 authored by Alex Catarineu's avatar Alex Catarineu Committed by clairehurst
Browse files

TB 40087 [android]: Implement a switch for spoof English.

parent dfd72734
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -1331,6 +1331,15 @@ class GeckoEngine(
        override var globalPrivacyControlEnabled: Boolean
            get() = runtime.settings.globalPrivacyControl
            set(value) { runtime.settings.setGlobalPrivacyControl(value) }

        override var spoofEnglish: Boolean
            get() = runtime.settings.spoofEnglish
            set(value) {
                value.let {
                    runtime.settings.spoofEnglish = it
                    localeUpdater.updateValue()
                }
            }
    }.apply {
        defaultSettings?.let {
            this.javascriptEnabled = it.javascriptEnabled
@@ -1357,6 +1366,7 @@ class GeckoEngine(
            this.cookieBannerHandlingGlobalRulesSubFrames = it.cookieBannerHandlingGlobalRulesSubFrames
            this.globalPrivacyControlEnabled = it.globalPrivacyControlEnabled
            this.emailTrackerBlockingPrivateBrowsing = it.emailTrackerBlockingPrivateBrowsing
            this.spoofEnglish = it.spoofEnglish
        }
    }

+3 −0
Original line number Diff line number Diff line
@@ -251,6 +251,8 @@ abstract class Settings {
     * Setting to control the email tracker blocking feature in the private browsing mode.
     */
    open var emailTrackerBlockingPrivateBrowsing: Boolean by UnsupportedSetting()

    open var spoofEnglish: Boolean by UnsupportedSetting()
}

/**
@@ -301,6 +303,7 @@ data class DefaultSettings(
    override var queryParameterStrippingAllowList: String = "",
    override var queryParameterStrippingStripList: String = "",
    override var emailTrackerBlockingPrivateBrowsing: Boolean = false,
    override var spoofEnglish: Boolean = false,
) : Settings()

class UnsupportedSetting<T> {
+1 −0
Original line number Diff line number Diff line
@@ -157,6 +157,7 @@ class Core(
            cookieBannerHandlingGlobalRules = context.settings().shouldEnableCookieBannerGlobalRules,
            cookieBannerHandlingGlobalRulesSubFrames = context.settings().shouldEnableCookieBannerGlobalRulesSubFrame,
            emailTrackerBlockingPrivateBrowsing = false,
            spoofEnglish = context.settings().spoofEnglish,
        )

        GeckoEngine(
+5 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.support.locale.LocaleManager
import mozilla.components.support.locale.LocaleUseCases
import org.mozilla.fenix.nimbus.FxNimbus
import org.mozilla.fenix.ext.components
import java.util.Locale

interface LocaleSettingsController {
@@ -83,5 +84,9 @@ class DefaultLocaleSettingsController(
        config.setLocale(locale)
        config.setLayoutDirection(locale)
        resources.updateConfiguration(config, resources.displayMetrics)
        // A slightly hacky way of triggering a `runtime.settings.locales` update,
        // so that the locales are updated in GeckoView.
        val spoofEnglish = context.components.core.engine.settings.spoofEnglish
        context.components.core.engine.settings.spoofEnglish = spoofEnglish
    }
}
+14 −1
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import org.mozilla.fenix.R
import org.mozilla.fenix.components.StoreProvider
import org.mozilla.fenix.databinding.FragmentLocaleSettingsBinding
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.ext.showToolbar

class LocaleSettingsFragment : Fragment(), MenuProvider {
@@ -46,6 +48,8 @@ class LocaleSettingsFragment : Fragment(), MenuProvider {
        _binding = FragmentLocaleSettingsBinding.inflate(inflater, container, false)
        val view = binding.root

        bindEnableSwitch()

        val browserStore = requireContext().components.core.store
        val localeUseCase = LocaleUseCases(browserStore)

@@ -62,10 +66,19 @@ class LocaleSettingsFragment : Fragment(), MenuProvider {
                localeUseCase = localeUseCase,
            ),
        )
        localeView = LocaleSettingsView(binding.root, interactor)
        localeView = LocaleSettingsView(binding.localeContainer, interactor)
        return view
    }

    private fun bindEnableSwitch() {
        val switch = binding.enableSwitch
        switch.isChecked = requireComponents.core.engine.settings.spoofEnglish
        switch.setOnCheckedChangeListener { _, isChecked ->
            context?.settings()?.spoofEnglish = isChecked
            requireComponents.core.engine.settings.spoofEnglish = isChecked
        }
    }

    override fun onCreateMenu(menu: Menu, inflater: MenuInflater) {
        inflater.inflate(R.menu.languages_list, menu)
        val searchItem = menu.findItem(R.id.search)
Loading