[fenix] Lint fixes

pull/600/head
Marc Leclair 2 years ago committed by mergify[bot]
parent 57b2f43a55
commit 6294425de6

@ -65,15 +65,20 @@ class ProfilerStopDialogFragment : DialogFragment() {
private fun StopProfilerCard() { private fun StopProfilerCard() {
val viewStateObserver = remember { mutableStateOf(CardState.UrlWarningState) } val viewStateObserver = remember { mutableStateOf(CardState.UrlWarningState) }
Dialog(onDismissRequest = { Dialog(
// In the waiting state, we do not want the users to be able to click away from the dialogue onDismissRequest = {
// since the user needs to wait for the profiler data to be ready and we don't want to handle // In the waiting state, we do not want the users to be able to click away from the dialogue
// the process in the background. // since the user needs to wait for the profiler data to be ready and we don't want to handle
if (viewStateObserver.value != CardState.WaitForProfilerState) { // the process in the background.
profilerViewModel.setProfilerState(requireContext().components.core.engine.profiler!!.isProfilerActive()) if (viewStateObserver.value != CardState.WaitForProfilerState) {
this@ProfilerStopDialogFragment.dismiss() profilerViewModel.setProfilerState(
requireContext()
.components.core.engine.profiler!!.isProfilerActive()
)
this@ProfilerStopDialogFragment.dismiss()
}
} }
}) { ) {
when (viewStateObserver.value) { when (viewStateObserver.value) {
CardState.UrlWarningState -> { CardState.UrlWarningState -> {
UrlWarningCard(viewStateObserver) UrlWarningCard(viewStateObserver)
@ -111,7 +116,7 @@ class ProfilerStopDialogFragment : DialogFragment() {
) { ) {
TextButton( TextButton(
onClick = { onClick = {
displayToastAndDismiss(R.string.profile_stop_dialogue_cancel_save) displayToastAndDismiss(R.string.profile_stop_dialogue_cancel_save)
} }
) { ) {
Text(stringResource(R.string.profiler_start_cancel)) Text(stringResource(R.string.profiler_start_cancel))

@ -14,14 +14,9 @@ import mozilla.components.concept.fetch.Response
import org.json.JSONObject import org.json.JSONObject
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.components
import java.io.BufferedReader
import java.io.ByteArrayInputStream
import java.io.File import java.io.File
import java.io.FileNotFoundException
import java.io.FileOutputStream import java.io.FileOutputStream
import java.io.IOException import java.io.IOException
import java.io.InputStreamReader
import java.util.zip.GZIPInputStream
private const val PROFILER_API = "https://api.profiler.firefox.com/compressed-store" private const val PROFILER_API = "https://api.profiler.firefox.com/compressed-store"
private const val PROFILER_SERVER_HEADER = "application/vnd.firefox-profiler+json;version=1.0" private const val PROFILER_SERVER_HEADER = "application/vnd.firefox-profiler+json;version=1.0"
@ -80,7 +75,7 @@ enum class ProfilerSettings(val threads: Array<String>, val features: Array<Stri
object ProfilerUtils { object ProfilerUtils {
private fun saveProfileUrlToClipboardAndToast(profileResult: ByteArray, context: Context): String { private fun saveProfileUrlToClipboardAndToast(profileResult: ByteArray, context: Context): String {
//The profile is saved to a temporary file since our fetch API takes a file or a string. // The profile is saved to a temporary file since our fetch API takes a file or a string.
// Converting the ByteArray to a String would hurt the encoding, which we need to preserve. // Converting the ByteArray to a String would hurt the encoding, which we need to preserve.
val outputFile = createTemporaryFile(profileResult, context) val outputFile = createTemporaryFile(profileResult, context)
val response = networkCallToProfilerServer(outputFile, context) val response = networkCallToProfilerServer(outputFile, context)

@ -8,14 +8,23 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
/**
* [ViewModel] to keep track of the profiler state
*/
class ProfilerViewModel : ViewModel() { class ProfilerViewModel : ViewModel() {
var isProfilerActive : MutableLiveData<Boolean> = MutableLiveData() var isProfilerActive: MutableLiveData<Boolean> = MutableLiveData()
/**
* @return profiler status
*/
fun getProfilerState(): LiveData<Boolean> { fun getProfilerState(): LiveData<Boolean> {
return isProfilerActive return isProfilerActive
} }
fun setProfilerState(isActive: Boolean){ /**
* @param isActive whether the profiler is active or not
*/
fun setProfilerState(isActive: Boolean) {
isProfilerActive.value = isActive isProfilerActive.value = isActive
} }
} }

@ -151,9 +151,12 @@ class SettingsFragment : PreferenceFragmentCompat() {
} }
} }
profilerViewModel.getProfilerState().observe(this, Observer<Boolean>{ profilerViewModel.getProfilerState().observe(
updateProfilerUI(it) this,
}) Observer<Boolean> {
updateProfilerUI(it)
}
)
} }
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
@ -497,7 +500,8 @@ class SettingsFragment : PreferenceFragmentCompat() {
findPreference<Preference>( findPreference<Preference>(
getPreferenceKey(R.string.pref_key_secret_debug_info) getPreferenceKey(R.string.pref_key_secret_debug_info)
)?.isVisible = showSecretDebugMenuThisSession )?.isVisible = showSecretDebugMenuThisSession
preferenceStartProfiler?.isVisible = showSecretDebugMenuThisSession && (requireContext().components.core.engine.profiler?.isProfilerActive() != null) preferenceStartProfiler?.isVisible = showSecretDebugMenuThisSession &&
(requireContext().components.core.engine.profiler?.isProfilerActive() != null)
} }
setupAmoCollectionOverridePreference(requireContext().settings()) setupAmoCollectionOverridePreference(requireContext().settings())
setupAllowDomesticChinaFxaServerPreference() setupAllowDomesticChinaFxaServerPreference()
@ -660,7 +664,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
return browsers.isFirefoxDefaultBrowser return browsers.isFirefoxDefaultBrowser
} }
private fun updateProfilerUI(profilerStatus: Boolean){ private fun updateProfilerUI(profilerStatus: Boolean) {
if (profilerStatus) { if (profilerStatus) {
findPreference<Preference>(getPreferenceKey(R.string.pref_key_start_profiler))?.title = findPreference<Preference>(getPreferenceKey(R.string.pref_key_start_profiler))?.title =
resources.getString(R.string.profiler_stop) resources.getString(R.string.profiler_stop)

Loading…
Cancel
Save