Skip to content

Commit 9f3103c

Browse files
Merge branch 'android:main' into loading-progress-for-image
2 parents e276212 + a3ee09e commit 9f3103c

File tree

13 files changed

+63
-81
lines changed

13 files changed

+63
-81
lines changed

app/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ dependencies {
106106
debugImplementation(libs.androidx.compose.ui.testManifest)
107107
debugImplementation(project(":ui-test-hilt-manifest"))
108108

109-
implementation(libs.accompanist.systemuicontroller)
110109
implementation(libs.androidx.activity.compose)
111110
implementation(libs.androidx.appcompat)
112111
implementation(libs.androidx.core.ktx)

app/src/androidTest/java/com/google/samples/apps/nowinandroid/ui/NavigationTest.kt

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,27 @@ import androidx.compose.ui.test.junit4.AndroidComposeTestRule
2727
import androidx.compose.ui.test.junit4.createAndroidComposeRule
2828
import androidx.compose.ui.test.onAllNodesWithText
2929
import androidx.compose.ui.test.onNodeWithContentDescription
30+
import androidx.compose.ui.test.onNodeWithTag
3031
import androidx.compose.ui.test.onNodeWithText
3132
import androidx.compose.ui.test.performClick
33+
import androidx.compose.ui.test.performScrollToNode
3234
import androidx.test.espresso.Espresso
3335
import androidx.test.espresso.NoActivityResumedException
3436
import com.google.samples.apps.nowinandroid.MainActivity
3537
import com.google.samples.apps.nowinandroid.R
38+
import com.google.samples.apps.nowinandroid.core.data.repository.TopicsRepository
39+
import com.google.samples.apps.nowinandroid.core.model.data.Topic
3640
import com.google.samples.apps.nowinandroid.core.rules.GrantPostNotificationsPermissionRule
3741
import dagger.hilt.android.testing.BindValue
3842
import dagger.hilt.android.testing.HiltAndroidRule
3943
import dagger.hilt.android.testing.HiltAndroidTest
44+
import kotlinx.coroutines.flow.first
45+
import kotlinx.coroutines.test.runTest
46+
import org.junit.Before
4047
import org.junit.Rule
4148
import org.junit.Test
4249
import org.junit.rules.TemporaryFolder
50+
import javax.inject.Inject
4351
import kotlin.properties.ReadOnlyProperty
4452
import com.google.samples.apps.nowinandroid.feature.bookmarks.R as BookmarksR
4553
import com.google.samples.apps.nowinandroid.feature.foryou.R as FeatureForyouR
@@ -78,6 +86,9 @@ class NavigationTest {
7886
@get:Rule(order = 3)
7987
val composeTestRule = createAndroidComposeRule<MainActivity>()
8088

89+
@Inject
90+
lateinit var topicsRepository: TopicsRepository
91+
8192
private fun AndroidComposeTestRule<*, *>.stringResource(@StringRes resId: Int) =
8293
ReadOnlyProperty<Any?, String> { _, _ -> activity.getString(resId) }
8394

@@ -92,6 +103,9 @@ class NavigationTest {
92103
private val brand by composeTestRule.stringResource(SettingsR.string.brand_android)
93104
private val ok by composeTestRule.stringResource(SettingsR.string.dismiss_dialog_button_text)
94105

106+
@Before
107+
fun setup() = hiltRule.inject()
108+
95109
@Test
96110
fun firstScreen_isForYou() {
97111
composeTestRule.apply {
@@ -251,11 +265,14 @@ class NavigationTest {
251265
}
252266

253267
@Test
254-
fun navigationBar_multipleBackStackInterests() {
268+
fun navigationBar_multipleBackStackInterests() = runTest {
255269
composeTestRule.apply {
256270
onNodeWithText(interests).performClick()
257-
// TODO: Grab string from fake data
258-
onNodeWithText("Android Studio & Tools").performClick()
271+
272+
// Select the last topic
273+
val topic = topicsRepository.getTopics().first().sortedBy(Topic::name).last().name
274+
onNodeWithTag("interests:topics").performScrollToNode(hasText(topic))
275+
onNodeWithText(topic).performClick()
259276

260277
// Switch tab
261278
onNodeWithText(forYou).performClick()
@@ -264,7 +281,7 @@ class NavigationTest {
264281
onNodeWithText(interests).performClick()
265282

266283
// Verify we're not in the list of interests
267-
onNodeWithText("Android Auto").assertDoesNotExist() // TODO: Grab string from fake data
284+
onNodeWithTag("interests:topics").assertDoesNotExist()
268285
}
269286
}
270287
}

app/src/main/java/com/google/samples/apps/nowinandroid/MainActivity.kt

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ package com.google.samples.apps.nowinandroid
1919
import android.os.Bundle
2020
import android.util.Log
2121
import androidx.activity.ComponentActivity
22+
import androidx.activity.SystemBarStyle
2223
import androidx.activity.compose.setContent
24+
import androidx.activity.enableEdgeToEdge
2325
import androidx.activity.viewModels
2426
import androidx.compose.foundation.isSystemInDarkTheme
2527
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
@@ -31,13 +33,11 @@ import androidx.compose.runtime.getValue
3133
import androidx.compose.runtime.mutableStateOf
3234
import androidx.compose.runtime.setValue
3335
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
34-
import androidx.core.view.WindowCompat
3536
import androidx.lifecycle.Lifecycle
3637
import androidx.lifecycle.lifecycleScope
3738
import androidx.lifecycle.repeatOnLifecycle
3839
import androidx.metrics.performance.JankStats
3940
import androidx.profileinstaller.ProfileVerifier
40-
import com.google.accompanist.systemuicontroller.rememberSystemUiController
4141
import com.google.samples.apps.nowinandroid.MainActivityUiState.Loading
4242
import com.google.samples.apps.nowinandroid.MainActivityUiState.Success
4343
import com.google.samples.apps.nowinandroid.core.analytics.AnalyticsHelper
@@ -108,16 +108,28 @@ class MainActivity : ComponentActivity() {
108108
}
109109

110110
// Turn off the decor fitting system windows, which allows us to handle insets,
111-
// including IME animations
112-
WindowCompat.setDecorFitsSystemWindows(window, false)
111+
// including IME animations, and go edge-to-edge
112+
// This also sets up the initial system bar style based on the platform theme
113+
enableEdgeToEdge()
113114

114115
setContent {
115-
val systemUiController = rememberSystemUiController()
116116
val darkTheme = shouldUseDarkTheme(uiState)
117117

118-
// Update the dark content of the system bars to match the theme
119-
DisposableEffect(systemUiController, darkTheme) {
120-
systemUiController.systemBarsDarkContentEnabled = !darkTheme
118+
// Update the edge to edge configuration to match the theme
119+
// This is the same parameters as the default enableEdgeToEdge call, but we manually
120+
// resolve whether or not to show dark theme using uiState, since it can be different
121+
// than the configuration's dark theme value based on the user preference.
122+
DisposableEffect(darkTheme) {
123+
enableEdgeToEdge(
124+
statusBarStyle = SystemBarStyle.auto(
125+
android.graphics.Color.TRANSPARENT,
126+
android.graphics.Color.TRANSPARENT,
127+
) { darkTheme },
128+
navigationBarStyle = SystemBarStyle.auto(
129+
lightScrim,
130+
darkScrim,
131+
) { darkTheme },
132+
)
121133
onDispose {}
122134
}
123135

@@ -224,3 +236,15 @@ private fun shouldUseDarkTheme(
224236
DarkThemeConfig.DARK -> true
225237
}
226238
}
239+
240+
/**
241+
* The default light scrim, as defined by androidx and the platform:
242+
* https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:activity/activity/src/main/java/androidx/activity/EdgeToEdge.kt;l=35-38;drc=27e7d52e8604a080133e8b842db10c89b4482598
243+
*/
244+
private val lightScrim = android.graphics.Color.argb(0xe6, 0xFF, 0xFF, 0xFF)
245+
246+
/**
247+
* The default dark scrim, as defined by androidx and the platform:
248+
* https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:activity/activity/src/main/java/androidx/activity/EdgeToEdge.kt;l=40-44;drc=27e7d52e8604a080133e8b842db10c89b4482598
249+
*/
250+
private val darkScrim = android.graphics.Color.argb(0x80, 0x1b, 0x1b, 0x1b)

app/src/main/res/values-night/themes.xml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616
-->
1717
<resources xmlns:tools="http://schemas.android.com/tools">
1818

19-
<style name="NightAdjusted.Theme.Nia" parent="android:Theme.Material.NoActionBar">
20-
<item name="android:windowLightStatusBar" tools:targetApi="23">false</item>
21-
<item name="android:windowLightNavigationBar" tools:targetApi="27">false</item>
22-
</style>
19+
<style name="NightAdjusted.Theme.Nia" parent="android:Theme.Material.NoActionBar" />
2320

2421
<style name="NightAdjusted.Theme.Splash" parent="Theme.SplashScreen">
2522
<item name="android:windowLightStatusBar" tools:targetApi="23">false</item>

app/src/main/res/values-v23/themes.xml

Lines changed: 0 additions & 22 deletions
This file was deleted.

app/src/main/res/values-v27/themes.xml

Lines changed: 0 additions & 23 deletions
This file was deleted.

app/src/main/res/values/themes.xml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,10 @@
1818

1919
<!-- Allows us to override night specific attributes in the
2020
values-night folder. -->
21-
<style name="NightAdjusted.Theme.Nia" parent="android:Theme.Material.Light.NoActionBar">
22-
<item name="android:windowLightStatusBar" tools:targetApi="23">true</item>
23-
<item name="android:windowLightNavigationBar" tools:targetApi="27">true</item>
24-
</style>
25-
26-
<!-- Allows us to override platform level specific attributes in their
27-
respective values-vXX folder. -->
28-
<style name="PlatformAdjusted.Theme.Nia" parent="NightAdjusted.Theme.Nia">
29-
<item name="android:statusBarColor">@color/black30</item>
30-
</style>
21+
<style name="NightAdjusted.Theme.Nia" parent="android:Theme.Material.Light.NoActionBar" />
3122

3223
<!-- The final theme we use -->
33-
<style name="Theme.Nia" parent="PlatformAdjusted.Theme.Nia" />
24+
<style name="Theme.Nia" parent="NightAdjusted.Theme.Nia" />
3425

3526
<style name="NightAdjusted.Theme.Splash" parent="Theme.SplashScreen">
3627
<item name="android:windowLightStatusBar" tools:targetApi="23">true</item>

core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/data/FollowableTopicTestData.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ val followableTopicTestData: List<FollowableTopic> = listOf(
3737
id = "3",
3838
name = "UI",
3939
shortDescription = "Material Design, Navigation, Text, Paging, Accessibility (a11y), Internationalization (i18n), Localization (l10n), Animations, Large Screens, Widgets",
40-
longDescription = "Learn how to optimize your app's user interface - everything that users can see and interact with. Stay up to date on tocpis such as Material Design, Navigation, Text, Paging, Compose, Accessibility (a11y), Internationalization (i18n), Localization (l10n), Animations, Large Screens, Widgets, and many more!",
40+
longDescription = "Learn how to optimize your app's user interface - everything that users can see and interact with. Stay up to date on topics such as Material Design, Navigation, Text, Paging, Compose, Accessibility (a11y), Internationalization (i18n), Localization (l10n), Animations, Large Screens, Widgets, and many more!",
4141
imageUrl = "https://firebasestorage.googleapis.com/v0/b/now-in-android.appspot.com/o/img%2Fic_topic_UI.svg?alt=media&token=0ee1842b-12e8-435f-87ba-a5bb02c47594",
4242
url = "",
4343
),

core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/data/TopicsTestData.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ val topicsTestData: List<Topic> = listOf(
3232
id = "3",
3333
name = "UI",
3434
shortDescription = "Material Design, Navigation, Text, Paging, Accessibility (a11y), Internationalization (i18n), Localization (l10n), Animations, Large Screens, Widgets",
35-
longDescription = "Learn how to optimize your app's user interface - everything that users can see and interact with. Stay up to date on tocpis such as Material Design, Navigation, Text, Paging, Compose, Accessibility (a11y), Internationalization (i18n), Localization (l10n), Animations, Large Screens, Widgets, and many more!",
35+
longDescription = "Learn how to optimize your app's user interface - everything that users can see and interact with. Stay up to date on topics such as Material Design, Navigation, Text, Paging, Compose, Accessibility (a11y), Internationalization (i18n), Localization (l10n), Animations, Large Screens, Widgets, and many more!",
3636
imageUrl = "https://firebasestorage.googleapis.com/v0/b/now-in-android.appspot.com/o/img%2Fic_topic_UI.svg?alt=media&token=0ee1842b-12e8-435f-87ba-a5bb02c47594",
3737
url = "",
3838
),

core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/FollowableTopicPreviewParameterProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class FollowableTopicPreviewParameterProvider : PreviewParameterProvider<List<Fo
4545
id = "3",
4646
name = "UI",
4747
shortDescription = "Material Design, Navigation, Text, Paging, Accessibility (a11y), Internationalization (i18n), Localization (l10n), Animations, Large Screens, Widgets",
48-
longDescription = "Learn how to optimize your app's user interface - everything that users can see and interact with. Stay up to date on tocpis such as Material Design, Navigation, Text, Paging, Compose, Accessibility (a11y), Internationalization (i18n), Localization (l10n), Animations, Large Screens, Widgets, and many more!",
48+
longDescription = "Learn how to optimize your app's user interface - everything that users can see and interact with. Stay up to date on topics such as Material Design, Navigation, Text, Paging, Compose, Accessibility (a11y), Internationalization (i18n), Localization (l10n), Animations, Large Screens, Widgets, and many more!",
4949
imageUrl = "https://firebasestorage.googleapis.com/v0/b/now-in-android.appspot.com/o/img%2Fic_topic_UI.svg?alt=media&token=0ee1842b-12e8-435f-87ba-a5bb02c47594",
5050
url = "",
5151
),

0 commit comments

Comments
 (0)