@ -26,6 +26,7 @@ import androidx.navigation.findNavController
import androidx.navigation.fragment.navArgs
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreference
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.amo_collection_override_dialog.view.*
import kotlinx.coroutines.CoroutineScope
@ -92,7 +93,8 @@ class SettingsFragment : PreferenceFragmentCompat() {
scope = lifecycleScope ,
accountManager = requireComponents . backgroundServices . accountManager ,
httpClient = requireComponents . core . client ,
updateFxASyncOverrideMenu = :: updateFxASyncOverrideMenu
updateFxASyncOverrideMenu = :: updateFxASyncOverrideMenu ,
updateFxAAllowDomesticChinaServerMenu = :: updateFxAAllowDomesticChinaServerMenu
)
// Observe account changes to keep the UI up-to-date.
@ -447,6 +449,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
}
setupAmoCollectionOverridePreference ( requireContext ( ) . settings ( ) )
setupAllowDomesticChinaFxaServerPreference ( )
}
/ * *
@ -539,6 +542,22 @@ class SettingsFragment : PreferenceFragmentCompat() {
}
}
private fun updateFxAAllowDomesticChinaServerMenu ( ) {
val settings = requireContext ( ) . settings ( )
val preferenceAllowDomesticChinaServer =
findPreference < SwitchPreference > ( getPreferenceKey ( R . string . pref _key _allow _domestic _china _fxa _server ) )
// Only enable changes to these prefs when the user isn't connected to an account.
val enabled =
requireComponents . backgroundServices . accountManager . authenticatedAccount ( ) == null
val checked = settings . allowDomesticChinaFxaServer
val visible = Config . channel . isMozillaOnline
preferenceAllowDomesticChinaServer ?. apply {
isEnabled = enabled
isChecked = checked
isVisible = visible
}
}
private fun updateFxASyncOverrideMenu ( ) {
val preferenceFxAOverride =
findPreference < Preference > ( getPreferenceKey ( R . string . pref _key _override _fxa _server ) )
@ -577,6 +596,33 @@ class SettingsFragment : PreferenceFragmentCompat() {
}
}
private fun setupAllowDomesticChinaFxaServerPreference ( ) {
val allowDomesticChinaFxAServer = getPreferenceKey ( R . string . pref _key _allow _domestic _china _fxa _server )
val preferenceAllowDomesticChinaFxAServer = findPreference < SwitchPreference > ( allowDomesticChinaFxAServer )
val visible = Config . channel . isMozillaOnline
preferenceAllowDomesticChinaFxAServer ?. apply {
isVisible = visible
}
if ( visible ) {
preferenceAllowDomesticChinaFxAServer ?. onPreferenceChangeListener =
Preference . OnPreferenceChangeListener { preference , newValue ->
preference . context . settings ( ) . preferences . edit ( )
. putBoolean ( preference . key , newValue as Boolean ) . apply ( )
updateFxAAllowDomesticChinaServerMenu ( )
Toast . makeText (
context ,
getString ( R . string . toast _override _fxa _sync _server _done ) ,
Toast . LENGTH _LONG
) . show ( )
Handler ( Looper . getMainLooper ( ) ) . postDelayed ( {
exitProcess ( 0 )
} , FXA _SYNC _OVERRIDE _EXIT _DELAY )
}
}
}
companion object {
private const val REQUEST _CODE _BROWSER _ROLE = 1
private const val SCROLL _INDICATOR _DELAY = 10L