Skip to content

Commit

Permalink
#11 프로필 & 좋아요 리스트 페이지 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
seoyeonsw committed Nov 6, 2024
1 parent ed9f7fd commit c0f7b4e
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 144 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.hackathon.alddeul_babsang.domain.entity

data class ProfileLikeListEntity(
val id: Long,
val avatar: String? = null,
val name: String,
val codeName: String,
val address: String,
val phone: String,
val favorite: Boolean=false,
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,15 @@ import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import com.hackathon.alddeul_babsang.presentation.profile.screen.ProfileLikeListRoute
import com.hackathon.alddeul_babsang.presentation.profile.screen.ProfileRoute
import com.hackathon.alddeul_babsang.presentation.report.navigation.ReportNavigator
import com.hackathon.alddeul_babsang.presentation.report.screen.ReportWriteRoute


fun NavGraphBuilder.profileNavGraph(
navigator: ProfileNavigator
) {
composable(route = "profile") {
ProfileRoute(navigator = navigator)
}
}

fun NavGraphBuilder.profileLikeListNavGraph(
navigator: ProfileNavigator
) {
composable(route = "profileLikeList") {
ProfileLikeListRoute(navigator = navigator)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ class ProfileNavigator(
val navController: NavController
) {

fun profileLikeList() {
navController.navigate("profileLikeList")
}

fun navigateBack() {
navController.popBackStack()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.hackathon.alddeul_babsang.presentation.profile.screen
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement.Bottom
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
Expand All @@ -12,49 +12,47 @@ import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
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.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import coil.compose.AsyncImage
import com.hackathon.alddeul_babsang.R
import com.hackathon.alddeul_babsang.core_ui.theme.AlddeulBabsangTheme
import com.hackathon.alddeul_babsang.core_ui.theme.Font_B04
import com.hackathon.alddeul_babsang.core_ui.theme.Gray200
import com.hackathon.alddeul_babsang.core_ui.theme.Gray300
import com.hackathon.alddeul_babsang.core_ui.theme.Gray600
import com.hackathon.alddeul_babsang.core_ui.theme.Orange700
import com.hackathon.alddeul_babsang.core_ui.theme.Orange800
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.body3Semi
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.BabsangDetailEntity
import com.hackathon.alddeul_babsang.domain.entity.ReviewEntity
import com.hackathon.alddeul_babsang.presentation.detail.screen.DetailViewModel
import kotlin.math.round
import com.hackathon.alddeul_babsang.domain.entity.ProfileLikeListEntity

@Composable
fun LikeItem(
data: BabsangDetailEntity
data: ProfileLikeListEntity
) {
var isFavorite by remember { mutableStateOf(data.favorite ?: false) }

// 클릭할 때마다 favorite 값 토글
val heartIconId = if (isFavorite) {
R.drawable.ic_heart_red
} else {
R.drawable.ic_heart_white
}


Column(
modifier = Modifier
.width(350.dp)
Expand All @@ -71,16 +69,19 @@ fun LikeItem(
.height(140.dp)
.clip(RoundedCornerShape(topStart = 14.dp, topEnd = 14.dp))
) {
// AsyncImage 로드를 위한 함수 호출
// AsyncImage 로드
LoadImageWithPlaceholder(data.codeName, data.avatar)

// 아이콘을 이미지 위에 오버레이
Image(
painter = painterResource(id = R.drawable.ic_heart_white),
painter = painterResource(heartIconId),
contentDescription = null,
modifier = Modifier
.padding(end = 10.dp, top = 10.dp)
.align(Alignment.TopEnd) // Box 내에서 오른쪽 끝으로 배치
.clickable {
// 클릭 시 좋아요 상태를 토글
isFavorite = !isFavorite
}
)
}

Expand Down Expand Up @@ -128,55 +129,63 @@ fun LikeItem(

@Composable
fun LoadImageWithPlaceholder(codeName: String, imageUrl: String?) {
var imageId =R.drawable.ic_korean_food
if (codeName =="경양식/일식"){
imageId=R.drawable.ic_japanese_food
}
else if (codeName =="한식"){
imageId=R.drawable.ic_korean_food
}
else if (codeName =="중식"){
imageId=R.drawable.ic_chinese_food
}
else {
imageId=R.drawable.ic_etc_food
var imageId = R.drawable.ic_korean_food
if (codeName == "경양식/일식") {
imageId = R.drawable.ic_japanese_food
} else if (codeName == "한식") {
imageId = R.drawable.ic_korean_food
} else if (codeName == "중식") {
imageId = R.drawable.ic_chinese_food
} else {
imageId = R.drawable.ic_etc_food
}


Box(
modifier = Modifier
.fillMaxWidth()
.fillMaxHeight()
.background(color= Orange700) // 배경색 설정
.background(color = Orange700) // 배경색 설정
) {
AsyncImage(
model = imageUrl,
contentDescription = null,
placeholder = painterResource(id = imageId), // codeName에 따라 다른 placeholder 제공
modifier = Modifier
.fillMaxWidth()
.fillMaxHeight()
.padding(vertical = 15.dp)
)
if (imageUrl.isNullOrEmpty()) {
// imageUrl이 null이나 empty일 경우 대체 이미지 표시
Image(
painter = painterResource(id = imageId), // 대체 이미지
contentDescription = null,
modifier = Modifier
.fillMaxWidth()
.fillMaxHeight()
.padding(vertical = 15.dp)
)
} else {
// imageUrl이 null이 아니면 AsyncImage로 비동기 이미지 로드
AsyncImage(
model = imageUrl,
contentDescription = null,
placeholder = painterResource(id = imageId), // codeName에 따라 다른 placeholder 제공
contentScale = ContentScale.Crop,
modifier = Modifier
.fillMaxWidth()
.fillMaxHeight()
.padding(vertical = 15.dp)
)
}
}
}

@Preview(showBackground = true)
@Composable
fun ReviewItemPreview() {
val LikeListViewModel: LikeListViewModel = hiltViewModel()
AlddeulBabsangTheme {
LikeItem(
data = BabsangDetailEntity(
data = ProfileLikeListEntity(
id = 1,
avatar = "",
avatar = null,
name = "송이네 밥상",
codeName = "경양식/일식",
address = "서울특별시 용산구 청파동 11",
phone = "02-210-0220",
rating = 4.3,
menu = "김치찌개: 8000, 된장찌개 9000",
review = LikeListViewModel.mockReviews
favorite = true
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,87 +2,60 @@ package com.hackathon.alddeul_babsang.presentation.profile.screen


import androidx.lifecycle.ViewModel
import com.hackathon.alddeul_babsang.domain.entity.BabsangDetailEntity
import com.hackathon.alddeul_babsang.domain.entity.MenuEntity
import com.hackathon.alddeul_babsang.domain.entity.ReviewEntity
import com.hackathon.alddeul_babsang.domain.entity.ProfileLikeListEntity
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class LikeListViewModel @Inject constructor() : ViewModel() {
val mockMenuList = listOf(
MenuEntity("김치찌개", 8000),
MenuEntity("된장찌개", 9000),
)

val mockReviews = listOf(
ReviewEntity(
id = 1,
avatar = "https://avatars.githubusercontent.com/u/12345678?v=4",
nickname = "김개발",
createdAt = "24.03.12",
star = 4.56,
content = "맛있어요!"
),
ReviewEntity(
id = 2,
avatar = "https://avatars.githubusercontent.com/u/12345678?v=4",
nickname = "김디자인",
createdAt = "24.03.12",
star = 3.28,
content = "그저 그랬어요 블라블라블라!"
),
ReviewEntity(
id = 3,
avatar = "https://avatars.githubusercontent.com/u/12345678?v=4",
nickname = "김마케팅",
createdAt = "24.03.12",
star = 2.49,
content = "위생이 별로에요!"
),

)

val mockLikeList = listOf(
BabsangDetailEntity(
id = 1,
ProfileLikeListEntity(
id=1,
avatar = null,
name = "송이네 밥상",
codeName = "기타외식업",
address = "서울특별시 용산구 청파동 81",
phone = "02-210-0120",
favorite = true
),
ProfileLikeListEntity(
id=2,
avatar = null,
name = "송이네 일식",
codeName = "경양식/일식",
address = "서울특별시 용산구 청파동 1211",
phone = "02-295-0220",
rating = 4.3,
menu = "김치찌개: 8000, 된장찌개 9000",
review = mockReviews
address = "서울특별시 용산구 청파동 11",
phone = "02-210-0220",
favorite = true
),
BabsangDetailEntity(
id = 2,
name = "송이네 밥상2",
ProfileLikeListEntity(
id=3,
avatar = null,
name = "송이네 한식",
codeName = "한식",
address = "서울특별시 용산구 청파동 911",
phone = "02-230-0220",
rating = 4.3,
menu = "김치찌개: 8000, 된장찌개 9000",
review = mockReviews
address = "서울특별시 용산구 청파동 31",
phone = "02-223-0220",
favorite = true
),
BabsangDetailEntity(
id = 3,
name = "송이네 밥상3",
ProfileLikeListEntity(
id=4,
avatar = null,
name = "송이네 중식",
codeName = "중식",
address = "서울특별시 용산구 청파동 321",
phone = "02-210-2097",
rating = 4.3,
menu = "김치찌개: 8000, 된장찌개 9000",
review = mockReviews
address = "서울특별시 용산구 청파동 31",
phone = "02-223-0220",
favorite = true
),
BabsangDetailEntity(
id = 4,
name = "송이네 밥상4",
codeName = "기타외식업",
address = "서울특별시 용산구 청파동 14",
phone = "02-210-0270",
rating = 4.3,
menu = "김치찌개: 8000, 된장찌개 9000",
review = mockReviews
ProfileLikeListEntity(
id=4,
avatar = "https://avatars.githubusercontent.com/u/166610834?s=400&u=568eacc2e4696d563a4fd732c148edba2196e4f6&v=4",
name = "송이네 밥상",
codeName = "중식",
address = "서울특별시 용산구 청파동 31",
phone = "02-223-0220",
favorite = true
)

)
}
Loading

0 comments on commit c0f7b4e

Please sign in to comment.