From 1cd04cd05ec4f2cc5101c4a765ad4a4c711253b7 Mon Sep 17 00:00:00 2001 From: Sebastian Kaspari Date: Mon, 26 Jul 2021 15:20:52 +0200 Subject: [PATCH] Render debug info screen with Jetpack Compose. --- app/build.gradle | 12 ++++ .../mozilla/fenix/components/Components.kt | 10 +++ .../settings/SecretDebugSettingsFragment.kt | 63 ++++++++++++++----- app/src/main/res/values/preference_keys.xml | 2 - app/src/main/res/values/static_strings.xml | 1 - .../xml/secret_info_settings_preferences.xml | 20 ------ buildSrc/src/main/java/Dependencies.kt | 10 ++- 7 files changed, 80 insertions(+), 38 deletions(-) delete mode 100644 app/src/main/res/xml/secret_info_settings_preferences.xml diff --git a/app/build.gradle b/app/build.gradle index aa0b0b3b5..f78b0fd71 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -217,6 +217,14 @@ android { minHeapSize = "1024m" } } + + buildFeatures { + compose true + } + + composeOptions { + kotlinCompilerExtensionVersion = Versions.androidx_compose + } } android.applicationVariants.all { variant -> @@ -496,6 +504,10 @@ dependencies { implementation Deps.mozilla_lib_dataprotect debugImplementation Deps.leakcanary + implementation Deps.androidx_compose_ui + implementation Deps.androidx_compose_ui_tooling + implementation Deps.androidx_compose_foundation + implementation Deps.androidx_compose_material implementation Deps.androidx_legacy implementation Deps.androidx_biometric implementation Deps.androidx_paging diff --git a/app/src/main/java/org/mozilla/fenix/components/Components.kt b/app/src/main/java/org/mozilla/fenix/components/Components.kt index 6eb0a70e5..84415ba2e 100644 --- a/app/src/main/java/org/mozilla/fenix/components/Components.kt +++ b/app/src/main/java/org/mozilla/fenix/components/Components.kt @@ -7,6 +7,8 @@ package org.mozilla.fenix.components import android.app.Application import android.content.Context import android.content.Intent +import androidx.compose.runtime.Composable +import androidx.compose.ui.platform.LocalContext import androidx.core.net.toUri import com.google.android.play.core.review.ReviewManagerFactory import mozilla.components.feature.addons.AddonManager @@ -25,6 +27,7 @@ import org.mozilla.fenix.R import org.mozilla.fenix.autofill.AutofillConfirmActivity import org.mozilla.fenix.autofill.AutofillSearchActivity import org.mozilla.fenix.autofill.AutofillUnlockActivity +import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.settings import org.mozilla.fenix.perf.AppStartReasonProvider import org.mozilla.fenix.perf.StartupActivityLog @@ -173,3 +176,10 @@ class Components(private val context: Context) { val startupActivityLog by lazyMonitored { StartupActivityLog() } val startupStateProvider by lazyMonitored { StartupStateProvider(startupActivityLog, appStartReasonProvider) } } + +/** + * Returns the [Components] object from within a [Composable]. + */ +val components: Components + @Composable + get() = LocalContext.current.components diff --git a/app/src/main/java/org/mozilla/fenix/settings/SecretDebugSettingsFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/SecretDebugSettingsFragment.kt index 9ac930728..8db2736fe 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/SecretDebugSettingsFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/SecretDebugSettingsFragment.kt @@ -5,30 +5,65 @@ package org.mozilla.fenix.settings import android.os.Bundle -import androidx.preference.Preference -import androidx.preference.PreferenceFragmentCompat +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.padding +import androidx.compose.material.MaterialTheme +import androidx.compose.material.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.ComposeView +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import androidx.fragment.app.Fragment import org.mozilla.fenix.R -import org.mozilla.fenix.ext.requireComponents +import org.mozilla.fenix.components.components import org.mozilla.fenix.ext.showToolbar -class SecretDebugSettingsFragment : PreferenceFragmentCompat() { +class SecretDebugSettingsFragment : Fragment() { override fun onResume() { super.onResume() + showToolbar(getString(R.string.preferences_debug_info)) } - override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { - setPreferencesFromResource(R.xml.secret_info_settings_preferences, rootKey) - - val store = requireComponents.core.store - - requirePreference(R.string.pref_key_search_region_home).apply { - summary = store.state.search.region?.home ?: "Unknown" + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + return ComposeView(requireContext()).apply { + setContent { DebugInfo() } } + } +} - requirePreference(R.string.pref_key_search_region_current).apply { - summary = store.state.search.region?.current ?: "Unknown" - } +@Composable +private fun DebugInfo() { + val store = components.core.store + + Column( + modifier = Modifier.padding(8.dp) + ) { + Text( + text = stringResource(R.string.debug_info_region_home), + style = MaterialTheme.typography.h6, + modifier = Modifier.padding(4.dp) + ) + Text( + text = store.state.search.region?.home ?: "Unknown", + modifier = Modifier.padding(4.dp)) + Text( + text = stringResource(R.string.debug_info_region_current), + style = MaterialTheme.typography.h6, + modifier = Modifier.padding(4.dp) + ) + Text( + text = store.state.search.region?.current ?: "Unknown", + modifier = Modifier.padding(4.dp) + ) } } diff --git a/app/src/main/res/values/preference_keys.xml b/app/src/main/res/values/preference_keys.xml index e45acd930..5af7120ba 100644 --- a/app/src/main/res/values/preference_keys.xml +++ b/app/src/main/res/values/preference_keys.xml @@ -279,8 +279,6 @@ pref_key_secret_debug_info - pref_key_search_region_home - pref_key_search_region_current pref_key_show_address_feature diff --git a/app/src/main/res/values/static_strings.xml b/app/src/main/res/values/static_strings.xml index c5593aed2..9ff79b2b8 100644 --- a/app/src/main/res/values/static_strings.xml +++ b/app/src/main/res/values/static_strings.xml @@ -73,7 +73,6 @@ Telemetry - Search Home region Current region diff --git a/app/src/main/res/xml/secret_info_settings_preferences.xml b/app/src/main/res/xml/secret_info_settings_preferences.xml deleted file mode 100644 index 21bed11ea..000000000 --- a/app/src/main/res/xml/secret_info_settings_preferences.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - diff --git a/buildSrc/src/main/java/Dependencies.kt b/buildSrc/src/main/java/Dependencies.kt index 7bc722ba1..8e638b62c 100644 --- a/buildSrc/src/main/java/Dependencies.kt +++ b/buildSrc/src/main/java/Dependencies.kt @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ object Versions { - const val kotlin = "1.5.20" + const val kotlin = "1.5.10" const val coroutines = "1.5.0" // These versions are linked: lint should be X+23.Y.Z of gradle_plugin version, according to: @@ -17,6 +17,8 @@ object Versions { const val detekt = "1.17.1" const val jna = "5.6.0" + const val androidx_activity_compose = "1.3.0-rc02" + const val androidx_compose = "1.0.0-rc02" const val androidx_appcompat = "1.3.0" const val androidx_benchmark = "1.0.0" const val androidx_biometric = "1.1.0" @@ -164,6 +166,12 @@ object Deps { const val sentry = "io.sentry:sentry-android:${Versions.sentry}" const val leakcanary = "com.squareup.leakcanary:leakcanary-android:${Versions.leakcanary}" + const val androidx_compose_ui = "androidx.compose.ui:ui:${Versions.androidx_compose}" + const val androidx_compose_ui_test = "androidx.compose.ui:ui-test-junit4:${Versions.androidx_compose}" + const val androidx_compose_ui_test_manifest = "androidx.compose.ui:ui-test-manifest:${Versions.androidx_compose}" + const val androidx_compose_ui_tooling = "androidx.compose.ui:ui-tooling:${Versions.androidx_compose}" + const val androidx_compose_foundation = "androidx.compose.foundation:foundation:${Versions.androidx_compose}" + const val androidx_compose_material = "androidx.compose.material:material:${Versions.androidx_compose}" const val androidx_annotation = "androidx.annotation:annotation:${Versions.androidx_annotation}" const val androidx_benchmark_junit4 = "androidx.benchmark:benchmark-junit4:${Versions.androidx_benchmark}" const val androidx_biometric = "androidx.biometric:biometric:${Versions.androidx_biometric}"