Skip to content

Commit 7203460

Browse files
authored
Merge branch 'main' into compose-bom-2023-06-00
2 parents 5efefa6 + e4668f3 commit 7203460

File tree

12 files changed

+77
-30
lines changed

12 files changed

+77
-30
lines changed

README.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ understanding of which libraries and tools are being used, the reasoning behind
4545
UI, testing, architecture and more, and how all of these different pieces of the project fit
4646
together to create a complete app.
4747

48-
NOTE: Building the app using an M1 Mac will require the use of
49-
[Rosetta](https://support.apple.com/en-gb/HT211861). See
50-
[the following bug](https://github.com/protocolbuffers/protobuf/issues/9397#issuecomment-1086138036)
51-
for more details.
52-
5348
# Architecture
5449

5550
The **Now in Android** app follows the

app/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ dependencies {
119119
implementation(libs.androidx.navigation.compose)
120120
implementation(libs.androidx.window.manager)
121121
implementation(libs.androidx.profileinstaller)
122+
implementation(libs.kotlinx.coroutines.guava)
122123
implementation(libs.coil.kt)
123124
}
124125

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.google.samples.apps.nowinandroid
1818

1919
import android.os.Bundle
20+
import android.util.Log
2021
import androidx.activity.ComponentActivity
2122
import androidx.activity.compose.setContent
2223
import androidx.activity.viewModels
@@ -35,6 +36,7 @@ import androidx.lifecycle.Lifecycle
3536
import androidx.lifecycle.lifecycleScope
3637
import androidx.lifecycle.repeatOnLifecycle
3738
import androidx.metrics.performance.JankStats
39+
import androidx.profileinstaller.ProfileVerifier
3840
import com.google.accompanist.systemuicontroller.rememberSystemUiController
3941
import com.google.samples.apps.nowinandroid.MainActivityUiState.Loading
4042
import com.google.samples.apps.nowinandroid.MainActivityUiState.Success
@@ -47,11 +49,16 @@ import com.google.samples.apps.nowinandroid.core.model.data.DarkThemeConfig
4749
import com.google.samples.apps.nowinandroid.core.model.data.ThemeBrand
4850
import com.google.samples.apps.nowinandroid.ui.NiaApp
4951
import dagger.hilt.android.AndroidEntryPoint
52+
import kotlinx.coroutines.Dispatchers
5053
import kotlinx.coroutines.flow.collect
5154
import kotlinx.coroutines.flow.onEach
55+
import kotlinx.coroutines.guava.await
5256
import kotlinx.coroutines.launch
57+
import kotlinx.coroutines.withContext
5358
import javax.inject.Inject
5459

60+
private const val TAG = "MainActivity"
61+
5562
@OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
5663
@AndroidEntryPoint
5764
class MainActivity : ComponentActivity() {
@@ -133,12 +140,48 @@ class MainActivity : ComponentActivity() {
133140
override fun onResume() {
134141
super.onResume()
135142
lazyStats.get().isTrackingEnabled = true
143+
lifecycleScope.launch {
144+
logCompilationStatus()
145+
}
136146
}
137147

138148
override fun onPause() {
139149
super.onPause()
140150
lazyStats.get().isTrackingEnabled = false
141151
}
152+
153+
/**
154+
* Logs the app's Baseline Profile Compilation Status using [ProfileVerifier].
155+
*/
156+
private suspend fun logCompilationStatus() {
157+
/*
158+
When delivering through Google Play, the baseline profile is compiled during installation.
159+
In this case you will see the correct state logged without any further action necessary.
160+
To verify baseline profile installation locally, you need to manually trigger baseline
161+
profile installation.
162+
For immediate compilation, call:
163+
`adb shell cmd package compile -f -m speed-profile com.example.macrobenchmark.target`
164+
You can also trigger background optimizations:
165+
`adb shell pm bg-dexopt-job`
166+
Both jobs run asynchronously and might take some time complete.
167+
To see quick turnaround of the ProfileVerifier, we recommend using `speed-profile`.
168+
If you don't do either of these steps, you might only see the profile status reported as
169+
"enqueued for compilation" when running the sample locally.
170+
*/
171+
withContext(Dispatchers.IO) {
172+
val status = ProfileVerifier.getCompilationStatusAsync().await()
173+
Log.d(TAG, "ProfileInstaller status code: ${status.profileInstallResultCode}")
174+
Log.d(
175+
TAG,
176+
when {
177+
status.isCompiledWithProfile -> "ProfileInstaller: is compiled with profile"
178+
status.hasProfileEnqueuedForCompilation() ->
179+
"ProfileInstaller: Enqueued for compilation"
180+
else -> "Profile not compiled or enqueued"
181+
},
182+
)
183+
}
184+
}
142185
}
143186

144187
/**

benchmarks/src/main/java/com/google/samples/apps/nowinandroid/baselineprofile/BaselineProfileGenerator.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.google.samples.apps.nowinandroid.baselineprofile
1818

19-
import androidx.benchmark.macro.ExperimentalBaselineProfilesApi
2019
import androidx.benchmark.macro.junit4.BaselineProfileRule
2120
import com.google.samples.apps.nowinandroid.PACKAGE_NAME
2221
import com.google.samples.apps.nowinandroid.bookmarks.goToBookmarksScreen
@@ -31,13 +30,12 @@ import org.junit.Test
3130
/**
3231
* Generates a baseline profile which can be copied to `app/src/main/baseline-prof.txt`.
3332
*/
34-
@ExperimentalBaselineProfilesApi
3533
class BaselineProfileGenerator {
3634
@get:Rule val baselineProfileRule = BaselineProfileRule()
3735

3836
@Test
3937
fun generate() =
40-
baselineProfileRule.collectBaselineProfile(PACKAGE_NAME) {
38+
baselineProfileRule.collect(PACKAGE_NAME) {
4139
// This block defines the app's critical user journey. Here we are interested in
4240
// optimizing for app startup. But you can also navigate and scroll
4341
// through your most important UI.

build-logic/convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class AndroidApplicationConventionPlugin : Plugin<Project> {
3333

3434
extensions.configure<ApplicationExtension> {
3535
configureKotlinAndroid(this)
36-
defaultConfig.targetSdk = 33
36+
defaultConfig.targetSdk = 34
3737
configureGradleManagedDevices(this)
3838
}
3939
extensions.configure<ApplicationAndroidComponentsExtension> {

build-logic/convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class AndroidLibraryConventionPlugin : Plugin<Project> {
3838

3939
extensions.configure<LibraryExtension> {
4040
configureKotlinAndroid(this)
41-
defaultConfig.targetSdk = 33
41+
defaultConfig.targetSdk = 34
4242
configureFlavors(this)
4343
configureGradleManagedDevices(this)
4444
}

build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/KotlinAndroid.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ internal fun Project.configureKotlinAndroid(
3333
commonExtension: CommonExtension<*, *, *, *>,
3434
) {
3535
commonExtension.apply {
36-
compileSdk = 33
36+
compileSdk = 34
3737

3838
defaultConfig {
3939
minSdk = 21

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ fun LazyGridScope.newsFeed(
5757
when (feedState) {
5858
NewsFeedUiState.Loading -> Unit
5959
is NewsFeedUiState.Success -> {
60-
items(feedState.feed, key = { it.id }) { userNewsResource ->
60+
items(
61+
items = feedState.feed,
62+
key = { it.id },
63+
contentType = { "newsFeedItem" },
64+
) { userNewsResource ->
6165
val resourceUrl by remember {
6266
mutableStateOf(Uri.parse(userNewsResource.url))
6367
}

docs/ModularizationLearningJourney.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ Using the above modularization strategy, the Now in Android app has the followin
171171
<tr>
172172
<td><code>core:ui</code>
173173
</td>
174-
<td>Composite UI components and resources used by feature modules, such as the news feed. Unlike the <code>designsystem<code> module, it is dependent on the data layer since it renders models, like news resources.
174+
<td>Composite UI components and resources used by feature modules, such as the news feed. Unlike the <code>designsystem</code> module, it is dependent on the data layer since it renders models, like news resources.
175175
</td>
176176
<td> <code>NewsFeed</code> <code>NewsResourceCardExpanded</code>
177177
</td>

feature/foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ internal fun ForYouScreen(
182182
onTopicClick = onTopicClick,
183183
)
184184

185-
item(span = { GridItemSpan(maxLineSpan) }) {
185+
item(span = { GridItemSpan(maxLineSpan) }, contentType = "bottomSpacing") {
186186
Column {
187187
Spacer(modifier = Modifier.height(8.dp))
188188
// Add space for the content to clear the "offline" snackbar.
@@ -240,7 +240,7 @@ private fun LazyGridScope.onboarding(
240240
-> Unit
241241

242242
is OnboardingUiState.Shown -> {
243-
item(span = { GridItemSpan(maxLineSpan) }) {
243+
item(span = { GridItemSpan(maxLineSpan) }, contentType = "onboarding") {
244244
Column(modifier = interestsItemModifier) {
245245
Text(
246246
text = stringResource(R.string.onboarding_guidance_title),

0 commit comments

Comments
 (0)