Skip to content
Snippets Groups Projects
Commit 16f1cf25 authored by Alex Catarineu's avatar Alex Catarineu Committed by Pier Angelo Vendrame
Browse files

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

parent 6507104e
No related branches found
No related tags found
1 merge request!1503TB 43415, part 3: Shuffle commits
Showing
with 60 additions and 4 deletions
......@@ -1364,6 +1364,15 @@ class GeckoEngine(
get() = runtime.settings.userCharacteristicPingCurrentVersion
set(value) { runtime.settings.setUserCharacteristicPingCurrentVersion(value) }
override var spoofEnglish: Boolean
get() = runtime.settings.spoofEnglish
set(value) {
value.let {
runtime.settings.spoofEnglish = it
localeUpdater.updateValue()
}
}
override var webContentIsolationStrategy: WebContentIsolationStrategy?
get() = runtime.settings.webContentIsolationStrategy?.intoWebContentIsolationStrategy()
set(value) {
......@@ -1416,6 +1425,7 @@ class GeckoEngine(
this.fdlibmMathEnabled = it.fdlibmMathEnabled
this.emailTrackerBlockingPrivateBrowsing = it.emailTrackerBlockingPrivateBrowsing
this.userCharacteristicPingCurrentVersion = it.userCharacteristicPingCurrentVersion
this.spoofEnglish = it.spoofEnglish
this.webContentIsolationStrategy = it.webContentIsolationStrategy
this.fetchPriorityEnabled = it.fetchPriorityEnabled
this.parallelMarkingEnabled = it.parallelMarkingEnabled
......
......@@ -280,6 +280,8 @@ abstract class Settings {
*/
open var userCharacteristicPingCurrentVersion: Int by UnsupportedSetting()
open var spoofEnglish: Boolean by UnsupportedSetting()
/**
* Setting to control whether the desktop user agent is used.
*/
......@@ -364,6 +366,7 @@ data class DefaultSettings(
override var queryParameterStrippingStripList: String = "",
override var emailTrackerBlockingPrivateBrowsing: Boolean = false,
override var userCharacteristicPingCurrentVersion: Int = 0,
override var spoofEnglish: Boolean = false,
override var webContentIsolationStrategy: WebContentIsolationStrategy? =
WebContentIsolationStrategy.ISOLATE_HIGH_VALUE,
override var fetchPriorityEnabled: Boolean = true,
......
......@@ -174,6 +174,7 @@ class Core(
cookieBannerHandlingGlobalRulesSubFrames = context.settings().shouldEnableCookieBannerGlobalRulesSubFrame,
emailTrackerBlockingPrivateBrowsing = false,
userCharacteristicPingCurrentVersion = FxNimbus.features.userCharacteristics.value().currentVersion,
spoofEnglish = context.settings().spoofEnglish,
getDesktopMode = {
store.state.desktopMode
},
......
......@@ -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
}
}
......@@ -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)
......
......@@ -306,6 +306,11 @@ class Settings(private val appContext: Context) : PreferencesHolder {
false,
)
var spoofEnglish by booleanPreference(
appContext.getPreferenceKey(R.string.pref_key_spoof_english),
default = false
)
var defaultSearchEngineName by stringPreference(
appContext.getPreferenceKey(R.string.pref_key_search_engine),
default = "",
......
......@@ -7,13 +7,30 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/enable_switch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|end"
android:background="?android:attr/selectableItemBackground"
android:checked="true"
android:clickable="true"
android:focusable="true"
android:layout_marginStart="54dp"
android:padding="16dp"
android:text="@string/tor_spoof_english"
android:textColor="?textPrimary"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/locale_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toBottomOf="@id/enable_switch" />
</androidx.constraintlayout.widget.ConstraintLayout>
......@@ -427,4 +427,6 @@
<string name="pref_key_noscript_installed" translatable="false">pref_key_noscript_installed</string>
<string name="pref_key_noscript_updated" translatable="false">pref_key_noscript_updated</string>
<string name="pref_key_https_everywhere_removed" translatable="false">pref_key_https_everywhere_removed</string>
<string name="pref_key_spoof_english" translatable="false">pref_key_spoof_english</string>
</resources>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment