2019-02-25 23:05:19 +01:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
package org.mozilla.fenix.settings
|
|
|
|
|
|
|
|
import android.os.Bundle
|
|
|
|
import androidx.preference.PreferenceFragmentCompat
|
2019-03-11 19:27:40 +01:00
|
|
|
import androidx.preference.SwitchPreference
|
2019-11-05 00:47:46 +01:00
|
|
|
import org.mozilla.fenix.Config
|
2019-02-25 23:05:19 +01:00
|
|
|
import org.mozilla.fenix.R
|
2019-05-01 02:27:01 +02:00
|
|
|
import org.mozilla.fenix.ext.components
|
2019-08-21 17:38:14 +02:00
|
|
|
import org.mozilla.fenix.ext.getPreferenceKey
|
2019-09-10 19:11:58 +02:00
|
|
|
import org.mozilla.fenix.ext.settings
|
2019-11-25 21:36:47 +01:00
|
|
|
import org.mozilla.fenix.ext.showToolbar
|
2019-02-25 23:05:19 +01:00
|
|
|
|
2019-08-21 17:38:14 +02:00
|
|
|
/**
|
|
|
|
* Lets the user toggle telemetry on/off.
|
|
|
|
*/
|
2019-02-25 23:05:19 +01:00
|
|
|
class DataChoicesFragment : PreferenceFragmentCompat() {
|
|
|
|
|
2019-05-01 02:27:01 +02:00
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
2019-12-08 05:25:32 +01:00
|
|
|
|
|
|
|
val context = requireContext()
|
|
|
|
preferenceManager.sharedPreferences.registerOnSharedPreferenceChangeListener(this) { sharedPreferences, key ->
|
|
|
|
if (key == getPreferenceKey(R.string.pref_key_telemetry)) {
|
|
|
|
if (sharedPreferences.getBoolean(key, context.settings().isTelemetryEnabled)) {
|
|
|
|
context.components.analytics.metrics.start()
|
|
|
|
} else {
|
|
|
|
context.components.analytics.metrics.stop()
|
|
|
|
}
|
|
|
|
}
|
2019-05-01 02:27:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-06 23:52:25 +02:00
|
|
|
override fun onResume() {
|
|
|
|
super.onResume()
|
2019-11-25 21:36:47 +01:00
|
|
|
showToolbar(getString(R.string.preferences_data_collection))
|
2019-06-06 23:52:25 +02:00
|
|
|
}
|
|
|
|
|
2019-02-25 23:05:19 +01:00
|
|
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
|
|
|
setPreferencesFromResource(R.xml.data_choices_preferences, rootKey)
|
2019-03-11 19:27:40 +01:00
|
|
|
|
2019-08-21 17:38:14 +02:00
|
|
|
findPreference<SwitchPreference>(getPreferenceKey(R.string.pref_key_telemetry))?.apply {
|
2019-09-24 19:33:46 +02:00
|
|
|
isChecked = context.settings().isTelemetryEnabled
|
2019-07-19 21:31:55 +02:00
|
|
|
|
|
|
|
val appName = context.getString(R.string.app_name)
|
|
|
|
summary = context.getString(R.string.preferences_usage_data_description, appName)
|
2019-08-21 17:38:14 +02:00
|
|
|
|
|
|
|
onPreferenceChangeListener = SharedPreferenceUpdater()
|
2019-05-19 01:35:45 +02:00
|
|
|
}
|
2019-08-27 21:56:16 +02:00
|
|
|
|
2020-02-08 02:46:51 +01:00
|
|
|
findPreference<SwitchPreference>(getPreferenceKey(R.string.pref_key_telemetry))?.apply {
|
|
|
|
isChecked = context.settings().isMarketingTelemetryEnabled
|
|
|
|
|
|
|
|
val appName = context.getString(R.string.app_name)
|
|
|
|
summary = context.getString(R.string.preferences_marketing_data_description, appName)
|
|
|
|
|
|
|
|
onPreferenceChangeListener = SharedPreferenceUpdater()
|
|
|
|
}
|
|
|
|
|
2019-08-27 21:56:16 +02:00
|
|
|
findPreference<SwitchPreference>(getPreferenceKey(R.string.pref_key_experimentation))?.apply {
|
2019-09-24 19:33:46 +02:00
|
|
|
isChecked = context.settings().isExperimentationEnabled
|
2019-11-05 00:47:46 +01:00
|
|
|
isVisible = Config.channel.isReleaseOrBeta
|
2019-08-27 21:56:16 +02:00
|
|
|
onPreferenceChangeListener = SharedPreferenceUpdater()
|
|
|
|
}
|
2019-02-25 23:05:19 +01:00
|
|
|
}
|
|
|
|
}
|