Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to using static images for jetsnack #1422

Merged
merged 5 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions Jetsnack/app/src/main/java/com/example/jetsnack/model/Search.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.example.jetsnack.model

import androidx.compose.runtime.Immutable
import com.example.jetsnack.R
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.withContext
Expand Down Expand Up @@ -44,7 +45,7 @@ data class SearchCategoryCollection(
@Immutable
data class SearchCategory(
val name: String,
val imageUrl: String
val imageRes: Int
)

@Immutable
Expand All @@ -65,19 +66,19 @@ private val searchCategoryCollections = listOf(
categories = listOf(
SearchCategory(
name = "Chips & crackers",
imageUrl = "https://source.unsplash.com/UsSdMZ78Q3E"
imageRes = R.drawable.chips
),
SearchCategory(
name = "Fruit snacks",
imageUrl = "https://source.unsplash.com/SfP1PtM9Qa8"
imageRes = R.drawable.fruit,
),
SearchCategory(
name = "Desserts",
imageUrl = "https://source.unsplash.com/_jk8KIyN_uA"
imageRes = R.drawable.desserts
),
SearchCategory(
name = "Nuts ",
imageUrl = "https://source.unsplash.com/UsSdMZ78Q3E"
name = "Nuts",
imageRes = R.drawable.nuts,
)
)
),
Expand All @@ -87,27 +88,27 @@ private val searchCategoryCollections = listOf(
categories = listOf(
SearchCategory(
name = "Organic",
imageUrl = "https://source.unsplash.com/7meCnGCJ5Ms"
imageRes = R.drawable.organic
),
SearchCategory(
name = "Gluten Free",
imageUrl = "https://source.unsplash.com/m741tj4Cz7M"
imageRes = R.drawable.gluten_free
),
SearchCategory(
name = "Paleo",
imageUrl = "https://source.unsplash.com/dt5-8tThZKg"
imageRes = R.drawable.paleo,
),
SearchCategory(
name = "Vegan",
imageUrl = "https://source.unsplash.com/ReXxkS1m1H0"
imageRes = R.drawable.vegan,
),
SearchCategory(
name = "Vegitarian",
imageUrl = "https://source.unsplash.com/IGfIGP5ONV0"
name = "Vegetarian",
imageRes = R.drawable.organic,
),
SearchCategory(
name = "Whole30",
imageUrl = "https://source.unsplash.com/9MzCd76xLGk"
imageRes = R.drawable.paleo
)
)
)
Expand Down
61 changes: 32 additions & 29 deletions Jetsnack/app/src/main/java/com/example/jetsnack/model/Snack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@

package com.example.jetsnack.model

import androidx.annotation.DrawableRes
import androidx.compose.runtime.Immutable
import com.example.jetsnack.R

@Immutable
data class Snack(
val id: Long,
val name: String,
val imageUrl: String,
@DrawableRes
val imageRes: Int,
val price: Long,
val tagline: String = "",
val tags: Set<String> = emptySet()
Expand All @@ -37,190 +40,190 @@ val snacks = listOf(
id = 1L,
name = "Cupcake",
tagline = "A tag line",
imageUrl = "https://source.unsplash.com/pGM4sjt_BdQ",
imageRes = R.drawable.cupcake,
price = 299
),
Snack(
id = 2L,
name = "Donut",
tagline = "A tag line",
imageUrl = "https://source.unsplash.com/Yc5sL-ejk6U",
imageRes = R.drawable.donut,
price = 299
),
Snack(
id = 3L,
name = "Eclair",
tagline = "A tag line",
imageUrl = "https://source.unsplash.com/-LojFX9NfPY",
imageRes = R.drawable.eclair,
price = 299
),
Snack(
id = 4L,
name = "Froyo",
tagline = "A tag line",
imageUrl = "https://source.unsplash.com/3U2V5WqK1PQ",
imageRes = R.drawable.froyo,
price = 299
),
Snack(
id = 5L,
name = "Gingerbread",
tagline = "A tag line",
imageUrl = "https://source.unsplash.com/Y4YR9OjdIMk",
imageRes = R.drawable.gingerbread,
price = 499
),
Snack(
id = 6L,
name = "Honeycomb",
tagline = "A tag line",
imageUrl = "https://source.unsplash.com/bELvIg_KZGU",
imageRes = R.drawable.honeycomb,
price = 299
),
Snack(
id = 7L,
name = "Ice Cream Sandwich",
tagline = "A tag line",
imageUrl = "https://source.unsplash.com/YgYJsFDd4AU",
imageRes = R.drawable.ice_cream_sandwich,
price = 1299
),
Snack(
id = 8L,
name = "Jellybean",
tagline = "A tag line",
imageUrl = "https://source.unsplash.com/0u_vbeOkMpk",
imageRes = R.drawable.jelly_bean,
price = 299
),
Snack(
id = 9L,
name = "KitKat",
tagline = "A tag line",
imageUrl = "https://source.unsplash.com/yb16pT5F_jE",
imageRes = R.drawable.kitkat,
price = 549
),
Snack(
id = 10L,
name = "Lollipop",
tagline = "A tag line",
imageUrl = "https://source.unsplash.com/AHF_ZktTL6Q",
imageRes = R.drawable.lollipop,
price = 299
),
Snack(
id = 11L,
name = "Marshmallow",
tagline = "A tag line",
imageUrl = "https://source.unsplash.com/rqFm0IgMVYY",
imageRes = R.drawable.marshmallow,
price = 299
),
Snack(
id = 12L,
name = "Nougat",
tagline = "A tag line",
imageUrl = "https://source.unsplash.com/qRE_OpbVPR8",
imageRes = R.drawable.nougat,
price = 299
),
Snack(
id = 13L,
name = "Oreo",
tagline = "A tag line",
imageUrl = "https://source.unsplash.com/33fWPnyN6tU",
imageRes = R.drawable.oreo,
price = 299
),
Snack(
id = 14L,
name = "Pie",
tagline = "A tag line",
imageUrl = "https://source.unsplash.com/aX_ljOOyWJY",
imageRes = R.drawable.pie,
price = 299
),
Snack(
id = 15L,
name = "Chips",
imageUrl = "https://source.unsplash.com/UsSdMZ78Q3E",
imageRes = R.drawable.chips,
price = 299
),
Snack(
id = 16L,
name = "Pretzels",
imageUrl = "https://source.unsplash.com/7meCnGCJ5Ms",
imageRes = R.drawable.pretzels,
price = 299
),
Snack(
id = 17L,
name = "Smoothies",
imageUrl = "https://source.unsplash.com/m741tj4Cz7M",
imageRes = R.drawable.smoothies,
price = 299
),
Snack(
id = 18L,
name = "Popcorn",
imageUrl = "https://source.unsplash.com/iuwMdNq0-s4",
imageRes = R.drawable.popcorn,
price = 299
),
Snack(
id = 19L,
name = "Almonds",
imageUrl = "https://source.unsplash.com/qgWWQU1SzqM",
imageRes = R.drawable.almonds,
price = 299
),
Snack(
id = 20L,
name = "Cheese",
imageUrl = "https://source.unsplash.com/9MzCd76xLGk",
imageRes = R.drawable.cheese,
price = 299
),
Snack(
id = 21L,
name = "Apples",
tagline = "A tag line",
imageUrl = "https://source.unsplash.com/1d9xXWMtQzQ",
imageRes = R.drawable.apples,
price = 299
),
Snack(
id = 22L,
name = "Apple sauce",
tagline = "A tag line",
imageUrl = "https://source.unsplash.com/wZxpOw84QTU",
imageRes = R.drawable.apple_sauce,
price = 299
),
Snack(
id = 23L,
name = "Apple chips",
tagline = "A tag line",
imageUrl = "https://source.unsplash.com/okzeRxm_GPo",
imageRes = R.drawable.apple_chips,
price = 299
),
Snack(
id = 24L,
name = "Apple juice",
tagline = "A tag line",
imageUrl = "https://source.unsplash.com/l7imGdupuhU",
imageRes = R.drawable.apple_juice,
price = 299
),
Snack(
id = 25L,
name = "Apple pie",
tagline = "A tag line",
imageUrl = "https://source.unsplash.com/bkXzABDt08Q",
imageRes = R.drawable.apple_pie,
price = 299
),
Snack(
id = 26L,
name = "Grapes",
tagline = "A tag line",
imageUrl = "https://source.unsplash.com/y2MeW00BdBo",
imageRes = R.drawable.grapes,
price = 299
),
Snack(
id = 27L,
name = "Kiwi",
tagline = "A tag line",
imageUrl = "https://source.unsplash.com/1oMGgHn-M8k",
imageRes = R.drawable.kiwi,
price = 299
),
Snack(
id = 28L,
name = "Mango",
tagline = "A tag line",
imageUrl = "https://source.unsplash.com/TIGDsyy0TK4",
imageRes = R.drawable.mango,
price = 299
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.example.jetsnack.ui.components

import android.content.res.Configuration.UI_MODE_NIGHT_YES
import androidx.annotation.DrawableRes
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
Expand Down Expand Up @@ -50,15 +51,13 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import coil.request.ImageRequest
import com.example.jetsnack.R
import com.example.jetsnack.model.CollectionType
import com.example.jetsnack.model.Snack
import com.example.jetsnack.model.SnackCollection
Expand Down Expand Up @@ -194,7 +193,7 @@ fun SnackItem(
.padding(8.dp)
) {
SnackImage(
imageUrl = snack.imageUrl,
imageRes = snack.imageRes,
elevation = 4.dp,
contentDescription = null,
modifier = Modifier.size(120.dp)
Expand Down Expand Up @@ -254,7 +253,7 @@ private fun HighlightSnackItem(
)
)
SnackImage(
imageUrl = snack.imageUrl,
imageRes = snack.imageRes,
contentDescription = null,
modifier = Modifier
.size(120.dp)
Expand Down Expand Up @@ -283,7 +282,8 @@ private fun HighlightSnackItem(

@Composable
fun SnackImage(
imageUrl: String,
@DrawableRes
imageRes: Int,
contentDescription: String?,
modifier: Modifier = Modifier,
elevation: Dp = 0.dp
Expand All @@ -296,11 +296,10 @@ fun SnackImage(
) {
AsyncImage(
JolandaVerhoef marked this conversation as resolved.
Show resolved Hide resolved
model = ImageRequest.Builder(LocalContext.current)
.data(imageUrl)
.data(imageRes)
.crossfade(true)
.build(),
contentDescription = contentDescription,
JolandaVerhoef marked this conversation as resolved.
Show resolved Hide resolved
placeholder = painterResource(R.drawable.placeholder),
modifier = Modifier.fillMaxSize(),
contentScale = ContentScale.Crop,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ fun CartItem(
val (divider, image, name, tag, priceSpacer, price, remove, quantity) = createRefs()
createVerticalChain(name, tag, priceSpacer, price, chainStyle = ChainStyle.Packed)
SnackImage(
imageUrl = snack.imageUrl,
imageRes = snack.imageRes,
contentDescription = null,
modifier = Modifier
.size(100.dp)
Expand Down
Loading