Skip to content

Commit

Permalink
For mozilla-mobile#20919 add confirm dialog when turning on/off exper…
Browse files Browse the repository at this point in the history
…iments
  • Loading branch information
Amejia481 committed Aug 24, 2021
1 parent d7e80c1 commit 5117f1c
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions app/src/main/java/org/mozilla/fenix/settings/DataChoicesFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
package org.mozilla.fenix.settings

import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.core.content.edit
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreference
import org.mozilla.fenix.R
Expand Down Expand Up @@ -44,20 +43,6 @@ class DataChoicesFragment : PreferenceFragmentCompat() {
} else {
context.components.analytics.metrics.stop(MetricServiceType.Marketing)
}
} 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
)
}
}
}
Expand Down Expand Up @@ -86,7 +71,31 @@ class DataChoicesFragment : PreferenceFragmentCompat() {

requirePreference<SwitchPreference>(R.string.pref_key_experimentation).apply {
isChecked = context.settings().isExperimentationEnabled
onPreferenceChangeListener = SharedPreferenceUpdater()

setOnPreferenceChangeListener<Boolean> { preference, enabled ->
val builder = AlertDialog.Builder(context)
.setPositiveButton(
R.string.top_sites_rename_dialog_ok
) { dialog, _ ->
context.settings().preferences.edit {
putBoolean(preference.key, enabled).commit()
}
context.components.analytics.experiments.globalUserParticipation = enabled
dialog.dismiss()
exitProcess(0)
}
.setNegativeButton(
R.string.top_sites_rename_dialog_cancel
) { dialog, _ ->
dialog.dismiss()
}
.setTitle(R.string.preference_experiments_2)
.setMessage(getQuittingAppString())
.setCancelable(false)
val alertDialog: AlertDialog = builder.create()
alertDialog.show()
false
}
}
}

Expand Down

0 comments on commit 5117f1c

Please sign in to comment.