1
+ package com.everymeal.presentation.components
2
+
3
+ import androidx.compose.foundation.Image
4
+ import androidx.compose.foundation.background
5
+ import androidx.compose.foundation.layout.Arrangement
6
+ import androidx.compose.foundation.layout.Box
7
+ import androidx.compose.foundation.layout.Column
8
+ import androidx.compose.foundation.layout.Row
9
+ import androidx.compose.foundation.layout.Spacer
10
+ import androidx.compose.foundation.layout.aspectRatio
11
+ import androidx.compose.foundation.layout.fillMaxSize
12
+ import androidx.compose.foundation.layout.fillMaxWidth
13
+ import androidx.compose.foundation.layout.padding
14
+ import androidx.compose.foundation.shape.RoundedCornerShape
15
+ import androidx.compose.material3.Text
16
+ import androidx.compose.runtime.Composable
17
+ import androidx.compose.ui.Alignment
18
+ import androidx.compose.ui.Modifier
19
+ import androidx.compose.ui.draw.clip
20
+ import androidx.compose.ui.graphics.Color
21
+ import androidx.compose.ui.graphics.vector.ImageVector
22
+ import androidx.compose.ui.res.painterResource
23
+ import androidx.compose.ui.res.stringResource
24
+ import androidx.compose.ui.res.vectorResource
25
+ import androidx.compose.ui.text.font.FontWeight
26
+ import androidx.compose.ui.tooling.preview.Preview
27
+ import androidx.compose.ui.unit.dp
28
+ import androidx.compose.ui.unit.sp
29
+ import com.everymeal.presentation.R
30
+ import com.everymeal.presentation.ui.home.HomeScreen
31
+ import com.everymeal.presentation.ui.home.Restaurant
32
+ import com.everymeal.presentation.ui.theme.EveryMeal_AndroidTheme
33
+ import com.everymeal.presentation.ui.theme.Gray300
34
+ import com.everymeal.presentation.ui.theme.Gray500
35
+ import com.everymeal.presentation.ui.theme.Gray600
36
+ import com.everymeal.presentation.ui.theme.Gray700
37
+
38
+ @Composable
39
+ fun EveryMealRestaurantItem (
40
+ restaurant : Restaurant ,
41
+ onLoveClick : () -> Unit ,
42
+ ) {
43
+ Column (
44
+ modifier = Modifier
45
+ .fillMaxSize()
46
+ .padding(horizontal = 20 .dp)
47
+ .background(color = Color .White )
48
+ ) {
49
+ RestaurantTitle (restaurant)
50
+ Spacer (modifier = Modifier .padding(4 .dp))
51
+ RestaurantInfo (restaurant)
52
+ Spacer (modifier = Modifier .padding(4 .dp))
53
+ RestaurantImage (restaurant)
54
+ }
55
+ }
56
+
57
+ @Composable
58
+ fun RestaurantTitle (restaurant : Restaurant ) {
59
+ Row (
60
+ modifier = Modifier .fillMaxWidth(),
61
+ verticalAlignment = Alignment .CenterVertically ,
62
+ ) {
63
+ Text (
64
+ text = restaurant.name,
65
+ color = Color .Black ,
66
+ fontSize = 17 .sp,
67
+ fontWeight = FontWeight .SemiBold ,
68
+ )
69
+ Text (
70
+ modifier = Modifier
71
+ .padding(start = 4 .dp)
72
+ .clip(RoundedCornerShape (4 .dp))
73
+ .background(color = Gray300 )
74
+ .padding(vertical = 3 .dp, horizontal = 6 .dp),
75
+ text = restaurant.category,
76
+ color = Gray600 ,
77
+ fontSize = 12 .sp
78
+ )
79
+ Spacer (modifier = Modifier .weight(1f ))
80
+ Image (
81
+ modifier = Modifier
82
+ .padding(start = 4 .dp),
83
+ imageVector = ImageVector .vectorResource(R .drawable.icon_heart_mono),
84
+ contentDescription = stringResource(R .string.icon_star),
85
+ )
86
+ }
87
+ }
88
+
89
+ @Composable
90
+ fun RestaurantInfo (restaurant : Restaurant ) {
91
+ Row (
92
+ modifier = Modifier .fillMaxWidth(),
93
+ verticalAlignment = Alignment .CenterVertically ,
94
+ ) {
95
+ Image (
96
+ imageVector = ImageVector .vectorResource(R .drawable.icon_star_mono),
97
+ contentDescription = stringResource(R .string.icon_star),
98
+ )
99
+ Text (
100
+ modifier = Modifier .padding(start = 2 .dp),
101
+ text = restaurant.rating.toString(),
102
+ color = Gray700 ,
103
+ fontSize = 12 .sp,
104
+ fontWeight = FontWeight .Medium ,
105
+ )
106
+ Text (
107
+ modifier = Modifier .padding(start = 2 .dp),
108
+ text = " (${restaurant.reviewCount} )" ,
109
+ color = Gray700 ,
110
+ fontSize = 12 .sp,
111
+ fontWeight = FontWeight .Medium ,
112
+ )
113
+ Spacer (modifier = Modifier .weight(1f ))
114
+ Text (
115
+ text = " ${restaurant.loveCount} " ,
116
+ color = Gray500 ,
117
+ fontSize = 12 .sp,
118
+ fontWeight = FontWeight .Medium ,
119
+ )
120
+ }
121
+ }
122
+
123
+ @Composable
124
+ fun RestaurantImage (restaurant : Restaurant ) {
125
+ Row (
126
+ modifier = Modifier .fillMaxWidth(),
127
+ horizontalArrangement = Arrangement .SpaceBetween
128
+ ) {
129
+ when {
130
+ restaurant.image.size == 3 -> {
131
+ restaurant.image.forEach { image ->
132
+ Image (
133
+ modifier = Modifier
134
+ .weight(1f )
135
+ .aspectRatio(1f )
136
+ .clip(RoundedCornerShape (8 .dp))
137
+ .padding(4 .dp),
138
+ painter = painterResource(id = image),
139
+ contentDescription = null
140
+ )
141
+ }
142
+ }
143
+
144
+ restaurant.image.size == 2 -> {
145
+ restaurant.image.forEach { image ->
146
+ Image (
147
+ modifier = Modifier
148
+ .weight(1f )
149
+ .aspectRatio(1f )
150
+ .clip(RoundedCornerShape (8 .dp))
151
+ .padding(4 .dp),
152
+ painter = painterResource(id = image),
153
+ contentDescription = null
154
+ )
155
+ }
156
+ Spacer (modifier = Modifier .weight(1f ))
157
+ }
158
+
159
+ restaurant.image.size == 1 -> {
160
+ Image (
161
+ modifier = Modifier
162
+ .weight(1f )
163
+ .aspectRatio(1f )
164
+ .clip(RoundedCornerShape (8 .dp))
165
+ .padding(4 .dp),
166
+ painter = painterResource(id = restaurant.image[0 ]),
167
+ contentDescription = null
168
+ )
169
+ Spacer (modifier = Modifier .weight(2f ))
170
+ }
171
+
172
+ restaurant.image.size > 3 -> {
173
+ Image (
174
+ modifier = Modifier
175
+ .weight(1f )
176
+ .aspectRatio(1f )
177
+ .clip(RoundedCornerShape (8 .dp))
178
+ .padding(4 .dp),
179
+ painter = painterResource(restaurant.image[0 ]),
180
+ contentDescription = null
181
+ )
182
+ Image (
183
+ modifier = Modifier
184
+ .weight(1f )
185
+ .aspectRatio(1f )
186
+ .clip(RoundedCornerShape (8 .dp))
187
+ .padding(4 .dp),
188
+ painter = painterResource(restaurant.image[1 ]),
189
+ contentDescription = null
190
+ )
191
+ Box (
192
+ modifier = Modifier
193
+ .weight(1f )
194
+ .aspectRatio(1f )
195
+ .padding(4 .dp)
196
+ ) {
197
+ Image (
198
+ modifier = Modifier
199
+ .aspectRatio(1f )
200
+ .fillMaxSize(),
201
+ painter = painterResource(id = restaurant.image[2 ]),
202
+ contentDescription = null
203
+ )
204
+ Box (
205
+ modifier = Modifier
206
+ .matchParentSize()
207
+ .clip(RoundedCornerShape (8 .dp))
208
+ .background(Color .Black .copy(alpha = 0.5f )),
209
+ contentAlignment = Alignment .Center
210
+ ) {
211
+ Text (
212
+ text = " +${restaurant.image.size - 2 } " ,
213
+ color = Color .White ,
214
+ fontSize = 14 .sp
215
+ )
216
+ }
217
+ }
218
+ }
219
+ }
220
+ }
221
+ }
222
+
223
+ @Preview
224
+ @Composable
225
+ fun EveryMealRestaurantItemPreview () {
226
+ EveryMealRestaurantItem (
227
+ Restaurant (
228
+ name = " 슈니" ,
229
+ category = " 한식" ,
230
+ image = listOf (
231
+ 1 ,
232
+ 2 ,
233
+ 3 ,
234
+ ),
235
+ rating = 4.5 ,
236
+ reviewCount = 100 ,
237
+ loveCount = 50 ,
238
+ )
239
+ ) {
240
+
241
+ }
242
+ }
243
+
244
+ @Preview
245
+ @Composable
246
+ fun HomeScreenPreview () {
247
+ EveryMeal_AndroidTheme {
248
+ HomeScreen ()
249
+ }
250
+ }
0 commit comments