From 6294425de60bb49ad0bd45e898487d0bdd8085ee Mon Sep 17 00:00:00 2001 From: Marc Leclair Date: Tue, 3 May 2022 20:51:52 -0400 Subject: [PATCH] [fenix] Lint fixes --- .../fenix/perf/ProfilerStopDialogFragment.kt | 23 +++++++++++-------- .../org/mozilla/fenix/perf/ProfilerUtils.kt | 7 +----- .../mozilla/fenix/perf/ProfilerViewModel.kt | 15 +++++++++--- .../fenix/settings/SettingsFragment.kt | 14 +++++++---- 4 files changed, 36 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/perf/ProfilerStopDialogFragment.kt b/app/src/main/java/org/mozilla/fenix/perf/ProfilerStopDialogFragment.kt index 12171bde0b..cc2dda57fe 100644 --- a/app/src/main/java/org/mozilla/fenix/perf/ProfilerStopDialogFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/perf/ProfilerStopDialogFragment.kt @@ -65,15 +65,20 @@ class ProfilerStopDialogFragment : DialogFragment() { private fun StopProfilerCard() { val viewStateObserver = remember { mutableStateOf(CardState.UrlWarningState) } - Dialog(onDismissRequest = { - // In the waiting state, we do not want the users to be able to click away from the dialogue - // since the user needs to wait for the profiler data to be ready and we don't want to handle - // the process in the background. - if (viewStateObserver.value != CardState.WaitForProfilerState) { - profilerViewModel.setProfilerState(requireContext().components.core.engine.profiler!!.isProfilerActive()) - this@ProfilerStopDialogFragment.dismiss() + Dialog( + onDismissRequest = { + // In the waiting state, we do not want the users to be able to click away from the dialogue + // since the user needs to wait for the profiler data to be ready and we don't want to handle + // the process in the background. + if (viewStateObserver.value != CardState.WaitForProfilerState) { + profilerViewModel.setProfilerState( + requireContext() + .components.core.engine.profiler!!.isProfilerActive() + ) + this@ProfilerStopDialogFragment.dismiss() + } } - }) { + ) { when (viewStateObserver.value) { CardState.UrlWarningState -> { UrlWarningCard(viewStateObserver) @@ -111,7 +116,7 @@ class ProfilerStopDialogFragment : DialogFragment() { ) { TextButton( onClick = { - displayToastAndDismiss(R.string.profile_stop_dialogue_cancel_save) + displayToastAndDismiss(R.string.profile_stop_dialogue_cancel_save) } ) { Text(stringResource(R.string.profiler_start_cancel)) diff --git a/app/src/main/java/org/mozilla/fenix/perf/ProfilerUtils.kt b/app/src/main/java/org/mozilla/fenix/perf/ProfilerUtils.kt index d69e2355e8..faa3e1706e 100644 --- a/app/src/main/java/org/mozilla/fenix/perf/ProfilerUtils.kt +++ b/app/src/main/java/org/mozilla/fenix/perf/ProfilerUtils.kt @@ -14,14 +14,9 @@ import mozilla.components.concept.fetch.Response import org.json.JSONObject import org.mozilla.fenix.R import org.mozilla.fenix.ext.components -import java.io.BufferedReader -import java.io.ByteArrayInputStream import java.io.File -import java.io.FileNotFoundException import java.io.FileOutputStream 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_SERVER_HEADER = "application/vnd.firefox-profiler+json;version=1.0" @@ -80,7 +75,7 @@ enum class ProfilerSettings(val threads: Array, val features: Array = MutableLiveData() + var isProfilerActive: MutableLiveData = MutableLiveData() + /** + * @return profiler status + */ fun getProfilerState(): LiveData { return isProfilerActive } - fun setProfilerState(isActive: Boolean){ + /** + * @param isActive whether the profiler is active or not + */ + fun setProfilerState(isActive: Boolean) { isProfilerActive.value = isActive } -} \ No newline at end of file +} diff --git a/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt index ad467f94ac..23a1654592 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt @@ -151,9 +151,12 @@ class SettingsFragment : PreferenceFragmentCompat() { } } - profilerViewModel.getProfilerState().observe(this, Observer{ - updateProfilerUI(it) - }) + profilerViewModel.getProfilerState().observe( + this, + Observer { + updateProfilerUI(it) + } + ) } override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { @@ -497,7 +500,8 @@ class SettingsFragment : PreferenceFragmentCompat() { findPreference( getPreferenceKey(R.string.pref_key_secret_debug_info) )?.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()) setupAllowDomesticChinaFxaServerPreference() @@ -660,7 +664,7 @@ class SettingsFragment : PreferenceFragmentCompat() { return browsers.isFirefoxDefaultBrowser } - private fun updateProfilerUI(profilerStatus: Boolean){ + private fun updateProfilerUI(profilerStatus: Boolean) { if (profilerStatus) { findPreference(getPreferenceKey(R.string.pref_key_start_profiler))?.title = resources.getString(R.string.profiler_stop)