diff --git a/README.md b/README.md index 1b1fb795e..db3c656c9 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ follows Android design and development best practices and is intended to be a us for developers. As a running app, it's intended to help developers keep up-to-date with the world of Android development by providing regular news updates. -The app is currently in development. The `demoRelease` variant is [available on the Play Store in open beta](https://play.google.com/store/apps/details?id=com.google.samples.apps.nowinandroid). +The app is currently in development. The `prodRelease` variant is [available on the Play Store](https://play.google.com/store/apps/details?id=com.google.samples.apps.nowinandroid). # Features @@ -154,8 +154,8 @@ Run the following command to get and analyse compose compiler metrics: ./gradlew assembleRelease -PenableComposeCompilerMetrics=true -PenableComposeCompilerReports=true ``` -The reports files will be added to build/compose-reports in each module. The metrics files will be -added to build/compose-metrics in each module. +The reports files will be added to [build/compose-reports](build/compose-reports). The metrics files will also be +added to [build/compose-metrics](build/compose-metrics). For more information on Compose compiler metrics, see [this blog post](https://medium.com/androiddevelopers/jetpack-compose-stability-explained-79c10db270c8). diff --git a/app/build.gradle.kts b/app/build.gradle.kts index cb18b33d6..bca633d5d 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -29,8 +29,8 @@ plugins { android { defaultConfig { applicationId = "com.google.samples.apps.nowinandroid" - versionCode = 5 - versionName = "0.0.5" // X.Y.Z; X = Major, Y = minor, Z = Patch level + versionCode = 8 + versionName = "0.1.2" // X.Y.Z; X = Major, Y = minor, Z = Patch level // Custom test runner to set up Hilt dependency graph testInstrumentationRunner = "com.google.samples.apps.nowinandroid.core.testing.NiaTestRunner" @@ -106,7 +106,6 @@ dependencies { debugImplementation(libs.androidx.compose.ui.testManifest) debugImplementation(project(":ui-test-hilt-manifest")) - implementation(libs.accompanist.systemuicontroller) implementation(libs.androidx.activity.compose) implementation(libs.androidx.appcompat) implementation(libs.androidx.core.ktx) @@ -122,12 +121,3 @@ dependencies { implementation(libs.kotlinx.coroutines.guava) implementation(libs.coil.kt) } - -// androidx.test is forcing JUnit, 4.12. This forces it to use 4.13 -configurations.configureEach { - resolutionStrategy { - force(libs.junit4) - // Temporary workaround for https://issuetracker.google.com/174733673 - force("org.objenesis:objenesis:2.6") - } -} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index dcaf39ce7..9c7f3b935 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -7,3 +7,13 @@ -dontwarn org.openjsse.javax.net.ssl.SSLParameters -dontwarn org.openjsse.javax.net.ssl.SSLSocket -dontwarn org.openjsse.net.ssl.OpenJSSE + +# Fix for Retrofit issue https://github.com/square/retrofit/issues/3751 +# Keep generic signature of Call, Response (R8 full mode strips signatures from non-kept items). +-keep,allowobfuscation,allowshrinking interface retrofit2.Call +-keep,allowobfuscation,allowshrinking class retrofit2.Response + +# With R8 full mode generic signatures are stripped for classes that are not +# kept. Suspend functions are wrapped in continuations where the type argument +# is used. +-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation \ No newline at end of file diff --git a/app/src/androidTest/java/com/google/samples/apps/nowinandroid/ui/NavigationTest.kt b/app/src/androidTest/java/com/google/samples/apps/nowinandroid/ui/NavigationTest.kt index 036a2955c..e1eab4796 100644 --- a/app/src/androidTest/java/com/google/samples/apps/nowinandroid/ui/NavigationTest.kt +++ b/app/src/androidTest/java/com/google/samples/apps/nowinandroid/ui/NavigationTest.kt @@ -27,19 +27,27 @@ import androidx.compose.ui.test.junit4.AndroidComposeTestRule import androidx.compose.ui.test.junit4.createAndroidComposeRule import androidx.compose.ui.test.onAllNodesWithText import androidx.compose.ui.test.onNodeWithContentDescription +import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick +import androidx.compose.ui.test.performScrollToNode import androidx.test.espresso.Espresso import androidx.test.espresso.NoActivityResumedException import com.google.samples.apps.nowinandroid.MainActivity import com.google.samples.apps.nowinandroid.R +import com.google.samples.apps.nowinandroid.core.data.repository.TopicsRepository +import com.google.samples.apps.nowinandroid.core.model.data.Topic import com.google.samples.apps.nowinandroid.core.rules.GrantPostNotificationsPermissionRule import dagger.hilt.android.testing.BindValue import dagger.hilt.android.testing.HiltAndroidRule import dagger.hilt.android.testing.HiltAndroidTest +import kotlinx.coroutines.flow.first +import kotlinx.coroutines.test.runTest +import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.rules.TemporaryFolder +import javax.inject.Inject import kotlin.properties.ReadOnlyProperty import com.google.samples.apps.nowinandroid.feature.bookmarks.R as BookmarksR import com.google.samples.apps.nowinandroid.feature.foryou.R as FeatureForyouR @@ -78,6 +86,9 @@ class NavigationTest { @get:Rule(order = 3) val composeTestRule = createAndroidComposeRule() + @Inject + lateinit var topicsRepository: TopicsRepository + private fun AndroidComposeTestRule<*, *>.stringResource(@StringRes resId: Int) = ReadOnlyProperty { _, _ -> activity.getString(resId) } @@ -92,6 +103,9 @@ class NavigationTest { private val brand by composeTestRule.stringResource(SettingsR.string.brand_android) private val ok by composeTestRule.stringResource(SettingsR.string.dismiss_dialog_button_text) + @Before + fun setup() = hiltRule.inject() + @Test fun firstScreen_isForYou() { composeTestRule.apply { @@ -251,11 +265,14 @@ class NavigationTest { } @Test - fun navigationBar_multipleBackStackInterests() { + fun navigationBar_multipleBackStackInterests() = runTest { composeTestRule.apply { onNodeWithText(interests).performClick() - // TODO: Grab string from fake data - onNodeWithText("Android Studio & Tools").performClick() + + // Select the last topic + val topic = topicsRepository.getTopics().first().sortedBy(Topic::name).last().name + onNodeWithTag("interests:topics").performScrollToNode(hasText(topic)) + onNodeWithText(topic).performClick() // Switch tab onNodeWithText(forYou).performClick() @@ -264,7 +281,7 @@ class NavigationTest { onNodeWithText(interests).performClick() // Verify we're not in the list of interests - onNodeWithText("Android Auto").assertDoesNotExist() // TODO: Grab string from fake data + onNodeWithTag("interests:topics").assertDoesNotExist() } } } diff --git a/app/src/androidTest/java/com/google/samples/apps/nowinandroid/ui/NiaAppStateTest.kt b/app/src/androidTest/java/com/google/samples/apps/nowinandroid/ui/NiaAppStateTest.kt index 2457af900..1560a74eb 100644 --- a/app/src/androidTest/java/com/google/samples/apps/nowinandroid/ui/NiaAppStateTest.kt +++ b/app/src/androidTest/java/com/google/samples/apps/nowinandroid/ui/NiaAppStateTest.kt @@ -183,7 +183,7 @@ class NiaAppStateTest { @Composable private fun rememberTestNavController(): TestNavHostController { val context = LocalContext.current - val navController = remember { + return remember { TestNavHostController(context).apply { navigatorProvider.addNavigator(ComposeNavigator()) graph = createGraph(startDestination = "a") { @@ -193,5 +193,4 @@ private fun rememberTestNavController(): TestNavHostController { } } } - return navController } diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/MainActivity.kt b/app/src/main/java/com/google/samples/apps/nowinandroid/MainActivity.kt index e107fd88c..7fe1bc674 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/MainActivity.kt +++ b/app/src/main/java/com/google/samples/apps/nowinandroid/MainActivity.kt @@ -19,7 +19,9 @@ package com.google.samples.apps.nowinandroid import android.os.Bundle import android.util.Log import androidx.activity.ComponentActivity +import androidx.activity.SystemBarStyle import androidx.activity.compose.setContent +import androidx.activity.enableEdgeToEdge import androidx.activity.viewModels import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi @@ -31,13 +33,11 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen -import androidx.core.view.WindowCompat import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope import androidx.lifecycle.repeatOnLifecycle import androidx.metrics.performance.JankStats import androidx.profileinstaller.ProfileVerifier -import com.google.accompanist.systemuicontroller.rememberSystemUiController import com.google.samples.apps.nowinandroid.MainActivityUiState.Loading import com.google.samples.apps.nowinandroid.MainActivityUiState.Success import com.google.samples.apps.nowinandroid.core.analytics.AnalyticsHelper @@ -108,16 +108,28 @@ class MainActivity : ComponentActivity() { } // Turn off the decor fitting system windows, which allows us to handle insets, - // including IME animations - WindowCompat.setDecorFitsSystemWindows(window, false) + // including IME animations, and go edge-to-edge + // This also sets up the initial system bar style based on the platform theme + enableEdgeToEdge() setContent { - val systemUiController = rememberSystemUiController() val darkTheme = shouldUseDarkTheme(uiState) - // Update the dark content of the system bars to match the theme - DisposableEffect(systemUiController, darkTheme) { - systemUiController.systemBarsDarkContentEnabled = !darkTheme + // Update the edge to edge configuration to match the theme + // This is the same parameters as the default enableEdgeToEdge call, but we manually + // resolve whether or not to show dark theme using uiState, since it can be different + // than the configuration's dark theme value based on the user preference. + DisposableEffect(darkTheme) { + enableEdgeToEdge( + statusBarStyle = SystemBarStyle.auto( + android.graphics.Color.TRANSPARENT, + android.graphics.Color.TRANSPARENT, + ) { darkTheme }, + navigationBarStyle = SystemBarStyle.auto( + lightScrim, + darkScrim, + ) { darkTheme }, + ) onDispose {} } @@ -224,3 +236,15 @@ private fun shouldUseDarkTheme( DarkThemeConfig.DARK -> true } } + +/** + * The default light scrim, as defined by androidx and the platform: + * https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:activity/activity/src/main/java/androidx/activity/EdgeToEdge.kt;l=35-38;drc=27e7d52e8604a080133e8b842db10c89b4482598 + */ +private val lightScrim = android.graphics.Color.argb(0xe6, 0xFF, 0xFF, 0xFF) + +/** + * The default dark scrim, as defined by androidx and the platform: + * https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:activity/activity/src/main/java/androidx/activity/EdgeToEdge.kt;l=40-44;drc=27e7d52e8604a080133e8b842db10c89b4482598 + */ +private val darkScrim = android.graphics.Color.argb(0x80, 0x1b, 0x1b, 0x1b) diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/MainActivityViewModel.kt b/app/src/main/java/com/google/samples/apps/nowinandroid/MainActivityViewModel.kt index ebea4b965..09f4597a7 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/MainActivityViewModel.kt +++ b/app/src/main/java/com/google/samples/apps/nowinandroid/MainActivityViewModel.kt @@ -43,6 +43,6 @@ class MainActivityViewModel @Inject constructor( } sealed interface MainActivityUiState { - object Loading : MainActivityUiState + data object Loading : MainActivityUiState data class Success(val userData: UserData) : MainActivityUiState } diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml index b014ff647..2cf4177e6 100644 --- a/app/src/main/res/values-night/themes.xml +++ b/app/src/main/res/values-night/themes.xml @@ -16,10 +16,7 @@ --> - + - diff --git a/app/src/main/res/values-v27/themes.xml b/app/src/main/res/values-v27/themes.xml deleted file mode 100644 index 969e51914..000000000 --- a/app/src/main/res/values-v27/themes.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 82456f53a..7cdd25527 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -18,19 +18,10 @@ - - - - +