feat(ui): show product images in list/detail
This commit is contained in:
1 parent
035d396eaf
commit
575c26eaf5
3 files changed
+24
-7
No files matched your search
@@ -43,6 +43,7 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import coil3.compose.AsyncImage
|
||||
import com.example.minishop.cart.CartItem
|
||||
import com.example.minishop.cart.CartRepository
|
||||
import com.example.minishop.checkout.CheckoutService
|
||||
@@ -247,6 +248,7 @@ private fun ProductListScreen(
|
||||
items(products) { p ->
|
||||
ElevatedCard(onClick = { onClick(p) }, modifier = Modifier.fillMaxWidth()) {
|
||||
Column(Modifier.padding(12.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
ProductCover(p.imageUrl)
|
||||
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) {
|
||||
Text(p.title, style = MaterialTheme.typography.titleMedium, fontWeight = FontWeight.SemiBold)
|
||||
PriceTag(p.price)
|
||||
@@ -297,6 +299,7 @@ private fun ProductDetailScreen(
|
||||
shape = RoundedCornerShape(14.dp)
|
||||
) {
|
||||
Column(Modifier.padding(14.dp), verticalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||
ProductCover(product.imageUrl)
|
||||
Text(product.title, style = MaterialTheme.typography.headlineSmall, fontWeight = FontWeight.Bold)
|
||||
PriceTag(product.price)
|
||||
Text(product.description)
|
||||
@@ -382,6 +385,18 @@ private fun CartScreen(
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ProductCover(url: String) {
|
||||
AsyncImage(
|
||||
model = if (url.isNotBlank()) url else "https://picsum.photos/seed/fallback/600/360",
|
||||
contentDescription = null,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(150.dp)
|
||||
.clip(RoundedCornerShape(12.dp))
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SmallOpButton(text: String, onClick: () -> Unit) {
|
||||
OutlinedButton(onClick = onClick) {
|
||||
|
||||
@@ -12,5 +12,7 @@ data class Product(
|
||||
@SerialName("price")
|
||||
val price: Double,
|
||||
@SerialName("description")
|
||||
val description: String
|
||||
val description: String,
|
||||
@SerialName("imageUrl")
|
||||
val imageUrl: String = ""
|
||||
)
|
||||
@@ -16,11 +16,11 @@ class ProductApi(
|
||||
}
|
||||
|
||||
private fun mockProducts(): List<Product> = listOf(
|
||||
Product("1", "KMP 入门课", 99.0, "跨平台开发基础课程"),
|
||||
Product("2", "Compose 实战课", 149.0, "Compose 多端 UI 实战"),
|
||||
Product("3", "Kotlin 协程训练营", 129.0, "协程与 Flow 进阶"),
|
||||
Product("4", "Clean 架构速成", 199.0, "从0构建可维护架构"),
|
||||
Product("5", "SQLDelight 实战", 119.0, "KMP 本地数据库方案"),
|
||||
Product("6", "Ktor API 实战", 159.0, "跨平台网络层搭建")
|
||||
Product("1", "KMP 入门课", 99.0, "跨平台开发基础课程", "https://picsum.photos/seed/kmp1/600/360"),
|
||||
Product("2", "Compose 实战课", 149.0, "Compose 多端 UI 实战", "https://picsum.photos/seed/kmp2/600/360"),
|
||||
Product("3", "Kotlin 协程训练营", 129.0, "协程与 Flow 进阶", "https://picsum.photos/seed/kmp3/600/360"),
|
||||
Product("4", "Clean 架构速成", 199.0, "从0构建可维护架构", "https://picsum.photos/seed/kmp4/600/360"),
|
||||
Product("5", "SQLDelight 实战", 119.0, "KMP 本地数据库方案", "https://picsum.photos/seed/kmp5/600/360"),
|
||||
Product("6", "Ktor API 实战", 159.0, "跨平台网络层搭建", "https://picsum.photos/seed/kmp6/600/360")
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user