Skip to content

Commit 3dd9581

Browse files
authored
Merge pull request #42 from android/bugfix/unsplash-url
Replaces: Unsplash image url with static images [Macro benchmark sample]
2 parents 598c8a4 + 0251b98 commit 3dd9581

Some content is hidden

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

44 files changed

+70
-67
lines changed

benchmarking/app/src/main/java/com/example/macrobenchmark_codelab/model/Search.kt

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.example.macrobenchmark_codelab.model
1818

1919
import androidx.compose.runtime.Immutable
20+
import com.example.macrobenchmark_codelab.R
2021
import kotlinx.coroutines.Dispatchers
2122
import kotlinx.coroutines.delay
2223
import kotlinx.coroutines.withContext
@@ -44,7 +45,7 @@ data class SearchCategoryCollection(
4445
@Immutable
4546
data class SearchCategory(
4647
val name: String,
47-
val imageUrl: String
48+
val imageRes: Int
4849
)
4950

5051
@Immutable
@@ -65,19 +66,19 @@ private val searchCategoryCollections = listOf(
6566
categories = listOf(
6667
SearchCategory(
6768
name = "Chips & crackers",
68-
imageUrl = "https://source.unsplash.com/UsSdMZ78Q3E"
69+
imageRes = R.drawable.chips
6970
),
7071
SearchCategory(
7172
name = "Fruit snacks",
72-
imageUrl = "https://source.unsplash.com/SfP1PtM9Qa8"
73+
imageRes = R.drawable.fruit,
7374
),
7475
SearchCategory(
7576
name = "Desserts",
76-
imageUrl = "https://source.unsplash.com/_jk8KIyN_uA"
77+
imageRes = R.drawable.desserts
7778
),
7879
SearchCategory(
79-
name = "Nuts ",
80-
imageUrl = "https://source.unsplash.com/UsSdMZ78Q3E"
80+
name = "Nuts",
81+
imageRes = R.drawable.nuts,
8182
)
8283
)
8384
),
@@ -87,27 +88,27 @@ private val searchCategoryCollections = listOf(
8788
categories = listOf(
8889
SearchCategory(
8990
name = "Organic",
90-
imageUrl = "https://source.unsplash.com/7meCnGCJ5Ms"
91+
imageRes = R.drawable.organic
9192
),
9293
SearchCategory(
9394
name = "Gluten Free",
94-
imageUrl = "https://source.unsplash.com/m741tj4Cz7M"
95+
imageRes = R.drawable.gluten_free
9596
),
9697
SearchCategory(
9798
name = "Paleo",
98-
imageUrl = "https://source.unsplash.com/dt5-8tThZKg"
99+
imageRes = R.drawable.paleo,
99100
),
100101
SearchCategory(
101102
name = "Vegan",
102-
imageUrl = "https://source.unsplash.com/ReXxkS1m1H0"
103+
imageRes = R.drawable.vegan,
103104
),
104105
SearchCategory(
105-
name = "Vegitarian",
106-
imageUrl = "https://source.unsplash.com/IGfIGP5ONV0"
106+
name = "Vegetarian",
107+
imageRes = R.drawable.organic,
107108
),
108109
SearchCategory(
109110
name = "Whole30",
110-
imageUrl = "https://source.unsplash.com/9MzCd76xLGk"
111+
imageRes = R.drawable.paleo
111112
)
112113
)
113114
)

benchmarking/app/src/main/java/com/example/macrobenchmark_codelab/model/Snack.kt

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@
1616

1717
package com.example.macrobenchmark_codelab.model
1818

19+
import androidx.annotation.DrawableRes
1920
import androidx.compose.runtime.Immutable
21+
import com.example.macrobenchmark_codelab.R
2022

2123
@Immutable
2224
data class Snack(
2325
val id: Long,
2426
val name: String,
25-
val imageUrl: String,
27+
@DrawableRes
28+
val imageRes: Int,
2629
val price: Long,
2730
val tagline: String = "",
2831
val tags: Set<String> = emptySet()
@@ -37,190 +40,190 @@ val snacks = listOf(
3740
id = 1L,
3841
name = "Cupcake",
3942
tagline = "A tag line",
40-
imageUrl = "https://source.unsplash.com/pGM4sjt_BdQ",
43+
imageRes = R.drawable.cupcake,
4144
price = 299
4245
),
4346
Snack(
4447
id = 2L,
4548
name = "Donut",
4649
tagline = "A tag line",
47-
imageUrl = "https://source.unsplash.com/Yc5sL-ejk6U",
50+
imageRes = R.drawable.donut,
4851
price = 299
4952
),
5053
Snack(
5154
id = 3L,
5255
name = "Eclair",
5356
tagline = "A tag line",
54-
imageUrl = "https://source.unsplash.com/-LojFX9NfPY",
57+
imageRes = R.drawable.eclair,
5558
price = 299
5659
),
5760
Snack(
5861
id = 4L,
5962
name = "Froyo",
6063
tagline = "A tag line",
61-
imageUrl = "https://source.unsplash.com/3U2V5WqK1PQ",
64+
imageRes = R.drawable.froyo,
6265
price = 299
6366
),
6467
Snack(
6568
id = 5L,
6669
name = "Gingerbread",
6770
tagline = "A tag line",
68-
imageUrl = "https://source.unsplash.com/Y4YR9OjdIMk",
71+
imageRes = R.drawable.gingerbread,
6972
price = 499
7073
),
7174
Snack(
7275
id = 6L,
7376
name = "Honeycomb",
7477
tagline = "A tag line",
75-
imageUrl = "https://source.unsplash.com/bELvIg_KZGU",
78+
imageRes = R.drawable.honeycomb,
7679
price = 299
7780
),
7881
Snack(
7982
id = 7L,
8083
name = "Ice Cream Sandwich",
8184
tagline = "A tag line",
82-
imageUrl = "https://source.unsplash.com/YgYJsFDd4AU",
85+
imageRes = R.drawable.ice_cream_sandwich,
8386
price = 1299
8487
),
8588
Snack(
8689
id = 8L,
8790
name = "Jellybean",
8891
tagline = "A tag line",
89-
imageUrl = "https://source.unsplash.com/0u_vbeOkMpk",
92+
imageRes = R.drawable.jelly_bean,
9093
price = 299
9194
),
9295
Snack(
9396
id = 9L,
9497
name = "KitKat",
9598
tagline = "A tag line",
96-
imageUrl = "https://source.unsplash.com/yb16pT5F_jE",
99+
imageRes = R.drawable.kitkat,
97100
price = 549
98101
),
99102
Snack(
100103
id = 10L,
101104
name = "Lollipop",
102105
tagline = "A tag line",
103-
imageUrl = "https://source.unsplash.com/AHF_ZktTL6Q",
106+
imageRes = R.drawable.lollipop,
104107
price = 299
105108
),
106109
Snack(
107110
id = 11L,
108111
name = "Marshmallow",
109112
tagline = "A tag line",
110-
imageUrl = "https://source.unsplash.com/rqFm0IgMVYY",
113+
imageRes = R.drawable.marshmallow,
111114
price = 299
112115
),
113116
Snack(
114117
id = 12L,
115118
name = "Nougat",
116119
tagline = "A tag line",
117-
imageUrl = "https://source.unsplash.com/qRE_OpbVPR8",
120+
imageRes = R.drawable.nougat,
118121
price = 299
119122
),
120123
Snack(
121124
id = 13L,
122125
name = "Oreo",
123126
tagline = "A tag line",
124-
imageUrl = "https://source.unsplash.com/33fWPnyN6tU",
127+
imageRes = R.drawable.oreo,
125128
price = 299
126129
),
127130
Snack(
128131
id = 14L,
129132
name = "Pie",
130133
tagline = "A tag line",
131-
imageUrl = "https://source.unsplash.com/aX_ljOOyWJY",
134+
imageRes = R.drawable.pie,
132135
price = 299
133136
),
134137
Snack(
135138
id = 15L,
136139
name = "Chips",
137-
imageUrl = "https://source.unsplash.com/UsSdMZ78Q3E",
140+
imageRes = R.drawable.chips,
138141
price = 299
139142
),
140143
Snack(
141144
id = 16L,
142145
name = "Pretzels",
143-
imageUrl = "https://source.unsplash.com/7meCnGCJ5Ms",
146+
imageRes = R.drawable.pretzels,
144147
price = 299
145148
),
146149
Snack(
147150
id = 17L,
148151
name = "Smoothies",
149-
imageUrl = "https://source.unsplash.com/m741tj4Cz7M",
152+
imageRes = R.drawable.smoothies,
150153
price = 299
151154
),
152155
Snack(
153156
id = 18L,
154157
name = "Popcorn",
155-
imageUrl = "https://source.unsplash.com/iuwMdNq0-s4",
158+
imageRes = R.drawable.popcorn,
156159
price = 299
157160
),
158161
Snack(
159162
id = 19L,
160163
name = "Almonds",
161-
imageUrl = "https://source.unsplash.com/qgWWQU1SzqM",
164+
imageRes = R.drawable.almonds,
162165
price = 299
163166
),
164167
Snack(
165168
id = 20L,
166169
name = "Cheese",
167-
imageUrl = "https://source.unsplash.com/9MzCd76xLGk",
170+
imageRes = R.drawable.cheese,
168171
price = 299
169172
),
170173
Snack(
171174
id = 21L,
172175
name = "Apples",
173176
tagline = "A tag line",
174-
imageUrl = "https://source.unsplash.com/1d9xXWMtQzQ",
177+
imageRes = R.drawable.apples,
175178
price = 299
176179
),
177180
Snack(
178181
id = 22L,
179182
name = "Apple sauce",
180183
tagline = "A tag line",
181-
imageUrl = "https://source.unsplash.com/wZxpOw84QTU",
184+
imageRes = R.drawable.apple_sauce,
182185
price = 299
183186
),
184187
Snack(
185188
id = 23L,
186189
name = "Apple chips",
187190
tagline = "A tag line",
188-
imageUrl = "https://source.unsplash.com/okzeRxm_GPo",
191+
imageRes = R.drawable.apple_chips,
189192
price = 299
190193
),
191194
Snack(
192195
id = 24L,
193196
name = "Apple juice",
194197
tagline = "A tag line",
195-
imageUrl = "https://source.unsplash.com/l7imGdupuhU",
198+
imageRes = R.drawable.apple_juice,
196199
price = 299
197200
),
198201
Snack(
199202
id = 25L,
200203
name = "Apple pie",
201204
tagline = "A tag line",
202-
imageUrl = "https://source.unsplash.com/bkXzABDt08Q",
205+
imageRes = R.drawable.apple_pie,
203206
price = 299
204207
),
205208
Snack(
206209
id = 26L,
207210
name = "Grapes",
208211
tagline = "A tag line",
209-
imageUrl = "https://source.unsplash.com/y2MeW00BdBo",
212+
imageRes = R.drawable.grapes,
210213
price = 299
211214
),
212215
Snack(
213216
id = 27L,
214217
name = "Kiwi",
215218
tagline = "A tag line",
216-
imageUrl = "https://source.unsplash.com/1oMGgHn-M8k",
219+
imageRes = R.drawable.kiwi,
217220
price = 299
218221
),
219222
Snack(
220223
id = 28L,
221224
name = "Mango",
222225
tagline = "A tag line",
223-
imageUrl = "https://source.unsplash.com/TIGDsyy0TK4",
226+
imageRes = R.drawable.mango,
224227
price = 299
225228
)
226229
)

benchmarking/app/src/main/java/com/example/macrobenchmark_codelab/ui/JetsnackMain.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
package com.example.macrobenchmark_codelab.ui
1818

19-
import androidx.compose.foundation.layout.padding
19+
import androidx.compose.foundation.layout.consumeWindowInsets
20+
import androidx.compose.foundation.layout.safeDrawingPadding
2021
import androidx.compose.foundation.layout.systemBarsPadding
2122
import androidx.compose.material.SnackbarHost
2223
import androidx.compose.runtime.Composable
@@ -48,7 +49,7 @@ fun JetsnackMain() {
4849
modifier = Modifier.semantics {
4950
// Allows to use testTag() for UiAutomator resource-id.
5051
testTagsAsResourceId = true
51-
},
52+
}.safeDrawingPadding(),
5253
bottomBar = {
5354
if (appState.shouldShowBottomBar) {
5455
JetsnackBottomBar(
@@ -70,7 +71,7 @@ fun JetsnackMain() {
7071
NavHost(
7172
navController = appState.navController,
7273
startDestination = MainDestinations.HOME_ROUTE,
73-
modifier = Modifier.padding(innerPaddingModifier)
74+
modifier = Modifier.consumeWindowInsets(innerPaddingModifier)
7475
) {
7576
jetsnackNavGraph(
7677
onSnackSelected = appState::navigateToSnackDetail,

benchmarking/app/src/main/java/com/example/macrobenchmark_codelab/ui/MainActivity.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,13 @@ package com.example.macrobenchmark_codelab.ui
1919
import android.os.Bundle
2020
import androidx.activity.ComponentActivity
2121
import androidx.activity.compose.setContent
22-
import androidx.core.view.WindowCompat
22+
import androidx.activity.enableEdgeToEdge
2323

2424
class MainActivity : ComponentActivity() {
2525
override fun onCreate(savedInstanceState: Bundle?) {
26+
enableEdgeToEdge()
2627
super.onCreate(savedInstanceState)
2728

28-
// This app draws behind the system bars, so we want to handle fitting system windows
29-
WindowCompat.setDecorFitsSystemWindows(window, false)
30-
3129
setContent {
3230
JetsnackMain()
3331
}

0 commit comments

Comments
 (0)