Skip to content

Commit

Permalink
For mozilla-mobile#20919 quite the app when turning on/off experiments
Browse files Browse the repository at this point in the history
  • Loading branch information
Amejia481 committed Aug 20, 2021
1 parent d235da6 commit ab37416
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
package org.mozilla.fenix.settings.studies

import android.content.Context
import android.os.Handler
import android.os.Looper
import android.text.SpannableStringBuilder
import android.text.method.LinkMovementMethod
import android.text.style.ClickableSpan
import android.text.style.URLSpan
import android.view.View
import android.widget.TextView
import android.widget.Toast
import androidx.annotation.VisibleForTesting
import androidx.appcompat.widget.SwitchCompat
import androidx.core.text.HtmlCompat
Expand All @@ -27,6 +30,7 @@ import org.mozilla.fenix.databinding.SettingsStudiesBinding
import org.mozilla.fenix.settings.SupportUtils
import org.mozilla.fenix.settings.SupportUtils.SumoTopic.OPT_OUT_STUDIES
import org.mozilla.fenix.utils.Settings
import kotlin.system.exitProcess

@Suppress("LongParameterList")
class StudiesView(
Expand All @@ -51,6 +55,7 @@ class StudiesView(
settings.isExperimentationEnabled = isChecked
experiments.globalUserParticipation = isChecked
provideStudiesTitle().text = getSwitchTitle()
quitTheApp()
}
bindDescription()

Expand Down Expand Up @@ -130,4 +135,23 @@ class StudiesView(

@VisibleForTesting
internal fun provideStudiesList(): RecyclerView = binding.studiesList

@VisibleForTesting
internal fun quitTheApp() {
Toast.makeText(
context,
context.getString(R.string.studies_toast_quit_application),
Toast.LENGTH_LONG
).show()
Handler(Looper.getMainLooper()).postDelayed(
{
exitProcess(0)
},
OVERRIDE_EXIT_DELAY
)
}

companion object {
private const val OVERRIDE_EXIT_DELAY = 3000L
}
}
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,8 @@
<string name="studies_restart_dialog_ok">OK</string>
<!-- Dialog button text for canceling removing a study. -->
<string name="studies_restart_dialog_cancel">Cancel</string>
<!-- Toast shown after turning on/off studies preferences -->
<string name="studies_toast_quit_application">Quitting the application to apply changes…</string>

<!-- Sessions -->
<!-- Title for the list of tabs -->
Expand Down

0 comments on commit ab37416

Please sign in to comment.