Skip to content

Commit

Permalink
#16 착한밥상 & 예비착한 밥상 페이지 구현 (수정)
Browse files Browse the repository at this point in the history
  • Loading branch information
seoyeonsw committed Nov 7, 2024
1 parent 5b977f9 commit 442a37f
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.navigation.compose.rememberNavController
import coil.compose.AsyncImage
import com.hackathon.alddeul_babsang.R
import com.hackathon.alddeul_babsang.core_ui.theme.AlddeulBabsangTheme
Expand All @@ -38,16 +37,15 @@ import com.hackathon.alddeul_babsang.core_ui.theme.Orange900
import com.hackathon.alddeul_babsang.core_ui.theme.body2Regular
import com.hackathon.alddeul_babsang.core_ui.theme.body4Regular
import com.hackathon.alddeul_babsang.core_ui.theme.head4Bold
import com.hackathon.alddeul_babsang.domain.entity.BabsangListEntity
import com.hackathon.alddeul_babsang.presentation.babsang.navigation.BabsangNavigator
import com.hackathon.alddeul_babsang.domain.entity.LikesEntity
import com.hackathon.alddeul_babsang.presentation.profile.screen.LikeItem

@Composable
fun BabsangListItem(
navigator: BabsangNavigator,
data: BabsangListEntity
onClick: () -> Unit = {},
data: LikesEntity
) {

var isFavorite by remember { mutableStateOf(data.favorite ?: false) }
var isFavorite by remember { mutableStateOf(data.favorite) }

// 클릭할 때마다 favorite 값 토글
val heartIconId = if (isFavorite) {
Expand All @@ -56,7 +54,6 @@ fun BabsangListItem(
R.drawable.ic_heart_white
}


Column(
modifier = Modifier
.fillMaxWidth()
Expand All @@ -65,10 +62,7 @@ fun BabsangListItem(
color = Orange700,
shape = RoundedCornerShape(14.dp)
)
.height(240.dp)
.clickable(onClick = {
navigator.navigateDetail(data.id)
})
.clickable(onClick = { onClick() })
) {
Box(
modifier = Modifier
Expand All @@ -77,33 +71,28 @@ fun BabsangListItem(
.clip(RoundedCornerShape(topStart = 14.dp, topEnd = 14.dp))
) {
// AsyncImage 로드
ReplaceBabsangListImage(data.codeName, data.avatar)

ReplaceImage2(data.codeName, data.avatar)
Image(
painter = painterResource(heartIconId),
contentDescription = null,
modifier = Modifier
.padding(end = 10.dp, top = 10.dp)
.align(Alignment.TopEnd) // Box 내에서 오른쪽 끝으로 배치
.align(Alignment.TopEnd)
.clickable {
// 클릭 시 좋아요 상태를 토글
isFavorite = !isFavorite
}
)
}

Spacer(modifier = Modifier.height(15.dp))

Row {
Text(
text = data.name,
style = head4Bold,
color = Orange900,
modifier = Modifier.padding(start = 20.dp)
)

Spacer(modifier = Modifier.width(15.dp))

Text(
text = data.codeName,
style = body2Regular,
Expand All @@ -113,37 +102,32 @@ fun BabsangListItem(
.padding(bottom = 3.dp)
)
}

Spacer(modifier = Modifier.height(12.dp))

Text(
text = data.address,
style = body4Regular,
color = Gray300,
modifier = Modifier.padding(start = 20.dp)
)

Spacer(modifier = Modifier.height(7.dp))

Text(
text = data.phone,
style = body4Regular,
color = Gray300,
modifier = Modifier.padding(start = 20.dp)
modifier = Modifier.padding(start = 20.dp, bottom = 20.dp)
)
}
}

@Composable
fun ReplaceBabsangListImage(codeName: String, imageUrl: String?) {
fun ReplaceImage2(codeName: String, imageUrl: String?) {
val imageId = when (codeName) {
"경양식/일식" -> R.drawable.ic_japanese_food
"한식" -> R.drawable.ic_korean_food
"중식" -> R.drawable.ic_chinese_food
else -> R.drawable.ic_etc_food
}


Box(
modifier = Modifier
.fillMaxWidth()
Expand Down Expand Up @@ -171,23 +155,17 @@ fun ReplaceBabsangListImage(codeName: String, imageUrl: String?) {
.fillMaxWidth() // 가로는 꽉 차게
.fillMaxHeight() // 세로도 꽉 차게
.clip(RoundedCornerShape(topStart = 14.dp, topEnd = 14.dp))

)

}
}
}

@Preview(showBackground = true)
@Composable
fun BabsangListItemPreview() {
val navController = rememberNavController()
val navigator = BabsangNavigator(navController)

AlddeulBabsangTheme {
BabsangListItem(
navigator = navigator,
data = BabsangListEntity(
LikeItem(
data = LikesEntity(
id = 1,
avatar = null,
name = "송이네 밥상",
Expand All @@ -198,4 +176,4 @@ fun BabsangListItemPreview() {
)
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ package com.hackathon.alddeul_babsang.presentation.babsang.screen

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column

import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
Expand All @@ -17,21 +15,14 @@ import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.focus.focusModifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.navigation.compose.rememberNavController
import coil.compose.AsyncImage
import com.hackathon.alddeul_babsang.R
import com.hackathon.alddeul_babsang.core_ui.theme.AlddeulBabsangTheme
Expand All @@ -48,29 +39,25 @@ import com.hackathon.alddeul_babsang.core_ui.theme.body4Regular
import com.hackathon.alddeul_babsang.core_ui.theme.body7Semi
import com.hackathon.alddeul_babsang.core_ui.theme.head4Bold
import com.hackathon.alddeul_babsang.core_ui.theme.head5Bold
import com.hackathon.alddeul_babsang.domain.entity.BabsangListEntity
import com.hackathon.alddeul_babsang.domain.entity.BabsangRecommendEntity
import com.hackathon.alddeul_babsang.presentation.babsang.navigation.BabsangNavigator

@Composable
fun BabsangRecommendItem(
navigator: BabsangNavigator,
onClick: () -> Unit = {},
data: BabsangRecommendEntity
) {

Column(
modifier = Modifier
.width(170.dp)
.height(192.dp)
.clickable(onClick = {
navigator.navigateDetail(data.id)
})
.clickable(onClick = { onClick() })
) {
Box(
modifier = Modifier
.fillMaxWidth()
.fillMaxHeight()
.clip(RoundedCornerShape(10.dp))
.clip(RoundedCornerShape(14.dp))
) {
// AsyncImage 로드
ReplaceImage(data.codeName, data.avatar)
Expand All @@ -84,7 +71,7 @@ fun BabsangRecommendItem(
modifier = Modifier
.width(34.dp)
.height(17.dp)
.clip(RoundedCornerShape(50.dp))
.clip(RoundedCornerShape(6.dp))
.background(White),
contentAlignment = Alignment.Center

Expand Down Expand Up @@ -196,12 +183,8 @@ fun ReplaceImage(codeName: String, imageUrl: String?) {
@Preview(showBackground = true)
@Composable
fun BabsangRecommendItemPreview() {
val navController = rememberNavController()
val navigator = BabsangNavigator(navController)

AlddeulBabsangTheme {
BabsangRecommendItem(
navigator = navigator,
data = BabsangRecommendEntity(
id = 1,
avatar = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.hackathon.alddeul_babsang.presentation.babsang.screen

import androidx.lifecycle.ViewModel
import com.hackathon.alddeul_babsang.domain.entity.BabsangListEntity
import com.hackathon.alddeul_babsang.domain.entity.BabsangRecommendEntity
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
Expand Down
Loading

0 comments on commit 442a37f

Please sign in to comment.