Skip to content

Commit 89a1294

Browse files
authored
Merge branch 'main' into takahirom/rename-topicBody/2023-07-13
2 parents ed90a38 + 6c0d6ad commit 89a1294

File tree

104 files changed

+1891
-1070
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+1891
-1070
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ follows Android design and development best practices and is intended to be a us
1515
for developers. As a running app, it's intended to help developers keep up-to-date with the world
1616
of Android development by providing regular news updates.
1717

18-
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).
18+
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).
1919

2020
# Features
2121

@@ -154,8 +154,8 @@ Run the following command to get and analyse compose compiler metrics:
154154
./gradlew assembleRelease -PenableComposeCompilerMetrics=true -PenableComposeCompilerReports=true
155155
```
156156

157-
The reports files will be added to build/compose-reports in each module. The metrics files will be
158-
added to build/compose-metrics in each module.
157+
The reports files will be added to [build/compose-reports](build/compose-reports). The metrics files will also be
158+
added to [build/compose-metrics](build/compose-metrics).
159159

160160
For more information on Compose compiler metrics, see [this blog post](https://medium.com/androiddevelopers/jetpack-compose-stability-explained-79c10db270c8).
161161

app/build.gradle.kts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ plugins {
2929
android {
3030
defaultConfig {
3131
applicationId = "com.google.samples.apps.nowinandroid"
32-
versionCode = 5
33-
versionName = "0.0.5" // X.Y.Z; X = Major, Y = minor, Z = Patch level
32+
versionCode = 8
33+
versionName = "0.1.2" // X.Y.Z; X = Major, Y = minor, Z = Patch level
3434

3535
// Custom test runner to set up Hilt dependency graph
3636
testInstrumentationRunner = "com.google.samples.apps.nowinandroid.core.testing.NiaTestRunner"
@@ -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)
@@ -122,12 +121,3 @@ dependencies {
122121
implementation(libs.kotlinx.coroutines.guava)
123122
implementation(libs.coil.kt)
124123
}
125-
126-
// androidx.test is forcing JUnit, 4.12. This forces it to use 4.13
127-
configurations.configureEach {
128-
resolutionStrategy {
129-
force(libs.junit4)
130-
// Temporary workaround for https://issuetracker.google.com/174733673
131-
force("org.objenesis:objenesis:2.6")
132-
}
133-
}

app/proguard-rules.pro

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,13 @@
77
-dontwarn org.openjsse.javax.net.ssl.SSLParameters
88
-dontwarn org.openjsse.javax.net.ssl.SSLSocket
99
-dontwarn org.openjsse.net.ssl.OpenJSSE
10+
11+
# Fix for Retrofit issue https://github.com/square/retrofit/issues/3751
12+
# Keep generic signature of Call, Response (R8 full mode strips signatures from non-kept items).
13+
-keep,allowobfuscation,allowshrinking interface retrofit2.Call
14+
-keep,allowobfuscation,allowshrinking class retrofit2.Response
15+
16+
# With R8 full mode generic signatures are stripped for classes that are not
17+
# kept. Suspend functions are wrapped in continuations where the type argument
18+
# is used.
19+
-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation

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/androidTest/java/com/google/samples/apps/nowinandroid/ui/NiaAppStateTest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class NiaAppStateTest {
183183
@Composable
184184
private fun rememberTestNavController(): TestNavHostController {
185185
val context = LocalContext.current
186-
val navController = remember {
186+
return remember<TestNavHostController> {
187187
TestNavHostController(context).apply {
188188
navigatorProvider.addNavigator(ComposeNavigator())
189189
graph = createGraph(startDestination = "a") {
@@ -193,5 +193,4 @@ private fun rememberTestNavController(): TestNavHostController {
193193
}
194194
}
195195
}
196-
return navController
197196
}

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/java/com/google/samples/apps/nowinandroid/MainActivityViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ class MainActivityViewModel @Inject constructor(
4343
}
4444

4545
sealed interface MainActivityUiState {
46-
object Loading : MainActivityUiState
46+
data object Loading : MainActivityUiState
4747
data class Success(val userData: UserData) : MainActivityUiState
4848
}

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.

0 commit comments

Comments
 (0)