For #20919 quite the app when turning on/off experiments

pull/393/head
Arturo Mejia 3 years ago committed by Jonathan Almeida
parent 99e4d9d95c
commit f5dbfc3071

@ -5,6 +5,9 @@
package org.mozilla.fenix.settings
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.widget.Toast
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreference
import org.mozilla.fenix.R
@ -13,6 +16,7 @@ import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.getPreferenceKey
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.ext.showToolbar
import kotlin.system.exitProcess
/**
* Lets the user toggle telemetry on/off.
@ -43,6 +47,17 @@ class DataChoicesFragment : PreferenceFragmentCompat() {
} else if (key == getPreferenceKey(R.string.pref_key_experimentation)) {
val enabled = context.settings().isExperimentationEnabled
context.components.analytics.experiments.globalUserParticipation = enabled
Toast.makeText(
context,
getQuittingAppString(),
Toast.LENGTH_LONG
).show()
Handler(Looper.getMainLooper()).postDelayed(
{
exitProcess(0)
},
OVERRIDE_EXIT_DELAY
)
}
}
}
@ -74,4 +89,22 @@ class DataChoicesFragment : PreferenceFragmentCompat() {
onPreferenceChangeListener = SharedPreferenceUpdater()
}
}
@Suppress("TooGenericExceptionCaught")
private fun getQuittingAppString(): String {
// Fix for #20919. As we are not able to get new strings on Beta and Release,
// We are using a string that it's already translated and taking some parts of it.
// To be specific "Firefox Account/Sync server modified. Quitting the application to apply changes…"
// We are interested on the phrase after the dot, that is generic and we can use for this case.
val rawString = getString(R.string.toast_override_fxa_sync_server_done)
return try {
rawString.split(".")[1]
} catch (e: ArrayIndexOutOfBoundsException) {
rawString
}
}
companion object {
private const val OVERRIDE_EXIT_DELAY = 3000L
}
}

Loading…
Cancel
Save