Skip to content

Commit 598c8a4

Browse files
authored
Merge pull request #41 from android/bugfix/static-images
Baseline Profile Codelab Sample App - Replaces unsplash urls with static images
2 parents a732337 + 1ee15c2 commit 598c8a4

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

+71
-66
lines changed

baseline-profiles/app/src/main/java/com/example/baselineprofiles_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.baselineprofiles_codelab.model
1818

1919
import androidx.compose.runtime.Immutable
20+
import com.example.baselineprofiles_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
)

baseline-profiles/app/src/main/java/com/example/baselineprofiles_codelab/model/Snack.kt

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

1717
package com.example.baselineprofiles_codelab.model
1818

19+
import androidx.annotation.DrawableRes
1920
import androidx.compose.runtime.Immutable
21+
import com.example.baselineprofiles_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()
@@ -31,196 +34,195 @@ data class Snack(
3134
/**
3235
* Static data
3336
*/
34-
3537
val snacks = listOf(
3638
Snack(
3739
id = 1L,
3840
name = "Cupcake",
3941
tagline = "A tag line",
40-
imageUrl = "https://source.unsplash.com/pGM4sjt_BdQ",
42+
imageRes = R.drawable.cupcake,
4143
price = 299
4244
),
4345
Snack(
4446
id = 2L,
4547
name = "Donut",
4648
tagline = "A tag line",
47-
imageUrl = "https://source.unsplash.com/Yc5sL-ejk6U",
49+
imageRes = R.drawable.donut,
4850
price = 299
4951
),
5052
Snack(
5153
id = 3L,
5254
name = "Eclair",
5355
tagline = "A tag line",
54-
imageUrl = "https://source.unsplash.com/-LojFX9NfPY",
56+
imageRes = R.drawable.eclair,
5557
price = 299
5658
),
5759
Snack(
5860
id = 4L,
5961
name = "Froyo",
6062
tagline = "A tag line",
61-
imageUrl = "https://source.unsplash.com/3U2V5WqK1PQ",
63+
imageRes = R.drawable.froyo,
6264
price = 299
6365
),
6466
Snack(
6567
id = 5L,
6668
name = "Gingerbread",
6769
tagline = "A tag line",
68-
imageUrl = "https://source.unsplash.com/Y4YR9OjdIMk",
70+
imageRes = R.drawable.gingerbread,
6971
price = 499
7072
),
7173
Snack(
7274
id = 6L,
7375
name = "Honeycomb",
7476
tagline = "A tag line",
75-
imageUrl = "https://source.unsplash.com/bELvIg_KZGU",
77+
imageRes = R.drawable.honeycomb,
7678
price = 299
7779
),
7880
Snack(
7981
id = 7L,
8082
name = "Ice Cream Sandwich",
8183
tagline = "A tag line",
82-
imageUrl = "https://source.unsplash.com/YgYJsFDd4AU",
84+
imageRes = R.drawable.ice_cream_sandwich,
8385
price = 1299
8486
),
8587
Snack(
8688
id = 8L,
8789
name = "Jellybean",
8890
tagline = "A tag line",
89-
imageUrl = "https://source.unsplash.com/0u_vbeOkMpk",
91+
imageRes = R.drawable.jelly_bean,
9092
price = 299
9193
),
9294
Snack(
9395
id = 9L,
9496
name = "KitKat",
9597
tagline = "A tag line",
96-
imageUrl = "https://source.unsplash.com/yb16pT5F_jE",
98+
imageRes = R.drawable.kitkat,
9799
price = 549
98100
),
99101
Snack(
100102
id = 10L,
101103
name = "Lollipop",
102104
tagline = "A tag line",
103-
imageUrl = "https://source.unsplash.com/AHF_ZktTL6Q",
105+
imageRes = R.drawable.lollipop,
104106
price = 299
105107
),
106108
Snack(
107109
id = 11L,
108110
name = "Marshmallow",
109111
tagline = "A tag line",
110-
imageUrl = "https://source.unsplash.com/rqFm0IgMVYY",
112+
imageRes = R.drawable.marshmallow,
111113
price = 299
112114
),
113115
Snack(
114116
id = 12L,
115117
name = "Nougat",
116118
tagline = "A tag line",
117-
imageUrl = "https://source.unsplash.com/qRE_OpbVPR8",
119+
imageRes = R.drawable.nougat,
118120
price = 299
119121
),
120122
Snack(
121123
id = 13L,
122124
name = "Oreo",
123125
tagline = "A tag line",
124-
imageUrl = "https://source.unsplash.com/33fWPnyN6tU",
126+
imageRes = R.drawable.oreo,
125127
price = 299
126128
),
127129
Snack(
128130
id = 14L,
129131
name = "Pie",
130132
tagline = "A tag line",
131-
imageUrl = "https://source.unsplash.com/aX_ljOOyWJY",
133+
imageRes = R.drawable.pie,
132134
price = 299
133135
),
134136
Snack(
135137
id = 15L,
136138
name = "Chips",
137-
imageUrl = "https://source.unsplash.com/UsSdMZ78Q3E",
139+
imageRes = R.drawable.chips,
138140
price = 299
139141
),
140142
Snack(
141143
id = 16L,
142144
name = "Pretzels",
143-
imageUrl = "https://source.unsplash.com/7meCnGCJ5Ms",
145+
imageRes = R.drawable.pretzels,
144146
price = 299
145147
),
146148
Snack(
147149
id = 17L,
148150
name = "Smoothies",
149-
imageUrl = "https://source.unsplash.com/m741tj4Cz7M",
151+
imageRes = R.drawable.smoothies,
150152
price = 299
151153
),
152154
Snack(
153155
id = 18L,
154156
name = "Popcorn",
155-
imageUrl = "https://source.unsplash.com/iuwMdNq0-s4",
157+
imageRes = R.drawable.popcorn,
156158
price = 299
157159
),
158160
Snack(
159161
id = 19L,
160162
name = "Almonds",
161-
imageUrl = "https://source.unsplash.com/qgWWQU1SzqM",
163+
imageRes = R.drawable.almonds,
162164
price = 299
163165
),
164166
Snack(
165167
id = 20L,
166168
name = "Cheese",
167-
imageUrl = "https://source.unsplash.com/9MzCd76xLGk",
169+
imageRes = R.drawable.cheese,
168170
price = 299
169171
),
170172
Snack(
171173
id = 21L,
172174
name = "Apples",
173175
tagline = "A tag line",
174-
imageUrl = "https://source.unsplash.com/1d9xXWMtQzQ",
176+
imageRes = R.drawable.apples,
175177
price = 299
176178
),
177179
Snack(
178180
id = 22L,
179181
name = "Apple sauce",
180182
tagline = "A tag line",
181-
imageUrl = "https://source.unsplash.com/wZxpOw84QTU",
183+
imageRes = R.drawable.apple_sauce,
182184
price = 299
183185
),
184186
Snack(
185187
id = 23L,
186188
name = "Apple chips",
187189
tagline = "A tag line",
188-
imageUrl = "https://source.unsplash.com/okzeRxm_GPo",
190+
imageRes = R.drawable.apple_chips,
189191
price = 299
190192
),
191193
Snack(
192194
id = 24L,
193195
name = "Apple juice",
194196
tagline = "A tag line",
195-
imageUrl = "https://source.unsplash.com/l7imGdupuhU",
197+
imageRes = R.drawable.apple_juice,
196198
price = 299
197199
),
198200
Snack(
199201
id = 25L,
200202
name = "Apple pie",
201203
tagline = "A tag line",
202-
imageUrl = "https://source.unsplash.com/bkXzABDt08Q",
204+
imageRes = R.drawable.apple_pie,
203205
price = 299
204206
),
205207
Snack(
206208
id = 26L,
207209
name = "Grapes",
208210
tagline = "A tag line",
209-
imageUrl = "https://source.unsplash.com/y2MeW00BdBo",
211+
imageRes = R.drawable.grapes,
210212
price = 299
211213
),
212214
Snack(
213215
id = 27L,
214216
name = "Kiwi",
215217
tagline = "A tag line",
216-
imageUrl = "https://source.unsplash.com/1oMGgHn-M8k",
218+
imageRes = R.drawable.kiwi,
217219
price = 299
218220
),
219221
Snack(
220222
id = 28L,
221223
name = "Mango",
222224
tagline = "A tag line",
223-
imageUrl = "https://source.unsplash.com/TIGDsyy0TK4",
225+
imageRes = R.drawable.mango,
224226
price = 299
225227
)
226228
)

baseline-profiles/app/src/main/java/com/example/baselineprofiles_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.baselineprofiles_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,

baseline-profiles/app/src/main/java/com/example/baselineprofiles_codelab/ui/MainActivity.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,12 @@ package com.example.baselineprofiles_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)
27-
28-
// This app draws behind the system bars, so we want to handle fitting system windows
29-
WindowCompat.setDecorFitsSystemWindows(window, false)
30-
3128
setContent {
3229
JetsnackMain()
3330
}

0 commit comments

Comments
 (0)