From 3c920c7e9e4d5f4cdad212f443f7432500761f43 Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Sat, 11 Nov 2023 23:29:33 +0900 Subject: [PATCH 01/68] =?UTF-8?q?ItemRatingStars(Compose)=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20(=EB=93=9C=EB=9E=98=EA=B7=B8=20=EB=B6=88=EA=B0=80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../compose/ui/review/ItemRatingStars.kt | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemRatingStars.kt diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemRatingStars.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemRatingStars.kt new file mode 100644 index 00000000..f97e3775 --- /dev/null +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemRatingStars.kt @@ -0,0 +1,75 @@ +package com.wafflestudio.siksha2.compose.ui.review + +import androidx.compose.foundation.Image +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.lazy.LazyRow +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import com.wafflestudio.siksha2.R +import kotlin.math.roundToInt + +@Composable +fun ItemReviewSingleStar( + modifier: Modifier = Modifier, + flag: Int +){ + Image( + painter = painterResource( + when { + flag <= 0 -> R.drawable.ic_full_star + flag == 1 -> R.drawable.ic_half_star + else -> R.drawable.ic_empty_star + } + ), + contentDescription = null, + modifier = modifier + ) +} + +@Composable +fun ItemReviewStars( + rating: Float, + dragEnabled: Boolean = false, + size: Int = 0 +) { + val rounds = (rating * 2).roundToInt() + val starMeasure = when(size) { + 2 -> 48.dp + 1 -> 33.dp + else -> 18.dp + } + val gap = when(size) { + 2 -> 12.dp + 1 -> 8.dp + else -> 4.dp + } + LazyRow ( + horizontalArrangement = Arrangement.spacedBy(gap) + ) { + items(count = 5) { index -> + ItemReviewSingleStar( + flag = index*2 - rounds, + modifier = Modifier.width(starMeasure) + .height(starMeasure) + ) + } + } +} + +@Composable +@Preview +fun StarsPreview(){ + Column() { + ItemReviewStars(rating = 0.0f) + ItemReviewStars(rating = 1.0f, size = 2) + ItemReviewStars(rating = 2.5f, size = 1) + ItemReviewStars(rating = 3.5f) + ItemReviewStars(rating = 5.0f) + } +} From 135a253dc9cee9ab9cd680f1796389db519c12c9 Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Sat, 18 Nov 2023 11:20:13 +0900 Subject: [PATCH 02/68] =?UTF-8?q?ItemRatingStars=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wafflestudio/siksha2/compose/ui/review/ItemRatingStars.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemRatingStars.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemRatingStars.kt index f97e3775..5a490f0a 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemRatingStars.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemRatingStars.kt @@ -15,7 +15,7 @@ import com.wafflestudio.siksha2.R import kotlin.math.roundToInt @Composable -fun ItemReviewSingleStar( +private fun ItemReviewSingleStar( modifier: Modifier = Modifier, flag: Int ){ @@ -64,7 +64,7 @@ fun ItemReviewStars( @Composable @Preview -fun StarsPreview(){ +private fun StarsPreview(){ Column() { ItemReviewStars(rating = 0.0f) ItemReviewStars(rating = 1.0f, size = 2) From 090d2ec85ca13591ee1c8dc99c943f56e65e9e58 Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Wed, 29 Nov 2023 19:50:40 +0900 Subject: [PATCH 03/68] =?UTF-8?q?ItemRatingStars=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../siksha2/compose/ui/review/ItemRatingStars.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemRatingStars.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemRatingStars.kt index 5a490f0a..c648bc89 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemRatingStars.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemRatingStars.kt @@ -33,7 +33,7 @@ private fun ItemReviewSingleStar( } @Composable -fun ItemReviewStars( +fun ItemRatingStars( rating: Float, dragEnabled: Boolean = false, size: Int = 0 @@ -66,10 +66,10 @@ fun ItemReviewStars( @Preview private fun StarsPreview(){ Column() { - ItemReviewStars(rating = 0.0f) - ItemReviewStars(rating = 1.0f, size = 2) - ItemReviewStars(rating = 2.5f, size = 1) - ItemReviewStars(rating = 3.5f) - ItemReviewStars(rating = 5.0f) + ItemRatingStars(rating = 0.0f) + ItemRatingStars(rating = 1.0f, size = 2) + ItemRatingStars(rating = 2.5f, size = 1) + ItemRatingStars(rating = 3.5f) + ItemRatingStars(rating = 5.0f) } } From 9bfdc1809b069b8509d5804a781253f7d86e2004 Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Wed, 29 Nov 2023 19:51:42 +0900 Subject: [PATCH 04/68] =?UTF-8?q?ItemReview=20Composable=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20(=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=95=88=20?= =?UTF-8?q?=EB=B3=B4=EC=9E=84)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../siksha2/compose/ui/review/ItemReview.kt | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReview.kt diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReview.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReview.kt new file mode 100644 index 00000000..4fe2ec8b --- /dev/null +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReview.kt @@ -0,0 +1,98 @@ +package com.wafflestudio.siksha2.compose.ui.review + +import androidx.compose.foundation.Image +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.defaultMinSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.width +import androidx.compose.material.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.paint +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import com.wafflestudio.siksha2.R +import com.wafflestudio.siksha2.models.Review +import com.wafflestudio.siksha2.ui.SikshaColors +import com.wafflestudio.siksha2.utils.toKoreanDate +import com.wafflestudio.siksha2.utils.toLocalDateTime + +@Composable +fun ItemReview( + review: Review?, + modifier: Modifier = Modifier, + showImage: Boolean = true +){ + Column { + Box( + modifier = modifier + .fillMaxWidth() + .defaultMinSize(minHeight = 90.dp) + ) { + Spacer(modifier = Modifier.height(2.dp)) + Column { + Box ( + modifier = Modifier.fillMaxWidth() + ) { + Row ( + modifier = Modifier.align(Alignment.CenterStart) + ) { + Image( + modifier = Modifier.padding(bottom = 2.dp), + painter = painterResource(R.drawable.ic_review_profile), + contentDescription = "profilePic" + ) + Spacer(modifier = Modifier.width(7.dp)) + Column( + horizontalAlignment = Alignment.Start + ) { + Text( + text = "ID" + (review?.userId ?: "") + ) + ItemRatingStars(review?.score?.toFloat() ?: 0.0f) + } + } + Text( + text = review?.createdAt?.toLocalDateTime()?.toLocalDate()?.toKoreanDate() ?: "-", + modifier = Modifier.align(Alignment.TopEnd) + ) + } + Text( + text = review?.comment ?: "", + modifier = Modifier + .fillMaxWidth() + .defaultMinSize(minHeight = 80.dp) + .padding(horizontal = 16.dp, vertical = 2.dp) + .paint(painterResource(R.drawable.ic_speech_bubble)) + .padding(start = 30.dp, end = 10.dp, top = 10.dp, bottom = 10.dp), + color = SikshaColors.Gray800 + ) + } + Spacer(modifier = Modifier.height(10.dp)) + } + Spacer(modifier = Modifier.height(9.dp)) + } +} + +@Preview +@Composable +fun ItemReviewPreview(){ + ItemReview( + review = Review( + id = 0, + menuId = 0, + userId = 1234, + score = 5.0, + comment = "맛있어요", + createdAt = "2023-11-29T09:40:10.322Z", + etc = null + ) + ) +} From 0d80ba1a3fa12e8f664f336844bdf9376cd5dd10 Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Wed, 29 Nov 2023 20:12:21 +0900 Subject: [PATCH 05/68] =?UTF-8?q?ComposeUtil=20=EC=B6=94=EA=B0=80=20(dpToS?= =?UTF-8?q?p)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/wafflestudio/siksha2/utils/ComposeUtil.kt | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 app/src/main/java/com/wafflestudio/siksha2/utils/ComposeUtil.kt diff --git a/app/src/main/java/com/wafflestudio/siksha2/utils/ComposeUtil.kt b/app/src/main/java/com/wafflestudio/siksha2/utils/ComposeUtil.kt new file mode 100644 index 00000000..c8af0044 --- /dev/null +++ b/app/src/main/java/com/wafflestudio/siksha2/utils/ComposeUtil.kt @@ -0,0 +1,8 @@ +package com.wafflestudio.siksha2.utils + +import androidx.compose.runtime.Composable +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.unit.Dp + +@Composable +fun dpToSp(dp: Dp) = with(LocalDensity.current) { dp.toSp() } From b8917a36c3380429aa9acddee586412552460f74 Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Wed, 29 Nov 2023 21:01:53 +0900 Subject: [PATCH 06/68] =?UTF-8?q?ItemReview=20=EC=A1=B0=EA=B8=88=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../siksha2/compose/ui/review/ItemReview.kt | 40 ++++++++++++------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReview.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReview.kt index 4fe2ec8b..1609ae52 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReview.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReview.kt @@ -7,7 +7,6 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.defaultMinSize import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width import androidx.compose.material.Text @@ -15,12 +14,14 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.paint +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 com.wafflestudio.siksha2.R import com.wafflestudio.siksha2.models.Review import com.wafflestudio.siksha2.ui.SikshaColors +import com.wafflestudio.siksha2.utils.dpToSp import com.wafflestudio.siksha2.utils.toKoreanDate import com.wafflestudio.siksha2.utils.toLocalDateTime @@ -29,19 +30,21 @@ fun ItemReview( review: Review?, modifier: Modifier = Modifier, showImage: Boolean = true -){ - Column { +) { + Column( + modifier = Modifier.padding(bottom = 9.dp) + ) { Box( modifier = modifier .fillMaxWidth() .defaultMinSize(minHeight = 90.dp) + .padding(top = 2.dp, bottom = 10.dp) ) { - Spacer(modifier = Modifier.height(2.dp)) Column { - Box ( + Box( modifier = Modifier.fillMaxWidth() ) { - Row ( + Row( modifier = Modifier.align(Alignment.CenterStart) ) { Image( @@ -54,43 +57,52 @@ fun ItemReview( horizontalAlignment = Alignment.Start ) { Text( - text = "ID" + (review?.userId ?: "") + text = "ID" + (review?.userId ?: ""), + color = SikshaColors.Black900, + fontSize = dpToSp(12.dp) ) ItemRatingStars(review?.score?.toFloat() ?: 0.0f) } } Text( text = review?.createdAt?.toLocalDateTime()?.toLocalDate()?.toKoreanDate() ?: "-", - modifier = Modifier.align(Alignment.TopEnd) + modifier = Modifier + .align(Alignment.TopEnd) + .padding(end = 10.dp), + fontSize = dpToSp(12.dp), + color = SikshaColors.Gray500 ) } + // TODO: 말풍선 테두리 strokeWidth 말고 shadow로 처리하기 Text( text = review?.comment ?: "", modifier = Modifier .fillMaxWidth() .defaultMinSize(minHeight = 80.dp) .padding(horizontal = 16.dp, vertical = 2.dp) - .paint(painterResource(R.drawable.ic_speech_bubble)) + .paint( + painterResource(R.drawable.ic_speech_bubble), + contentScale = ContentScale.FillBounds + ) .padding(start = 30.dp, end = 10.dp, top = 10.dp, bottom = 10.dp), - color = SikshaColors.Gray800 + color = SikshaColors.Gray800, + fontSize = dpToSp(dp = 12.dp) ) } - Spacer(modifier = Modifier.height(10.dp)) } - Spacer(modifier = Modifier.height(9.dp)) } } @Preview @Composable -fun ItemReviewPreview(){ +fun ItemReviewPreview() { ItemReview( review = Review( id = 0, menuId = 0, userId = 1234, score = 5.0, - comment = "맛있어요", + comment = "그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 ", createdAt = "2023-11-29T09:40:10.322Z", etc = null ) From cbd78ef22bbb638c1a4ec572107bf482e9a45553 Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Wed, 29 Nov 2023 21:02:22 +0900 Subject: [PATCH 07/68] =?UTF-8?q?=EB=A7=90=ED=92=8D=EC=84=A0=20=ED=85=8C?= =?UTF-8?q?=EB=91=90=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/res/drawable/ic_speech_bubble.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/res/drawable/ic_speech_bubble.xml b/app/src/main/res/drawable/ic_speech_bubble.xml index 4fb8dcd4..0bedcd26 100644 --- a/app/src/main/res/drawable/ic_speech_bubble.xml +++ b/app/src/main/res/drawable/ic_speech_bubble.xml @@ -6,5 +6,7 @@ + android:fillType="evenOdd" + android:strokeColor="#26000000" + android:strokeWidth="0.5"/> From 23030502532c605f12d93eecc0a70dead40eccb6 Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Wed, 29 Nov 2023 21:13:30 +0900 Subject: [PATCH 08/68] formatting --- .../siksha2/compose/ui/review/ItemRatingStars.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemRatingStars.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemRatingStars.kt index c648bc89..1bba11e0 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemRatingStars.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemRatingStars.kt @@ -18,7 +18,7 @@ import kotlin.math.roundToInt private fun ItemReviewSingleStar( modifier: Modifier = Modifier, flag: Int -){ +) { Image( painter = painterResource( when { @@ -39,22 +39,22 @@ fun ItemRatingStars( size: Int = 0 ) { val rounds = (rating * 2).roundToInt() - val starMeasure = when(size) { + val starMeasure = when (size) { 2 -> 48.dp 1 -> 33.dp else -> 18.dp } - val gap = when(size) { + val gap = when (size) { 2 -> 12.dp 1 -> 8.dp else -> 4.dp } - LazyRow ( + LazyRow( horizontalArrangement = Arrangement.spacedBy(gap) ) { items(count = 5) { index -> ItemReviewSingleStar( - flag = index*2 - rounds, + flag = index * 2 - rounds, modifier = Modifier.width(starMeasure) .height(starMeasure) ) @@ -64,7 +64,7 @@ fun ItemRatingStars( @Composable @Preview -private fun StarsPreview(){ +private fun StarsPreview() { Column() { ItemRatingStars(rating = 0.0f) ItemRatingStars(rating = 1.0f, size = 2) From 4812a235765d9e48d5e22bbc36048b6a35beed62 Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Wed, 29 Nov 2023 21:37:13 +0900 Subject: [PATCH 09/68] =?UTF-8?q?coil=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle.kts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 88f46932..9b7bea9e 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -185,4 +185,8 @@ dependencies { implementation("androidx.paging:paging-compose:${Deps.Version.PagingCompose}") implementation("androidx.lifecycle:lifecycle-viewmodel-compose:${Deps.Version.ComposeViewModel}") implementation("androidx.hilt:hilt-navigation-compose:${Deps.Version.ComposeHiltNavigation}") + + // Coil + implementation("io.coil-kt:coil:2.5.0") + implementation("io.coil-kt:coil-compose:2.5.0") } From 79f0ef0a724f861e6a10199e92a59e0ec429cd3a Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Wed, 29 Nov 2023 22:22:27 +0900 Subject: [PATCH 10/68] =?UTF-8?q?ItemReviewImage=20Compose=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../compose/ui/review/ItemReviewImage.kt | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReviewImage.kt diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReviewImage.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReviewImage.kt new file mode 100644 index 00000000..6a37d6fc --- /dev/null +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReviewImage.kt @@ -0,0 +1,106 @@ +package com.wafflestudio.siksha2.compose.ui.review + +import android.net.Uri +import androidx.compose.foundation.Image +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material.Text +import androidx.compose.runtime.Composable +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.layout.ContentScale +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import androidx.compose.ui.zIndex +import coil.compose.rememberAsyncImagePainter +import com.wafflestudio.siksha2.R +import com.wafflestudio.siksha2.ui.SikshaColors +import com.wafflestudio.siksha2.utils.dpToSp + +@Composable +fun ItemReviewImage( + imageUri: Uri, + modifier: Modifier = Modifier, + onClick: () -> Unit = {}, + showMore: Int? = null, + deletable: Boolean = false +) { + Box( + modifier = modifier.padding(vertical = 4.dp) + .width(100.dp).height(100.dp) + .clip(shape = RoundedCornerShape(8.dp)) + ) { + Image( + modifier = Modifier.fillMaxSize() + .align(Alignment.Center), + painter = rememberAsyncImagePainter(imageUri), + contentDescription = null, + contentScale = ContentScale.Crop + ) + if (deletable) { + Image( + modifier = Modifier + .align(Alignment.TopEnd) + .clickable { onClick() }, + painter = painterResource(id = R.drawable.ic_image_delete), + contentDescription = null + ) + } + if (showMore != null) { + Box( + modifier = Modifier + .fillMaxSize() + .background(color = Color(0x80000000)) + .zIndex(1f) + .align(Alignment.Center) + ) { + Column( + modifier = Modifier.align(Alignment.Center), + horizontalAlignment = Alignment.CenterHorizontally + ) { + Text( + text = "+", + fontSize = dpToSp(12.dp), + color = SikshaColors.White900 + ) + Text( + text = showMore.toString() + "건 더 보기", + fontSize = dpToSp(12.dp), + color = SikshaColors.White900 + ) + } + } + } + } +} + +@Composable +@Preview +fun ItemReviewImagePreview() { + Column( + verticalArrangement = Arrangement.SpaceBetween + ) { + ItemReviewImage( + imageUri = Uri.parse("https://postfiles.pstatic.net/MjAyMzExMjVfMjkw/MDAxNzAwOTIyODAzODEw.QqyDtG40dMPBGRLsCcplMuOgz-wTVx6aZ4UeeykP65Qg.Hscm0YN_F9pcPE2lndK0YV8eDKz7m2Hi1RMa0ocu2Wog.JPEG.jyurisenpai/20231125010057_1.jpg?type=w773") + ) + ItemReviewImage( + imageUri = Uri.parse("https://postfiles.pstatic.net/MjAyMzExMjZfMjcy/MDAxNzAwOTI3NTczMDY5.c9qVmjXE0nBVZpKukBxB9EB0LytpB5Olc6psLGQdWLQg.-D-zLjlG7bIPYm8XmYzK9-l1vitTZAGcimoHM57QATAg.JPEG.jyurisenpai/20231121203650_1.jpg?type=w773"), + deletable = true + ) + ItemReviewImage( + imageUri = Uri.parse("https://postfiles.pstatic.net/MjAyMzExMjZfMjU5/MDAxNzAwOTI3MjgxMjAz.f7jMVmS7vYGWKWswaOnnxCjgmaN0qgSt0_2VLB-XZrog.WMa7r-nHh9zw_QXO15bA4ts2NabuiEtQQkM6XYSiA1Ug.JPEG.jyurisenpai/20231118200550_1.jpg?type=w773"), + showMore = 3 + ) + } +} From 783ca8ddbb137243985149d361d242a68a2ddff0 Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Tue, 5 Dec 2023 10:28:12 +0900 Subject: [PATCH 11/68] ReviewSpeechBubble --- .../compose/ui/review/ReviewSpeechBubble.kt | 38 +++++++++++++++++++ .../main/res/drawable/ic_speech_bubble.xml | 4 +- 2 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewSpeechBubble.kt diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewSpeechBubble.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewSpeechBubble.kt new file mode 100644 index 00000000..cf0c898c --- /dev/null +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewSpeechBubble.kt @@ -0,0 +1,38 @@ +package com.wafflestudio.siksha2.compose.ui.review + +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.offset +import androidx.compose.material.Icon +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.blur +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import com.wafflestudio.siksha2.R + +@Composable +fun ReviewSpeechBubble( + modifier: Modifier = Modifier +) { + Icon( + painter = painterResource(R.drawable.ic_speech_bubble), + contentDescription = null, + modifier = modifier.offset(x = (-1).dp, y = 1.dp) + .blur(10.dp), + tint = Color(0xff000000), + ) + Icon( + painter = painterResource(R.drawable.ic_speech_bubble), + contentDescription = null, + modifier = modifier, + tint = Color(0xffffffff) + ) +} + +@Composable +@Preview +fun ReviewSpeechBubblePreview() { + ReviewSpeechBubble(modifier = Modifier.fillMaxWidth()) +} diff --git a/app/src/main/res/drawable/ic_speech_bubble.xml b/app/src/main/res/drawable/ic_speech_bubble.xml index 0bedcd26..4fb8dcd4 100644 --- a/app/src/main/res/drawable/ic_speech_bubble.xml +++ b/app/src/main/res/drawable/ic_speech_bubble.xml @@ -6,7 +6,5 @@ + android:fillType="evenOdd"/> From 63865121387f98f219a63bbec8a394f9367909c8 Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Thu, 7 Dec 2023 17:03:29 +0900 Subject: [PATCH 12/68] ItemRatingStars fix --- .../siksha2/compose/ui/review/ItemRatingStars.kt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemRatingStars.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemRatingStars.kt index 1bba11e0..b6a0c955 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemRatingStars.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemRatingStars.kt @@ -3,9 +3,9 @@ package com.wafflestudio.siksha2.compose.ui.review import androidx.compose.foundation.Image import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.width -import androidx.compose.foundation.lazy.LazyRow import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource @@ -49,13 +49,14 @@ fun ItemRatingStars( 1 -> 8.dp else -> 4.dp } - LazyRow( + Row( horizontalArrangement = Arrangement.spacedBy(gap) ) { - items(count = 5) { index -> + for (i in 1..5){ ItemReviewSingleStar( - flag = index * 2 - rounds, - modifier = Modifier.width(starMeasure) + flag = i * 2 - rounds, + modifier = Modifier + .width(starMeasure) .height(starMeasure) ) } From 8929a2291b8c0c4a416a19fb22f6f6dd4c1d719d Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Thu, 7 Dec 2023 17:05:58 +0900 Subject: [PATCH 13/68] ReviewSpeechBubble --- .../compose/ui/review/ReviewSpeechBubble.kt | 58 ++++++++++++++----- .../main/res/drawable/ic_speech_bubble.xml | 3 +- 2 files changed, 44 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewSpeechBubble.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewSpeechBubble.kt index cf0c898c..e16841d5 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewSpeechBubble.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewSpeechBubble.kt @@ -1,12 +1,19 @@ package com.wafflestudio.siksha2.compose.ui.review +import androidx.compose.foundation.Image +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.offset -import androidx.compose.material.Icon import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.draw.blur import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.ColorFilter +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 @@ -16,23 +23,44 @@ import com.wafflestudio.siksha2.R fun ReviewSpeechBubble( modifier: Modifier = Modifier ) { - Icon( - painter = painterResource(R.drawable.ic_speech_bubble), - contentDescription = null, - modifier = modifier.offset(x = (-1).dp, y = 1.dp) - .blur(10.dp), - tint = Color(0xff000000), - ) - Icon( - painter = painterResource(R.drawable.ic_speech_bubble), - contentDescription = null, - modifier = modifier, - tint = Color(0xffffffff) - ) + Box( + modifier = modifier + ) { + Image( + painter = painterResource(R.drawable.ic_speech_bubble), + contentDescription = null, + contentScale = ContentScale.FillBounds, + modifier = Modifier + .fillMaxSize() + .offset(x = (-1).dp, y = 1.dp) + .blur(4.dp), + colorFilter = ColorFilter.tint(Color(0x26000000)) + ) + Image( + painter = painterResource(R.drawable.ic_speech_bubble), + contentDescription = null, + contentScale = ContentScale.FillBounds, + modifier = Modifier.fillMaxSize(), + colorFilter = ColorFilter.tint(Color(0xffffffff)) + ) + } } @Composable @Preview fun ReviewSpeechBubblePreview() { - ReviewSpeechBubble(modifier = Modifier.fillMaxWidth()) + Column { + ReviewSpeechBubble( + modifier = Modifier + .fillMaxWidth() + .height(80.dp) + .background(color = Color(0xff00ff00)) + ) + ReviewSpeechBubble( + modifier = Modifier + .fillMaxWidth() + .height(60.dp) + .background(color = Color(0xff0000ff)) + ) + } } diff --git a/app/src/main/res/drawable/ic_speech_bubble.xml b/app/src/main/res/drawable/ic_speech_bubble.xml index 4fb8dcd4..6935e40a 100644 --- a/app/src/main/res/drawable/ic_speech_bubble.xml +++ b/app/src/main/res/drawable/ic_speech_bubble.xml @@ -5,6 +5,5 @@ android:viewportHeight="75"> + android:fillColor="#ffffff"/> From 400909c862addc5bf3c9392944ac11ef80a40beb Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Thu, 7 Dec 2023 17:07:57 +0900 Subject: [PATCH 14/68] ItemReview --- .../siksha2/compose/ui/review/ItemReview.kt | 157 +++++++++++------- 1 file changed, 96 insertions(+), 61 deletions(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReview.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReview.kt index 1609ae52..35f29b2b 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReview.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReview.kt @@ -1,6 +1,8 @@ package com.wafflestudio.siksha2.compose.ui.review import androidx.compose.foundation.Image +import androidx.compose.foundation.background +import androidx.compose.foundation.horizontalScroll import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row @@ -9,12 +11,11 @@ import androidx.compose.foundation.layout.defaultMinSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width +import androidx.compose.foundation.rememberScrollState import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.draw.paint -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 @@ -32,62 +33,72 @@ fun ItemReview( showImage: Boolean = true ) { Column( - modifier = Modifier.padding(bottom = 9.dp) + modifier = modifier + .fillMaxWidth() + .background(color = SikshaColors.White900) + .padding(bottom = 10.dp) + .defaultMinSize(minHeight = 90.dp) + .padding(top = 2.dp, bottom = 10.dp) ) { Box( - modifier = modifier - .fillMaxWidth() - .defaultMinSize(minHeight = 90.dp) - .padding(top = 2.dp, bottom = 10.dp) + modifier = Modifier.fillMaxWidth() ) { - Column { - Box( - modifier = Modifier.fillMaxWidth() + Row( + modifier = Modifier.align(Alignment.CenterStart) + ) { + Image( + modifier = Modifier.padding(bottom = 2.dp), + painter = painterResource(R.drawable.ic_review_profile), + contentDescription = "profilePic" + ) + Spacer(modifier = Modifier.width(7.dp)) + Column( + horizontalAlignment = Alignment.Start ) { - Row( - modifier = Modifier.align(Alignment.CenterStart) - ) { - Image( - modifier = Modifier.padding(bottom = 2.dp), - painter = painterResource(R.drawable.ic_review_profile), - contentDescription = "profilePic" - ) - Spacer(modifier = Modifier.width(7.dp)) - Column( - horizontalAlignment = Alignment.Start - ) { - Text( - text = "ID" + (review?.userId ?: ""), - color = SikshaColors.Black900, - fontSize = dpToSp(12.dp) - ) - ItemRatingStars(review?.score?.toFloat() ?: 0.0f) - } - } Text( - text = review?.createdAt?.toLocalDateTime()?.toLocalDate()?.toKoreanDate() ?: "-", - modifier = Modifier - .align(Alignment.TopEnd) - .padding(end = 10.dp), - fontSize = dpToSp(12.dp), - color = SikshaColors.Gray500 + text = "ID" + (review?.userId ?: ""), + color = SikshaColors.Black900, + fontSize = dpToSp(12.dp) ) + ItemRatingStars(review?.score?.toFloat() ?: 0.0f) } - // TODO: 말풍선 테두리 strokeWidth 말고 shadow로 처리하기 - Text( - text = review?.comment ?: "", - modifier = Modifier - .fillMaxWidth() - .defaultMinSize(minHeight = 80.dp) - .padding(horizontal = 16.dp, vertical = 2.dp) - .paint( - painterResource(R.drawable.ic_speech_bubble), - contentScale = ContentScale.FillBounds - ) - .padding(start = 30.dp, end = 10.dp, top = 10.dp, bottom = 10.dp), - color = SikshaColors.Gray800, - fontSize = dpToSp(dp = 12.dp) - ) + } + Text( + text = review?.createdAt?.toLocalDateTime()?.toLocalDate()?.toKoreanDate() ?: "-", + modifier = Modifier + .align(Alignment.TopEnd) + .padding(end = 10.dp), + fontSize = dpToSp(12.dp), + color = SikshaColors.Gray500 + ) + } + Box ( + modifier = Modifier + .fillMaxWidth() + .defaultMinSize(80.dp) + .padding(horizontal = 16.dp, vertical = 2.dp) + ) { + ReviewSpeechBubble( + modifier = Modifier + .fillMaxWidth() + .matchParentSize() + ) + Text( + text = review?.comment ?: "", + modifier = Modifier + .align(Alignment.Center) + .fillMaxWidth() + .padding(start = 30.dp, end = 10.dp, top = 13.dp, bottom = 15.dp), + color = SikshaColors.Gray800, + fontSize = dpToSp(dp = 12.dp) + ) + } + if (showImage) { + Row( + modifier = Modifier + .padding(start = 13.dp) + .horizontalScroll(rememberScrollState()) + ) { } } } @@ -96,15 +107,39 @@ fun ItemReview( @Preview @Composable fun ItemReviewPreview() { - ItemReview( - review = Review( - id = 0, - menuId = 0, - userId = 1234, - score = 5.0, - comment = "그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 ", - createdAt = "2023-11-29T09:40:10.322Z", - etc = null + Column { + ItemReview( + review = Review( + id = 0, + menuId = 0, + userId = 1234, + score = 5.0, + comment = "그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 ", + createdAt = "2023-11-29T09:40:10.322Z", + etc = null + ) + ) + ItemReview( + review = Review( + id = 0, + menuId = 0, + userId = 1234, + score = 3.5, + comment = "그냥저냥 먹을만해요 ", + createdAt = "2023-11-29T09:40:10.322Z", + etc = null + ) ) - ) + ItemReview( + review = Review( + id = 0, + menuId = 0, + userId = 1234, + score = 1.0, + comment = "맛없어요\n\n\nㅠ", + createdAt = "2023-11-29T09:40:10.322Z", + etc = null + ) + ) + } } From 8cc5be11db36febcb609a7adc226d3dbf22aceff Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Thu, 7 Dec 2023 17:08:25 +0900 Subject: [PATCH 15/68] =?UTF-8?q?ReviewScreen=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt new file mode 100644 index 00000000..d172330c --- /dev/null +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt @@ -0,0 +1,7 @@ +package com.wafflestudio.siksha2.compose.ui.review + +import androidx.compose.runtime.Composable + +@Composable +fun ReviewScreen() { +} From a1242509bb9f3dc904519caccc9d5f32ebabae5f Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Thu, 7 Dec 2023 17:31:39 +0900 Subject: [PATCH 16/68] =?UTF-8?q?ItemReview=20=EC=82=AC=EC=A7=84=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../siksha2/compose/ui/review/ItemReview.kt | 23 +++++++++++++++---- .../compose/ui/review/ItemReviewImage.kt | 3 +-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReview.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReview.kt index 35f29b2b..3901f555 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReview.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReview.kt @@ -1,8 +1,10 @@ package com.wafflestudio.siksha2.compose.ui.review +import android.net.Uri import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.horizontalScroll +import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row @@ -20,6 +22,7 @@ import androidx.compose.ui.res.painterResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import com.wafflestudio.siksha2.R +import com.wafflestudio.siksha2.models.Etc import com.wafflestudio.siksha2.models.Review import com.wafflestudio.siksha2.ui.SikshaColors import com.wafflestudio.siksha2.utils.dpToSp @@ -75,7 +78,7 @@ fun ItemReview( Box ( modifier = Modifier .fillMaxWidth() - .defaultMinSize(80.dp) + .defaultMinSize(minHeight = 80.dp) .padding(horizontal = 16.dp, vertical = 2.dp) ) { ReviewSpeechBubble( @@ -96,9 +99,15 @@ fun ItemReview( if (showImage) { Row( modifier = Modifier - .padding(start = 13.dp) - .horizontalScroll(rememberScrollState()) + .padding(start = 20.dp) + .horizontalScroll(rememberScrollState()), + horizontalArrangement = Arrangement.spacedBy(4.dp) ) { + for(imageUri in review?.etc?.images ?: listOf()){ + ItemReviewImage( + imageUri = Uri.parse(imageUri) + ) + } } } } @@ -116,7 +125,13 @@ fun ItemReviewPreview() { score = 5.0, comment = "그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 ", createdAt = "2023-11-29T09:40:10.322Z", - etc = null + etc = Etc( + images = listOf( + "https://postfiles.pstatic.net/MjAyMzExMjZfMjcy/MDAxNzAwOTI3NTczMDY5.c9qVmjXE0nBVZpKukBxB9EB0LytpB5Olc6psLGQdWLQg.-D-zLjlG7bIPYm8XmYzK9-l1vitTZAGcimoHM57QATAg.JPEG.jyurisenpai/20231121203650_1.jpg?type=w773", + "https://postfiles.pstatic.net/MjAyMzExMjZfMjU5/MDAxNzAwOTI3MjgxMjAz.f7jMVmS7vYGWKWswaOnnxCjgmaN0qgSt0_2VLB-XZrog.WMa7r-nHh9zw_QXO15bA4ts2NabuiEtQQkM6XYSiA1Ug.JPEG.jyurisenpai/20231118200550_1.jpg?type=w773", + "https://postfiles.pstatic.net/MjAyMzExMjZfODAg/MDAxNzAwOTI5MDI4NDE3.kprldbXZmLtHlIh2AFuu9jCeWiXbXeO6pF5OpxpJB3Mg.U8aqpMqPJz4bORV05B8M8oVBF9KXTTJhY1oN17NlkaAg.JPEG.jyurisenpai/20231121211321_1.jpg?type=w773" + ) + ) ) ) ItemReview( diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReviewImage.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReviewImage.kt index 6a37d6fc..587cbde6 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReviewImage.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReviewImage.kt @@ -9,7 +9,6 @@ import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.Text @@ -37,7 +36,7 @@ fun ItemReviewImage( deletable: Boolean = false ) { Box( - modifier = modifier.padding(vertical = 4.dp) + modifier = modifier .width(100.dp).height(100.dp) .clip(shape = RoundedCornerShape(8.dp)) ) { From 9e87f4199e52e0b4387df57084e95b9faaba6b17 Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Sat, 9 Dec 2023 19:02:05 +0900 Subject: [PATCH 17/68] =?UTF-8?q?ItemReview=20=EC=82=AC=EC=A7=84=20?= =?UTF-8?q?=EC=97=AC=EB=B0=B1=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/wafflestudio/siksha2/compose/ui/review/ItemReview.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReview.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReview.kt index 3901f555..2be142df 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReview.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReview.kt @@ -99,7 +99,7 @@ fun ItemReview( if (showImage) { Row( modifier = Modifier - .padding(start = 20.dp) + .padding(start = 30.dp) .horizontalScroll(rememberScrollState()), horizontalArrangement = Arrangement.spacedBy(4.dp) ) { From be2d7521f4ae22040239b2ab59f73b0b9952d3ed Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Sat, 9 Dec 2023 19:48:42 +0900 Subject: [PATCH 18/68] =?UTF-8?q?OrangeMain=20=EA=B0=92=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/wafflestudio/siksha2/ui/SikshaColors.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/SikshaColors.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/SikshaColors.kt index 80fb89fa..40073f47 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/SikshaColors.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/SikshaColors.kt @@ -3,7 +3,7 @@ package com.wafflestudio.siksha2.ui import androidx.compose.ui.graphics.Color object SikshaColors { - val OrangeMain = Color(0xFFFF952B) + val OrangeMain = Color(0xFFFF9522) val White900 = Color(0xFFFFFFFF) From 809c582ea698fa3220d32cdd3ddc9aaf391b7cff Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Sat, 9 Dec 2023 20:58:12 +0900 Subject: [PATCH 19/68] =?UTF-8?q?ReviewScreen(=EB=A0=88=EC=9D=B4=EC=95=84?= =?UTF-8?q?=EC=9B=83=EB=A7=8C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../siksha2/compose/ui/review/ReviewScreen.kt | 150 +++++++++++++++++- 1 file changed, 149 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt index d172330c..3a03c75c 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt @@ -1,7 +1,155 @@ package com.wafflestudio.siksha2.compose.ui.review +import androidx.compose.foundation.Image +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.material.Text import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import com.wafflestudio.siksha2.R +import com.wafflestudio.siksha2.models.Etc +import com.wafflestudio.siksha2.models.Review +import com.wafflestudio.siksha2.ui.SikshaColors +import com.wafflestudio.siksha2.utils.dpToSp @Composable -fun ReviewScreen() { +fun ReviewScreen( + modifier: Modifier = Modifier, + //menuDetailViewModel: MenuDetailViewModel = hiltViewModel(), + showImages: Boolean = false +) { + // val reviews = menuDetailViewModel.getReviews(0).collectAsState(PagingData.empty()) + + // temporary reviews + val reviews = listOf( + Review( + id = 0, + menuId = 0, + userId = 1234, + score = 5.0, + comment = "그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 ", + createdAt = "2023-11-29T09:40:10.322Z", + etc = Etc( + images = listOf( + "https://postfiles.pstatic.net/MjAyMzExMjZfMjcy/MDAxNzAwOTI3NTczMDY5.c9qVmjXE0nBVZpKukBxB9EB0LytpB5Olc6psLGQdWLQg.-D-zLjlG7bIPYm8XmYzK9-l1vitTZAGcimoHM57QATAg.JPEG.jyurisenpai/20231121203650_1.jpg?type=w773", + "https://postfiles.pstatic.net/MjAyMzExMjZfMjU5/MDAxNzAwOTI3MjgxMjAz.f7jMVmS7vYGWKWswaOnnxCjgmaN0qgSt0_2VLB-XZrog.WMa7r-nHh9zw_QXO15bA4ts2NabuiEtQQkM6XYSiA1Ug.JPEG.jyurisenpai/20231118200550_1.jpg?type=w773", + "https://postfiles.pstatic.net/MjAyMzExMjZfODAg/MDAxNzAwOTI5MDI4NDE3.kprldbXZmLtHlIh2AFuu9jCeWiXbXeO6pF5OpxpJB3Mg.U8aqpMqPJz4bORV05B8M8oVBF9KXTTJhY1oN17NlkaAg.JPEG.jyurisenpai/20231121211321_1.jpg?type=w773" + ) + ) + ), + Review( + id = 0, + menuId = 0, + userId = 1234, + score = 3.5, + comment = "그냥저냥 먹을만해요 ", + createdAt = "2023-11-29T09:40:10.322Z", + etc = null + ), + Review( + id = 0, + menuId = 0, + userId = 1234, + score = 1.0, + comment = "맛없어요\n\n\nㅠ", + createdAt = "2023-11-29T09:40:10.322Z", + etc = null + ), + Review( + id = 0, + menuId = 0, + userId = 1234, + score = 1.0, + comment = "맛없어요\n\n\nㅠ", + createdAt = "2023-11-29T09:40:10.322Z", + etc = null + ), + Review( + id = 0, + menuId = 0, + userId = 1234, + score = 1.0, + comment = "맛없어요\n\n\nㅠ", + createdAt = "2023-11-29T09:40:10.322Z", + etc = null + ) + ) + + Column( + modifier = Modifier.fillMaxSize() + ) { + Box( + modifier = Modifier + .fillMaxWidth() + .height(56.dp) + .background(color = SikshaColors.OrangeMain) + ) { + Image( + painter = painterResource(R.drawable.ic_back_arrow), + contentDescription = "뒤로가기", + modifier = Modifier + .padding(horizontal = 20.dp, vertical = 16.dp) + .align(Alignment.CenterStart) + ) + Text( + text = "리뷰", + modifier = Modifier + .padding(horizontal = 10.dp, vertical = 12.dp) + .align(Alignment.Center), + fontSize = dpToSp(20.dp), + color = SikshaColors.White900 + ) + } + + LazyColumn( + modifier = modifier + .fillMaxSize() + //.padding(horizontal = 16.dp) + .background(color = SikshaColors.White900) + ) { + item { + Spacer(modifier = Modifier.height(16.dp)) + } + items(reviews) { review -> + ItemReview( + review = review, + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 16.dp), + showImage = showImages + ) + } + item { + Spacer(modifier = Modifier.height(20.dp)) + } + } + } + + +// item { +// Text( +// text = "리뷰가 없습니다.", +// fontSize = dpToSp(18.dp), +// //modifier = Modifier.fillMaxSize(), +// color = SikshaColors.Gray600 +// ) +// } +} + +@Preview +@Composable +fun ReviewScreenPreview(){ + ReviewScreen() } From 3aadca39352d0bcf454d0bac3f93494d59b84b0e Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Sat, 9 Dec 2023 20:58:31 +0900 Subject: [PATCH 20/68] =?UTF-8?q?paging=20dependencies=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle.kts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 9b7bea9e..d688f891 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -189,4 +189,8 @@ dependencies { // Coil implementation("io.coil-kt:coil:2.5.0") implementation("io.coil-kt:coil-compose:2.5.0") + + // Paging + implementation("androidx.paging:paging-runtime-ktx:3.2.1") + implementation("androidx.paging:paging-compose:3.2.1") } From dc760ff468bfbfc5c9b4cae779ff14ab8b5df730 Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Sun, 17 Dec 2023 20:03:54 +0900 Subject: [PATCH 21/68] =?UTF-8?q?ReviewFragment=20ComposeView=EB=A1=9C=20?= =?UTF-8?q?=EC=97=B0=EA=B2=B0=20(viewmodel=20X)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../siksha2/compose/ui/review/ReviewScreen.kt | 21 ++-- .../ui/menuDetail/review/ReviewFragment.kt | 55 ++++---- app/src/main/res/layout/fragment_review.xml | 117 +++++++++--------- 3 files changed, 104 insertions(+), 89 deletions(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt index 3a03c75c..1082e044 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt @@ -2,6 +2,7 @@ package com.wafflestudio.siksha2.compose.ui.review import androidx.compose.foundation.Image import androidx.compose.foundation.background +import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer @@ -18,6 +19,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp +import androidx.navigation.NavController import com.wafflestudio.siksha2.R import com.wafflestudio.siksha2.models.Etc import com.wafflestudio.siksha2.models.Review @@ -28,10 +30,10 @@ import com.wafflestudio.siksha2.utils.dpToSp fun ReviewScreen( modifier: Modifier = Modifier, //menuDetailViewModel: MenuDetailViewModel = hiltViewModel(), - showImages: Boolean = false + showImages: Boolean = false, + navController: NavController ) { // val reviews = menuDetailViewModel.getReviews(0).collectAsState(PagingData.empty()) - // temporary reviews val reviews = listOf( Review( @@ -127,7 +129,10 @@ fun ReviewScreen( review = review, modifier = Modifier .fillMaxWidth() - .padding(horizontal = 16.dp), + .padding(horizontal = 16.dp) + .clickable{ + navController.popBackStack() + }, showImage = showImages ) } @@ -148,8 +153,8 @@ fun ReviewScreen( // } } -@Preview -@Composable -fun ReviewScreenPreview(){ - ReviewScreen() -} +//@Preview +//@Composable +//fun ReviewScreenPreview(){ +// ReviewScreen() +//} diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt index 36cb6871..25f8c818 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt @@ -11,6 +11,7 @@ import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.navArgs import androidx.paging.LoadState import androidx.recyclerview.widget.LinearLayoutManager +import com.wafflestudio.siksha2.compose.ui.review.ReviewScreen import com.wafflestudio.siksha2.databinding.FragmentReviewBinding import com.wafflestudio.siksha2.ui.menuDetail.MenuDetailViewModel import com.wafflestudio.siksha2.ui.menuDetail.MenuReviewsAdapter @@ -38,31 +39,35 @@ class ReviewFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { reviewsAdapter = MenuReviewsAdapter(false, childFragmentManager) - binding.reviewList.apply { - layoutManager = LinearLayoutManager(context) - adapter = reviewsAdapter - } - - lifecycleScope.launch { - reviewsAdapter.loadStateFlow - .collectLatest { - if (it.refresh is LoadState.NotLoading) { - (reviewsAdapter.itemCount < 1).let { empty -> - binding.reviewList.setVisibleOrGone(empty.not()) - binding.textNoReviews.setVisibleOrGone(empty) - } - } - } - } - - lifecycleScope.launch { - vm.getReviews(args.menuId).collectLatest { - reviewsAdapter.submitData(it) - } - } - - binding.closeButton.setOnClickListener { - findNavController().popBackStack() +// binding.reviewList.apply { +// layoutManager = LinearLayoutManager(context) +// adapter = reviewsAdapter +// } +// +// lifecycleScope.launch { +// reviewsAdapter.loadStateFlow +// .collectLatest { +// if (it.refresh is LoadState.NotLoading) { +// (reviewsAdapter.itemCount < 1).let { empty -> +// binding.reviewList.setVisibleOrGone(empty.not()) +// binding.textNoReviews.setVisibleOrGone(empty) +// } +// } +// } +// } +// +// lifecycleScope.launch { +// vm.getReviews(args.menuId).collectLatest { +// reviewsAdapter.submitData(it) +// } +// } +// +// binding.closeButton.setOnClickListener { +// findNavController().popBackStack() +// } + + binding.reviewComposeView.setContent { + ReviewScreen(navController = findNavController()) } } } diff --git a/app/src/main/res/layout/fragment_review.xml b/app/src/main/res/layout/fragment_review.xml index 7419ffe6..9bdcc8d4 100644 --- a/app/src/main/res/layout/fragment_review.xml +++ b/app/src/main/res/layout/fragment_review.xml @@ -8,68 +8,73 @@ android:orientation="vertical" tools:context=".ui.menuDetail.review.ReviewFragment"> - + + + + + + + - + + + + + + + - + + + + + + + + + + + - - + + + + + + + + + - + - + + + + + + + + + + + + + + + + + + + + + + + - + android:layout_height="match_parent" + android:id="@+id/review_compose_view"/> \ No newline at end of file From dd9807c78fee119b88973f9996b808925432f978 Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Sun, 17 Dec 2023 22:33:40 +0900 Subject: [PATCH 22/68] fix typo --- .../wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt index 1082e044..ac506e8e 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt @@ -90,7 +90,7 @@ fun ReviewScreen( ) Column( - modifier = Modifier.fillMaxSize() + modifier = modifier.fillMaxSize() ) { Box( modifier = Modifier @@ -116,7 +116,7 @@ fun ReviewScreen( } LazyColumn( - modifier = modifier + modifier = Modifier .fillMaxSize() //.padding(horizontal = 16.dp) .background(color = SikshaColors.White900) From ff9d095ca5e35a9f993c2e9025490225d5c8fc5c Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Sun, 17 Dec 2023 23:49:55 +0900 Subject: [PATCH 23/68] ItemRatingBars --- .../compose/ui/review/ItemRatingBars.kt | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemRatingBars.kt diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemRatingBars.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemRatingBars.kt new file mode 100644 index 00000000..cd33d7dd --- /dev/null +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemRatingBars.kt @@ -0,0 +1,98 @@ +package com.wafflestudio.siksha2.compose.ui.review + +import androidx.compose.foundation.Image +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Arrangement +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.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.shape.CornerSize +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import com.wafflestudio.siksha2.R +import com.wafflestudio.siksha2.ui.SikshaColors +import com.wafflestudio.siksha2.utils.dpToSp + +@Composable +fun ItemRatingBar( + ratingIndex: Int, + ratio: Float, + modifier: Modifier = Modifier +) { + Row( + modifier = modifier, + horizontalArrangement = Arrangement.Start, + verticalAlignment = Alignment.CenterVertically + ) { + Text( + text = ratingIndex.toString(), + modifier = Modifier.padding(end = 3.dp), + fontSize = dpToSp(8.dp), + color = SikshaColors.Gray500 + ) + Image( + painter = painterResource(R.drawable.ic_gray_star), + contentDescription = null, + modifier = Modifier + .padding(end = 9.dp) + .width(8.dp) + .height(8.dp) + ) + if(ratio > 0.0f) + Box( + modifier = Modifier + .weight(ratio) + .height(5.dp) + .background( + color = SikshaColors.OrangeMain, + shape = RoundedCornerShape( + topStart = CornerSize(0.dp), + topEnd = CornerSize(2.dp), + bottomEnd = CornerSize(2.dp), + bottomStart = CornerSize(0.dp) + ) + ) + ){} + if(ratio < 1.0f) + Spacer(modifier = Modifier.weight(1.0f - ratio)) + } +} + +@Composable +fun ItemRatingBars( + distList: List, + modifier: Modifier = Modifier +) { + var maxCount = 1L + distList.forEach { if (maxCount < it) maxCount = it } + Column( + modifier = modifier, + verticalArrangement = Arrangement.spacedBy(5.dp) + ) { + distList.reversed().forEachIndexed{ index, cnt -> + ItemRatingBar( + ratingIndex = 5-index, + ratio = cnt.toFloat() / maxCount.toFloat() + ) + } + } +} + +@Composable +@Preview +fun ItemRatingBarsPreview() { + ItemRatingBars( + distList = listOf(5L, 2L, 1L, 0L, 2L), + modifier = Modifier.width(160.dp) + ) +} From 4831a4a0a27531948ffc939743aa8b8694ac7794 Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Sat, 13 Jan 2024 19:54:54 +0900 Subject: [PATCH 24/68] =?UTF-8?q?ReviewScreen(=EC=82=AC=EC=A7=84=20?= =?UTF-8?q?=EC=97=86=EC=9D=8C)=EC=97=90=20viewModel=20=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../siksha2/compose/ui/review/ReviewScreen.kt | 142 ++++++------------ .../ui/menuDetail/MenuDetailViewModel.kt | 2 + .../ui/menuDetail/review/ReviewFragment.kt | 43 +----- 3 files changed, 53 insertions(+), 134 deletions(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt index ac506e8e..caaab415 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt @@ -14,80 +14,31 @@ import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.material.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource -import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp +import androidx.hilt.navigation.compose.hiltViewModel import androidx.navigation.NavController +import androidx.paging.compose.collectAsLazyPagingItems import com.wafflestudio.siksha2.R -import com.wafflestudio.siksha2.models.Etc -import com.wafflestudio.siksha2.models.Review import com.wafflestudio.siksha2.ui.SikshaColors +import com.wafflestudio.siksha2.ui.menuDetail.MenuDetailViewModel import com.wafflestudio.siksha2.utils.dpToSp @Composable fun ReviewScreen( + navController: NavController, + menuId: Long, modifier: Modifier = Modifier, - //menuDetailViewModel: MenuDetailViewModel = hiltViewModel(), + menuDetailViewModel: MenuDetailViewModel = hiltViewModel(), showImages: Boolean = false, - navController: NavController ) { - // val reviews = menuDetailViewModel.getReviews(0).collectAsState(PagingData.empty()) - // temporary reviews - val reviews = listOf( - Review( - id = 0, - menuId = 0, - userId = 1234, - score = 5.0, - comment = "그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 ", - createdAt = "2023-11-29T09:40:10.322Z", - etc = Etc( - images = listOf( - "https://postfiles.pstatic.net/MjAyMzExMjZfMjcy/MDAxNzAwOTI3NTczMDY5.c9qVmjXE0nBVZpKukBxB9EB0LytpB5Olc6psLGQdWLQg.-D-zLjlG7bIPYm8XmYzK9-l1vitTZAGcimoHM57QATAg.JPEG.jyurisenpai/20231121203650_1.jpg?type=w773", - "https://postfiles.pstatic.net/MjAyMzExMjZfMjU5/MDAxNzAwOTI3MjgxMjAz.f7jMVmS7vYGWKWswaOnnxCjgmaN0qgSt0_2VLB-XZrog.WMa7r-nHh9zw_QXO15bA4ts2NabuiEtQQkM6XYSiA1Ug.JPEG.jyurisenpai/20231118200550_1.jpg?type=w773", - "https://postfiles.pstatic.net/MjAyMzExMjZfODAg/MDAxNzAwOTI5MDI4NDE3.kprldbXZmLtHlIh2AFuu9jCeWiXbXeO6pF5OpxpJB3Mg.U8aqpMqPJz4bORV05B8M8oVBF9KXTTJhY1oN17NlkaAg.JPEG.jyurisenpai/20231121211321_1.jpg?type=w773" - ) - ) - ), - Review( - id = 0, - menuId = 0, - userId = 1234, - score = 3.5, - comment = "그냥저냥 먹을만해요 ", - createdAt = "2023-11-29T09:40:10.322Z", - etc = null - ), - Review( - id = 0, - menuId = 0, - userId = 1234, - score = 1.0, - comment = "맛없어요\n\n\nㅠ", - createdAt = "2023-11-29T09:40:10.322Z", - etc = null - ), - Review( - id = 0, - menuId = 0, - userId = 1234, - score = 1.0, - comment = "맛없어요\n\n\nㅠ", - createdAt = "2023-11-29T09:40:10.322Z", - etc = null - ), - Review( - id = 0, - menuId = 0, - userId = 1234, - score = 1.0, - comment = "맛없어요\n\n\nㅠ", - createdAt = "2023-11-29T09:40:10.322Z", - etc = null - ) - ) + val reviewsFlow by remember(menuId) { mutableStateOf(menuDetailViewModel.getReviews(menuId)) } + val reviews = reviewsFlow.collectAsLazyPagingItems() Column( modifier = modifier.fillMaxSize() @@ -115,46 +66,45 @@ fun ReviewScreen( ) } - LazyColumn( + Box( modifier = Modifier - .fillMaxSize() - //.padding(horizontal = 16.dp) - .background(color = SikshaColors.White900) + .fillMaxWidth() + .weight(1f) ) { - item { - Spacer(modifier = Modifier.height(16.dp)) - } - items(reviews) { review -> - ItemReview( - review = review, - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 16.dp) - .clickable{ - navController.popBackStack() - }, - showImage = showImages + + if (reviews.itemCount == 0) { + Text( + text = "리뷰가 없습니다.", + fontSize = dpToSp(18.dp), + modifier = Modifier.align(Alignment.Center), + color = SikshaColors.Gray600 ) - } - item { - Spacer(modifier = Modifier.height(20.dp)) + } else { + LazyColumn( + modifier = Modifier + .fillMaxSize() + .background(color = SikshaColors.White900) + ) { + item { + Spacer(modifier = Modifier.height(16.dp)) + } + items(reviews.itemSnapshotList) { review -> + ItemReview( + review = review, + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 16.dp) + .clickable { + navController.popBackStack() + }, + showImage = showImages + ) + } + item { + Spacer(modifier = Modifier.height(20.dp)) + } + } } } } - - -// item { -// Text( -// text = "리뷰가 없습니다.", -// fontSize = dpToSp(18.dp), -// //modifier = Modifier.fillMaxSize(), -// color = SikshaColors.Gray600 -// ) -// } } - -//@Preview -//@Composable -//fun ReviewScreenPreview(){ -// ReviewScreen() -//} diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt index 80b83d86..6e439337 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt @@ -8,6 +8,7 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import androidx.paging.PagingData +import androidx.paging.cachedIn import com.wafflestudio.siksha2.models.Menu import com.wafflestudio.siksha2.models.Review import com.wafflestudio.siksha2.repositories.MenuRepository @@ -98,6 +99,7 @@ class MenuDetailViewModel @Inject constructor( fun getReviews(menuId: Long): Flow> { return menuRepository.getPagedReviewsByMenuIdFlow(menuId) + .cachedIn(viewModelScope) } fun getReviewsWithImages(menuId: Long): Flow> { diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt index 25f8c818..96fb1e1a 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt @@ -6,25 +6,17 @@ import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels -import androidx.lifecycle.lifecycleScope import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.navArgs -import androidx.paging.LoadState -import androidx.recyclerview.widget.LinearLayoutManager import com.wafflestudio.siksha2.compose.ui.review.ReviewScreen import com.wafflestudio.siksha2.databinding.FragmentReviewBinding import com.wafflestudio.siksha2.ui.menuDetail.MenuDetailViewModel -import com.wafflestudio.siksha2.ui.menuDetail.MenuReviewsAdapter -import com.wafflestudio.siksha2.utils.setVisibleOrGone -import kotlinx.coroutines.flow.collectLatest -import kotlinx.coroutines.launch class ReviewFragment : Fragment() { private lateinit var binding: FragmentReviewBinding private val vm: MenuDetailViewModel by activityViewModels() private val args: ReviewFragmentArgs by navArgs() - private lateinit var reviewsAdapter: MenuReviewsAdapter override fun onCreateView( inflater: LayoutInflater, @@ -37,37 +29,12 @@ class ReviewFragment : Fragment() { } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - reviewsAdapter = MenuReviewsAdapter(false, childFragmentManager) - -// binding.reviewList.apply { -// layoutManager = LinearLayoutManager(context) -// adapter = reviewsAdapter -// } -// -// lifecycleScope.launch { -// reviewsAdapter.loadStateFlow -// .collectLatest { -// if (it.refresh is LoadState.NotLoading) { -// (reviewsAdapter.itemCount < 1).let { empty -> -// binding.reviewList.setVisibleOrGone(empty.not()) -// binding.textNoReviews.setVisibleOrGone(empty) -// } -// } -// } -// } -// -// lifecycleScope.launch { -// vm.getReviews(args.menuId).collectLatest { -// reviewsAdapter.submitData(it) -// } -// } -// -// binding.closeButton.setOnClickListener { -// findNavController().popBackStack() -// } - binding.reviewComposeView.setContent { - ReviewScreen(navController = findNavController()) + ReviewScreen( + navController = findNavController(), + menuId = args.menuId, + menuDetailViewModel = vm + ) } } } From 4d5b1fec76d6701a2394805e91dc4aa35e7c6fb9 Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Sat, 13 Jan 2024 20:59:21 +0900 Subject: [PATCH 25/68] =?UTF-8?q?=EC=98=9B=EB=82=A0=20=EB=A6=AC=EB=B7=B0?= =?UTF-8?q?=EB=A5=BC=20=EB=AA=BB=20=EB=B0=9B=EC=95=84=EC=98=A4=EB=8A=94=20?= =?UTF-8?q?=EC=98=A4=EB=A5=98=20=EB=B0=9C=EC=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../compose/ui/review/MenuDetailScreen.kt | 125 ++++++++++++++++++ .../siksha2/compose/ui/review/ReviewScreen.kt | 2 +- .../ui/menuDetail/MenuDetailViewModel.kt | 1 - 3 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/MenuDetailScreen.kt diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/MenuDetailScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/MenuDetailScreen.kt new file mode 100644 index 00000000..cffb7ba9 --- /dev/null +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/MenuDetailScreen.kt @@ -0,0 +1,125 @@ +package com.wafflestudio.siksha2.compose.ui.review + +import androidx.compose.foundation.Image +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.material.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.unit.dp +import androidx.navigation.NavController +import com.wafflestudio.siksha2.R +import com.wafflestudio.siksha2.models.Etc +import com.wafflestudio.siksha2.models.Review +import com.wafflestudio.siksha2.ui.SikshaColors +import com.wafflestudio.siksha2.utils.dpToSp + +@Composable +fun MenuDetailScreen( + modifier: Modifier = Modifier, + navController: NavController +) { + val reviews = listOf( + Review( + id = 0, + menuId = 0, + userId = 1234, + score = 5.0, + comment = "그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 ", + createdAt = "2023-11-29T09:40:10.322Z", + etc = Etc( + images = listOf( + "https://postfiles.pstatic.net/MjAyMzExMjZfMjcy/MDAxNzAwOTI3NTczMDY5.c9qVmjXE0nBVZpKukBxB9EB0LytpB5Olc6psLGQdWLQg.-D-zLjlG7bIPYm8XmYzK9-l1vitTZAGcimoHM57QATAg.JPEG.jyurisenpai/20231121203650_1.jpg?type=w773", + "https://postfiles.pstatic.net/MjAyMzExMjZfMjU5/MDAxNzAwOTI3MjgxMjAz.f7jMVmS7vYGWKWswaOnnxCjgmaN0qgSt0_2VLB-XZrog.WMa7r-nHh9zw_QXO15bA4ts2NabuiEtQQkM6XYSiA1Ug.JPEG.jyurisenpai/20231118200550_1.jpg?type=w773", + "https://postfiles.pstatic.net/MjAyMzExMjZfODAg/MDAxNzAwOTI5MDI4NDE3.kprldbXZmLtHlIh2AFuu9jCeWiXbXeO6pF5OpxpJB3Mg.U8aqpMqPJz4bORV05B8M8oVBF9KXTTJhY1oN17NlkaAg.JPEG.jyurisenpai/20231121211321_1.jpg?type=w773" + ) + ) + ), + Review( + id = 0, + menuId = 0, + userId = 1234, + score = 3.5, + comment = "그냥저냥 먹을만해요 ", + createdAt = "2023-11-29T09:40:10.322Z", + etc = null + ), + Review( + id = 0, + menuId = 0, + userId = 1234, + score = 1.0, + comment = "맛없어요\n\n\nㅠ", + createdAt = "2023-11-29T09:40:10.322Z", + etc = null + ), + Review( + id = 0, + menuId = 0, + userId = 1234, + score = 1.0, + comment = "맛없어요\n\n\nㅠ", + createdAt = "2023-11-29T09:40:10.322Z", + etc = null + ), + Review( + id = 0, + menuId = 0, + userId = 1234, + score = 1.0, + comment = "맛없어요\n\n\nㅠ", + createdAt = "2023-11-29T09:40:10.322Z", + etc = null + ) + ) + + Column( + modifier = modifier.fillMaxSize() + ) { + Box( + modifier = Modifier + .fillMaxWidth() + .height(56.dp) + .background(color = SikshaColors.OrangeMain) + ) { + Image( + painter = painterResource(R.drawable.ic_back_arrow), + contentDescription = "뒤로가기", + modifier = Modifier + .padding(horizontal = 20.dp, vertical = 16.dp) + .align(Alignment.CenterStart) + ) + Text( + text = "리뷰", + modifier = Modifier + .padding(horizontal = 10.dp, vertical = 12.dp) + .align(Alignment.Center), + fontSize = dpToSp(20.dp), + color = SikshaColors.White900 + ) + } + + LazyColumn( + modifier = Modifier + .fillMaxWidth() + .background(color = SikshaColors.White900) + ) { + item { + Column( + modifier = Modifier + .fillMaxWidth() + ) { + + } + } + } + } +} diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt index caaab415..a01fe6c1 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt @@ -37,7 +37,7 @@ fun ReviewScreen( menuDetailViewModel: MenuDetailViewModel = hiltViewModel(), showImages: Boolean = false, ) { - val reviewsFlow by remember(menuId) { mutableStateOf(menuDetailViewModel.getReviews(menuId)) } + val reviewsFlow by remember{ mutableStateOf(menuDetailViewModel.getReviews(menuId)) } val reviews = reviewsFlow.collectAsLazyPagingItems() Column( diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt index 6e439337..70dbc0a6 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt @@ -99,7 +99,6 @@ class MenuDetailViewModel @Inject constructor( fun getReviews(menuId: Long): Flow> { return menuRepository.getPagedReviewsByMenuIdFlow(menuId) - .cachedIn(viewModelScope) } fun getReviewsWithImages(menuId: Long): Flow> { From 38b5dea026b9bd28c00fb4408a43ce280ae9c20a Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Sat, 13 Jan 2024 22:35:53 +0900 Subject: [PATCH 26/68] resolve conflict --- .../com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt index a01fe6c1..5e03a950 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt @@ -71,7 +71,6 @@ fun ReviewScreen( .fillMaxWidth() .weight(1f) ) { - if (reviews.itemCount == 0) { Text( text = "리뷰가 없습니다.", From a21ec70287300be76443ee817ec56ab7359ba912 Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Sun, 14 Jan 2024 17:01:49 +0900 Subject: [PATCH 27/68] =?UTF-8?q?=EC=9D=BC=EB=8B=A8=20=EC=A0=80=EC=9E=A5?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle.kts | 2 ++ .../siksha2/compose/ui/review/ReviewScreen.kt | 12 +++++++++--- .../siksha2/ui/menuDetail/MenuDetailViewModel.kt | 13 ++++++++++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index d688f891..4ec0faf9 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -116,6 +116,8 @@ dependencies { // Android arch lifecycle implementation("androidx.lifecycle:lifecycle-extensions:2.2.0") implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2") + implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.7.0") + implementation("androidx.lifecycle:lifecycle-runtime-compose:2.7.0") // Retrofit implementation("com.squareup.retrofit2:retrofit:2.9.0") diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt index 5e03a950..ea02da12 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt @@ -14,6 +14,8 @@ import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.material.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember @@ -37,8 +39,12 @@ fun ReviewScreen( menuDetailViewModel: MenuDetailViewModel = hiltViewModel(), showImages: Boolean = false, ) { - val reviewsFlow by remember{ mutableStateOf(menuDetailViewModel.getReviews(menuId)) } - val reviews = reviewsFlow.collectAsLazyPagingItems() + val reviewsState by menuDetailViewModel.reviews.collectAsState() + val reviews = reviewsState?.collectAsLazyPagingItems() + + LaunchedEffect(menuDetailViewModel){ + menuDetailViewModel.refreshMenu(menuId) + } Column( modifier = modifier.fillMaxSize() @@ -71,7 +77,7 @@ fun ReviewScreen( .fillMaxWidth() .weight(1f) ) { - if (reviews.itemCount == 0) { + if (reviews == null || reviews.itemCount == 0) { Text( text = "리뷰가 없습니다.", fontSize = dpToSp(18.dp), diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt index 70dbc0a6..349b04bb 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt @@ -6,6 +6,7 @@ import android.net.Uri import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel +import androidx.lifecycle.asFlow import androidx.lifecycle.viewModelScope import androidx.paging.PagingData import androidx.paging.cachedIn @@ -20,6 +21,10 @@ import id.zelory.compressor.constraint.format import id.zelory.compressor.constraint.resolution import id.zelory.compressor.constraint.size import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.SharingStarted +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.MultipartBody @@ -64,6 +69,12 @@ class MenuDetailViewModel @Inject constructor( val leaveReviewState: LiveData get() = _leaveReviewState + val reviews: StateFlow>?> + = _menu.asFlow().map { menu -> + if(menu != null) getReviews(menu.id) + else null + }.stateIn(viewModelScope, SharingStarted.Eagerly, initialValue = null) + fun refreshMenu(menuId: Long) { _networkResultState.value = State.LOADING viewModelScope.launch { @@ -98,7 +109,7 @@ class MenuDetailViewModel @Inject constructor( } fun getReviews(menuId: Long): Flow> { - return menuRepository.getPagedReviewsByMenuIdFlow(menuId) + return menuRepository.getPagedReviewsByMenuIdFlow(menuId).cachedIn(viewModelScope) } fun getReviewsWithImages(menuId: Long): Flow> { From 0dca7676c28dc362c1a2055025ada333e7c7c2cb Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Sun, 14 Jan 2024 18:51:50 +0900 Subject: [PATCH 28/68] =?UTF-8?q?MenuDetailViewModel=EC=97=90=20=EB=A6=AC?= =?UTF-8?q?=EB=B7=B0=20=EB=AA=A9=EB=A1=9D=20=ED=94=84=EB=A1=9C=ED=8D=BC?= =?UTF-8?q?=ED=8B=B0=EB=A1=9C=20=EC=B6=94=EA=B0=80,=20=EB=A1=9C=EB=94=A9?= =?UTF-8?q?=20=EC=9D=B4=EC=8A=88=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../siksha2/compose/ui/review/ReviewScreen.kt | 14 +++++++------- .../siksha2/repositories/MenuRepository.kt | 8 +++++++- .../ui/menuDetail/MenuDetailViewModel.kt | 19 ++++++++++++++++++- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt index ea02da12..42ac1f45 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt @@ -11,14 +11,11 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.foundation.lazy.items import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource @@ -39,9 +36,12 @@ fun ReviewScreen( menuDetailViewModel: MenuDetailViewModel = hiltViewModel(), showImages: Boolean = false, ) { - val reviewsState by menuDetailViewModel.reviews.collectAsState() - val reviews = reviewsState?.collectAsLazyPagingItems() + val reviewFlow by + if(!showImages) menuDetailViewModel.reviews.collectAsState() + else menuDetailViewModel.reviewsWithImage.collectAsState() + val reviews = reviewFlow?.collectAsLazyPagingItems() + // TODO: MenuDetailScreen에서만 리프레시하도록 바꾸기 LaunchedEffect(menuDetailViewModel){ menuDetailViewModel.refreshMenu(menuId) } @@ -93,9 +93,9 @@ fun ReviewScreen( item { Spacer(modifier = Modifier.height(16.dp)) } - items(reviews.itemSnapshotList) { review -> + items(reviews.itemCount) { ItemReview( - review = review, + review = reviews[it], modifier = Modifier .fillMaxWidth() .padding(horizontal = 16.dp) diff --git a/app/src/main/java/com/wafflestudio/siksha2/repositories/MenuRepository.kt b/app/src/main/java/com/wafflestudio/siksha2/repositories/MenuRepository.kt index 8ecdce3d..72879b8c 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/repositories/MenuRepository.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/repositories/MenuRepository.kt @@ -27,7 +27,6 @@ class MenuRepository @Inject constructor( private val sikshaApi: SikshaApi, private val dailyMenusDao: DailyMenusDao ) { - // Client Heuristic: 앞 뒤 1일 정도를 캐싱해둔다. suspend fun syncWithServer(date: LocalDate) { withContext(Dispatchers.IO) { @@ -56,6 +55,7 @@ class MenuRepository @Inject constructor( return sikshaApi.fetchMenuById(menuId) } + // TODO: 리포지토리에서 Pager 제거 fun getPagedReviewsByMenuIdFlow(menuId: Long): Flow> { return Pager( config = MenuReviewPagingSource.Config, @@ -70,6 +70,12 @@ class MenuRepository @Inject constructor( ).flow } + fun menuReviewPagingSource(menuId: Long): MenuReviewPagingSource + = MenuReviewPagingSource(sikshaApi, menuId) + + fun menuReviewWithImagePagingSource(menuId: Long): MenuReviewWithImagePagingSource + = MenuReviewWithImagePagingSource(sikshaApi, menuId) + suspend fun leaveMenuReview(menuId: Long, score: Double, comment: String): LeaveReviewResult { return sikshaApi.leaveMenuReview(LeaveReviewParam(menuId, score, comment)) } diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt index 349b04bb..e0af3a86 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt @@ -8,6 +8,7 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.asFlow import androidx.lifecycle.viewModelScope +import androidx.paging.Pager import androidx.paging.PagingData import androidx.paging.cachedIn import com.wafflestudio.siksha2.models.Menu @@ -71,7 +72,23 @@ class MenuDetailViewModel @Inject constructor( val reviews: StateFlow>?> = _menu.asFlow().map { menu -> - if(menu != null) getReviews(menu.id) + if(menu != null) Pager( + config = MenuReviewPagingSource.Config, + pagingSourceFactory = { + menuRepository.menuReviewPagingSource(menu.id) + } + ).flow + else null + }.stateIn(viewModelScope, SharingStarted.Eagerly, initialValue = null) + + val reviewsWithImage: StateFlow>?> + = _menu.asFlow().map { menu -> + if(menu != null) Pager( + config = MenuReviewWithImagePagingSource.Config, + pagingSourceFactory = { + menuRepository.menuReviewWithImagePagingSource(menu.id) + } + ).flow else null }.stateIn(viewModelScope, SharingStarted.Eagerly, initialValue = null) From 6b14b4eaceba3112068d80f37df7924b9da930e2 Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Tue, 16 Jan 2024 16:32:09 +0900 Subject: [PATCH 29/68] =?UTF-8?q?args=20=EC=B6=94=EA=B0=80=EA=B0=80=20?= =?UTF-8?q?=EC=95=88=20=EB=90=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../siksha2/compose/ui/review/ItemReviewImage.kt | 10 ++++++++-- .../siksha2/ui/menuDetail/MenuDetailFragment.kt | 4 ++-- .../siksha2/ui/menuDetail/review/ReviewFragment.kt | 1 + app/src/main/res/navigation/nav_graph.xml | 4 ++++ 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReviewImage.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReviewImage.kt index 587cbde6..17b1ba8f 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReviewImage.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReviewImage.kt @@ -27,11 +27,15 @@ import com.wafflestudio.siksha2.R import com.wafflestudio.siksha2.ui.SikshaColors import com.wafflestudio.siksha2.utils.dpToSp + +//TODO: 이미지를 클릭하면 이전 프래그먼트로 돌아간다??? @Composable fun ItemReviewImage( imageUri: Uri, modifier: Modifier = Modifier, onClick: () -> Unit = {}, + onDelete: () -> Unit = {}, + onShowMore: () -> Unit = {}, showMore: Int? = null, deletable: Boolean = false ) { @@ -42,7 +46,8 @@ fun ItemReviewImage( ) { Image( modifier = Modifier.fillMaxSize() - .align(Alignment.Center), + .align(Alignment.Center) + .clickable { if(showMore == null) onClick() }, painter = rememberAsyncImagePainter(imageUri), contentDescription = null, contentScale = ContentScale.Crop @@ -51,7 +56,7 @@ fun ItemReviewImage( Image( modifier = Modifier .align(Alignment.TopEnd) - .clickable { onClick() }, + .clickable { onDelete() }, painter = painterResource(id = R.drawable.ic_image_delete), contentDescription = null ) @@ -63,6 +68,7 @@ fun ItemReviewImage( .background(color = Color(0x80000000)) .zIndex(1f) .align(Alignment.Center) + .clickable { onShowMore() } ) { Column( modifier = Modifier.align(Alignment.Center), diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt index dee9f056..0f07f748 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt @@ -160,13 +160,13 @@ class MenuDetailFragment : Fragment() { binding.layoutCollectPhotoReviews.setOnClickListener { val action = - MenuDetailFragmentDirections.actionMenuDetailFragmentToReviewPhotoFragment(args.menuId) + MenuDetailFragmentDirections.actionMenuDetailFragmentToReviewFragment(args.menuId, true) findNavController().navigate(action) } binding.layoutCollectReviews.setOnClickListener { val action = - MenuDetailFragmentDirections.actionMenuDetailFragmentToReviewFragment(args.menuId) + MenuDetailFragmentDirections.actionMenuDetailFragmentToReviewFragment(args.menuId, false) findNavController().navigate(action) } diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt index 96fb1e1a..cedc90cf 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt @@ -33,6 +33,7 @@ class ReviewFragment : Fragment() { ReviewScreen( navController = findNavController(), menuId = args.menuId, + showImages = args.showImages, menuDetailViewModel = vm ) } diff --git a/app/src/main/res/navigation/nav_graph.xml b/app/src/main/res/navigation/nav_graph.xml index efbc1811..9ee2d186 100644 --- a/app/src/main/res/navigation/nav_graph.xml +++ b/app/src/main/res/navigation/nav_graph.xml @@ -100,6 +100,10 @@ + Date: Tue, 16 Jan 2024 20:49:17 +0900 Subject: [PATCH 30/68] =?UTF-8?q?=EB=82=B4=EB=B9=84=EA=B2=8C=EC=9D=B4?= =?UTF-8?q?=EC=85=98=20=EC=98=A4=EB=A5=98=20=ED=95=B4=EA=B2=B0!!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle.kts | 2 +- .../wafflestudio/siksha2/compose/ui/review/ItemReviewImage.kt | 1 - app/src/main/res/navigation/nav_graph.xml | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 4ec0faf9..615fd367 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -11,7 +11,7 @@ plugins { id("com.google.firebase.crashlytics") version "2.9.5" id("com.google.gms.google-services") version "4.3.15" id("org.jlleitschuh.gradle.ktlint") version "11.3.2" - id("androidx.navigation.safeargs") version "2.5.3" + id("androidx.navigation.safeargs.kotlin") version "2.5.3" id("com.google.firebase.appdistribution") version "4.0.0" } diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReviewImage.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReviewImage.kt index 17b1ba8f..86413a5e 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReviewImage.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReviewImage.kt @@ -28,7 +28,6 @@ import com.wafflestudio.siksha2.ui.SikshaColors import com.wafflestudio.siksha2.utils.dpToSp -//TODO: 이미지를 클릭하면 이전 프래그먼트로 돌아간다??? @Composable fun ItemReviewImage( imageUri: Uri, diff --git a/app/src/main/res/navigation/nav_graph.xml b/app/src/main/res/navigation/nav_graph.xml index 9ee2d186..588f827a 100644 --- a/app/src/main/res/navigation/nav_graph.xml +++ b/app/src/main/res/navigation/nav_graph.xml @@ -103,7 +103,7 @@ + app:argType="boolean" /> Date: Tue, 16 Jan 2024 23:00:21 +0900 Subject: [PATCH 31/68] =?UTF-8?q?=ED=8C=A8=ED=82=A4=EC=A7=80=20=EB=A6=AC?= =?UTF-8?q?=ED=8C=A9=ED=84=B0=EB=A7=81=20MenuDetailScreen=20=EC=9C=97?= =?UTF-8?q?=EB=B6=80=EB=B6=84=20=EB=A6=AC=ED=8C=A9=ED=84=B0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../compose/menuDetail}/ItemRatingBars.kt | 2 +- .../compose/menuDetail}/ItemRatingStars.kt | 2 +- .../compose/menuDetail}/ItemReview.kt | 2 +- .../compose/menuDetail}/ItemReviewImage.kt | 2 +- .../compose/menuDetail/LikeButton.kt | 24 ++ .../compose/menuDetail}/ReviewSpeechBubble.kt | 2 +- .../compose/ui/menuDetail/MenuDetailScreen.kt | 152 +++++++++ .../{ => menuDetail}/review/ReviewScreen.kt | 10 +- .../compose/ui/review/MenuDetailScreen.kt | 125 -------- .../ui/menuDetail/MenuDetailFragment.kt | 298 +++++++++--------- .../ui/menuDetail/MenuDetailViewModel.kt | 6 + .../ui/menuDetail/review/ReviewFragment.kt | 2 +- .../main/res/layout/fragment_menu_detail.xml | 5 + 13 files changed, 351 insertions(+), 281 deletions(-) rename app/src/main/java/com/wafflestudio/siksha2/{compose/ui/review => components/compose/menuDetail}/ItemRatingBars.kt (97%) rename app/src/main/java/com/wafflestudio/siksha2/{compose/ui/review => components/compose/menuDetail}/ItemRatingStars.kt (96%) rename app/src/main/java/com/wafflestudio/siksha2/{compose/ui/review => components/compose/menuDetail}/ItemReview.kt (99%) rename app/src/main/java/com/wafflestudio/siksha2/{compose/ui/review => components/compose/menuDetail}/ItemReviewImage.kt (98%) create mode 100644 app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/LikeButton.kt rename app/src/main/java/com/wafflestudio/siksha2/{compose/ui/review => components/compose/menuDetail}/ReviewSpeechBubble.kt (97%) create mode 100644 app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt rename app/src/main/java/com/wafflestudio/siksha2/compose/ui/{ => menuDetail}/review/ReviewScreen.kt (92%) delete mode 100644 app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/MenuDetailScreen.kt diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemRatingBars.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemRatingBars.kt similarity index 97% rename from app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemRatingBars.kt rename to app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemRatingBars.kt index cd33d7dd..f2fc07f2 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemRatingBars.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemRatingBars.kt @@ -1,4 +1,4 @@ -package com.wafflestudio.siksha2.compose.ui.review +package com.wafflestudio.siksha2.components.compose.menuDetail import androidx.compose.foundation.Image import androidx.compose.foundation.background diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemRatingStars.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemRatingStars.kt similarity index 96% rename from app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemRatingStars.kt rename to app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemRatingStars.kt index b6a0c955..8d906922 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemRatingStars.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemRatingStars.kt @@ -1,4 +1,4 @@ -package com.wafflestudio.siksha2.compose.ui.review +package com.wafflestudio.siksha2.components.compose.menuDetail import androidx.compose.foundation.Image import androidx.compose.foundation.layout.Arrangement diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReview.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReview.kt similarity index 99% rename from app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReview.kt rename to app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReview.kt index 2be142df..3f5afa2c 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReview.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReview.kt @@ -1,4 +1,4 @@ -package com.wafflestudio.siksha2.compose.ui.review +package com.wafflestudio.siksha2.components.compose.menuDetail import android.net.Uri import androidx.compose.foundation.Image diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReviewImage.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReviewImage.kt similarity index 98% rename from app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReviewImage.kt rename to app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReviewImage.kt index 86413a5e..72ed18b8 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ItemReviewImage.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReviewImage.kt @@ -1,4 +1,4 @@ -package com.wafflestudio.siksha2.compose.ui.review +package com.wafflestudio.siksha2.components.compose.menuDetail import android.net.Uri import androidx.compose.foundation.Image diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/LikeButton.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/LikeButton.kt new file mode 100644 index 00000000..d331e778 --- /dev/null +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/LikeButton.kt @@ -0,0 +1,24 @@ +package com.wafflestudio.siksha2.components.compose.menuDetail + +import androidx.compose.foundation.Image +import androidx.compose.foundation.clickable +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.painterResource +import com.wafflestudio.siksha2.R + +@Composable +fun LikeButton( + isChecked: Boolean, + modifier: Modifier = Modifier, + onClick: () -> Unit = {}, +) { + Image( + painter = painterResource( + if(isChecked) R.drawable.ic_full_heart_small + else R.drawable.ic_empty_heart_small + ), + contentDescription = "좋아요", + modifier = modifier.clickable { onClick() } + ) +} diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewSpeechBubble.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ReviewSpeechBubble.kt similarity index 97% rename from app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewSpeechBubble.kt rename to app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ReviewSpeechBubble.kt index e16841d5..e5224224 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewSpeechBubble.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ReviewSpeechBubble.kt @@ -1,4 +1,4 @@ -package com.wafflestudio.siksha2.compose.ui.review +package com.wafflestudio.siksha2.components.compose.menuDetail import androidx.compose.foundation.Image import androidx.compose.foundation.background diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt new file mode 100644 index 00000000..e41cb5d0 --- /dev/null +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt @@ -0,0 +1,152 @@ +package com.wafflestudio.siksha2.compose.ui.menuDetail + +import androidx.compose.foundation.Image +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Arrangement +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.fillMaxSize +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.lazy.LazyColumn +import androidx.compose.material.Divider +import androidx.compose.material.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.collectAsState +import androidx.compose.runtime.getValue +import androidx.compose.runtime.livedata.observeAsState +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.unit.dp +import androidx.hilt.navigation.compose.hiltViewModel +import androidx.navigation.NavController +import androidx.paging.compose.collectAsLazyPagingItems +import com.wafflestudio.siksha2.R +import com.wafflestudio.siksha2.components.compose.menuDetail.ItemReview +import com.wafflestudio.siksha2.components.compose.menuDetail.LikeButton +import com.wafflestudio.siksha2.ui.SikshaColors +import com.wafflestudio.siksha2.ui.menuDetail.MenuDetailViewModel +import com.wafflestudio.siksha2.utils.dpToSp + +@Composable +fun MenuDetailScreen( + navController: NavController, + menuId: Long, + modifier: Modifier = Modifier, + menuDetailViewModel: MenuDetailViewModel = hiltViewModel(), +) { + val menu by menuDetailViewModel.menu.observeAsState() + val reviewFlow by menuDetailViewModel.reviews.collectAsState() + val reviews = reviewFlow?.collectAsLazyPagingItems() + + LaunchedEffect(menuDetailViewModel) { + menuDetailViewModel.refreshMenu(menuId) + } + + Column( + modifier = modifier.fillMaxSize() + ) { + Box( + modifier = Modifier + .fillMaxWidth() + .height(56.dp) + .background(color = SikshaColors.OrangeMain) + ) { + Image( + painter = painterResource(R.drawable.ic_back_arrow), + contentDescription = "뒤로가기", + modifier = Modifier + .padding(horizontal = 20.dp, vertical = 16.dp) + .align(Alignment.CenterStart) + ) + Text( + text = menu?.nameKr ?: "리뷰", + modifier = Modifier + .padding(horizontal = 10.dp, vertical = 12.dp) + .fillMaxWidth(0.72f) + .align(Alignment.Center), + fontSize = dpToSp(20.dp), + overflow = TextOverflow.Ellipsis, + textAlign = TextAlign.Center, + color = SikshaColors.White900 + ) + } + + Column( + modifier = Modifier + .fillMaxWidth() + .background(SikshaColors.White900) + ) { + Column( + modifier = Modifier + .fillMaxWidth() + .padding(vertical = 18.dp), + verticalArrangement = Arrangement.spacedBy(9.dp), + horizontalAlignment = Alignment.CenterHorizontally + ) { + LikeButton( + isChecked = menu?.isLiked ?: false, + onClick = { menuDetailViewModel.toggleLike() }, + modifier = Modifier.size(21.dp) + ) + Text( + text = "좋아요 " + (menu?.likeCount?:0).toString() + "개", + fontSize = dpToSp(14.dp) + ) + } + + Divider( + modifier = Modifier.padding(horizontal = 17.dp), + color = SikshaColors.OrangeMain, + thickness = 1.dp + ) + +// Column( +// modifier = Modifier.fillMaxWidth() +// .padding(top = 15.dp, bottom = 15.dp, start = 45.dp, end = 25.dp) +// ) { +// Row { +// Text( +// +// ) +// Text( +// +// ) +// Text( +// +// ) +// } +// } + } + + Spacer(modifier = Modifier + .height(10.dp) + .background(SikshaColors.Gray600)) + + LazyColumn( + modifier = Modifier + .fillMaxWidth() + .background(color = SikshaColors.White900) + ) { + if(reviews != null) { + items(reviews.itemCount) { + ItemReview( + review = reviews[it], + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 16.dp), + showImage = true + ) + } + } + } + } +} diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt similarity index 92% rename from app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt rename to app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt index 42ac1f45..abae7884 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/ReviewScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt @@ -1,8 +1,7 @@ -package com.wafflestudio.siksha2.compose.ui.review +package com.wafflestudio.siksha2.compose.ui.menuDetail.review import androidx.compose.foundation.Image import androidx.compose.foundation.background -import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer @@ -24,10 +23,12 @@ import androidx.hilt.navigation.compose.hiltViewModel import androidx.navigation.NavController import androidx.paging.compose.collectAsLazyPagingItems import com.wafflestudio.siksha2.R +import com.wafflestudio.siksha2.components.compose.menuDetail.ItemReview import com.wafflestudio.siksha2.ui.SikshaColors import com.wafflestudio.siksha2.ui.menuDetail.MenuDetailViewModel import com.wafflestudio.siksha2.utils.dpToSp +// TODO: menuId 없애기? @Composable fun ReviewScreen( navController: NavController, @@ -98,10 +99,7 @@ fun ReviewScreen( review = reviews[it], modifier = Modifier .fillMaxWidth() - .padding(horizontal = 16.dp) - .clickable { - navController.popBackStack() - }, + .padding(horizontal = 16.dp), showImage = showImages ) } diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/MenuDetailScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/MenuDetailScreen.kt deleted file mode 100644 index cffb7ba9..00000000 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/review/MenuDetailScreen.kt +++ /dev/null @@ -1,125 +0,0 @@ -package com.wafflestudio.siksha2.compose.ui.review - -import androidx.compose.foundation.Image -import androidx.compose.foundation.background -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.material.Text -import androidx.compose.runtime.Composable -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.res.painterResource -import androidx.compose.ui.unit.dp -import androidx.navigation.NavController -import com.wafflestudio.siksha2.R -import com.wafflestudio.siksha2.models.Etc -import com.wafflestudio.siksha2.models.Review -import com.wafflestudio.siksha2.ui.SikshaColors -import com.wafflestudio.siksha2.utils.dpToSp - -@Composable -fun MenuDetailScreen( - modifier: Modifier = Modifier, - navController: NavController -) { - val reviews = listOf( - Review( - id = 0, - menuId = 0, - userId = 1234, - score = 5.0, - comment = "그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 ", - createdAt = "2023-11-29T09:40:10.322Z", - etc = Etc( - images = listOf( - "https://postfiles.pstatic.net/MjAyMzExMjZfMjcy/MDAxNzAwOTI3NTczMDY5.c9qVmjXE0nBVZpKukBxB9EB0LytpB5Olc6psLGQdWLQg.-D-zLjlG7bIPYm8XmYzK9-l1vitTZAGcimoHM57QATAg.JPEG.jyurisenpai/20231121203650_1.jpg?type=w773", - "https://postfiles.pstatic.net/MjAyMzExMjZfMjU5/MDAxNzAwOTI3MjgxMjAz.f7jMVmS7vYGWKWswaOnnxCjgmaN0qgSt0_2VLB-XZrog.WMa7r-nHh9zw_QXO15bA4ts2NabuiEtQQkM6XYSiA1Ug.JPEG.jyurisenpai/20231118200550_1.jpg?type=w773", - "https://postfiles.pstatic.net/MjAyMzExMjZfODAg/MDAxNzAwOTI5MDI4NDE3.kprldbXZmLtHlIh2AFuu9jCeWiXbXeO6pF5OpxpJB3Mg.U8aqpMqPJz4bORV05B8M8oVBF9KXTTJhY1oN17NlkaAg.JPEG.jyurisenpai/20231121211321_1.jpg?type=w773" - ) - ) - ), - Review( - id = 0, - menuId = 0, - userId = 1234, - score = 3.5, - comment = "그냥저냥 먹을만해요 ", - createdAt = "2023-11-29T09:40:10.322Z", - etc = null - ), - Review( - id = 0, - menuId = 0, - userId = 1234, - score = 1.0, - comment = "맛없어요\n\n\nㅠ", - createdAt = "2023-11-29T09:40:10.322Z", - etc = null - ), - Review( - id = 0, - menuId = 0, - userId = 1234, - score = 1.0, - comment = "맛없어요\n\n\nㅠ", - createdAt = "2023-11-29T09:40:10.322Z", - etc = null - ), - Review( - id = 0, - menuId = 0, - userId = 1234, - score = 1.0, - comment = "맛없어요\n\n\nㅠ", - createdAt = "2023-11-29T09:40:10.322Z", - etc = null - ) - ) - - Column( - modifier = modifier.fillMaxSize() - ) { - Box( - modifier = Modifier - .fillMaxWidth() - .height(56.dp) - .background(color = SikshaColors.OrangeMain) - ) { - Image( - painter = painterResource(R.drawable.ic_back_arrow), - contentDescription = "뒤로가기", - modifier = Modifier - .padding(horizontal = 20.dp, vertical = 16.dp) - .align(Alignment.CenterStart) - ) - Text( - text = "리뷰", - modifier = Modifier - .padding(horizontal = 10.dp, vertical = 12.dp) - .align(Alignment.Center), - fontSize = dpToSp(20.dp), - color = SikshaColors.White900 - ) - } - - LazyColumn( - modifier = Modifier - .fillMaxWidth() - .background(color = SikshaColors.White900) - ) { - item { - Column( - modifier = Modifier - .fillMaxWidth() - ) { - - } - } - } - } -} diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt index 0f07f748..8b5fa3bc 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt @@ -11,6 +11,7 @@ import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.navArgs import androidx.paging.LoadState import androidx.recyclerview.widget.LinearLayoutManager +import com.wafflestudio.siksha2.compose.ui.menuDetail.MenuDetailScreen import com.wafflestudio.siksha2.databinding.FragmentMenuDetailBinding import com.wafflestudio.siksha2.utils.dp import com.wafflestudio.siksha2.utils.showToast @@ -39,151 +40,160 @@ class MenuDetailFragment : Fragment() { } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - - reviewsAdapter = MenuReviewsAdapter(true, childFragmentManager) - - binding.reviewList.apply { - layoutManager = LinearLayoutManager(context) - adapter = reviewsAdapter - } - - lifecycleScope.launch { - reviewsAdapter.loadStateFlow - .collectLatest { - if (it.refresh is LoadState.NotLoading) { - (reviewsAdapter.itemCount < 1).let { empty -> - binding.emptyList.setVisibleOrGone(empty) - binding.reviewList.setVisibleOrGone(empty.not()) - } - } - } - } - - vm.refreshMenu(args.menuId) - vm.refreshImages(args.menuId) - vm.refreshReviewDistribution(args.menuId) - - vm.networkResultState.observe(viewLifecycleOwner) { - binding.menuInfoContainer.setVisibleOrGone(it == MenuDetailViewModel.State.SUCCESS) - binding.onErrorContainer.root.setVisibleOrGone(it == MenuDetailViewModel.State.FAILED) - binding.onLoadingContainer.root.setVisibleOrGone(it == MenuDetailViewModel.State.LOADING) - } - - vm.menu.observe(viewLifecycleOwner) { menu -> - // for marquee - binding.menuTitle.isSelected = true - binding.menuTitle.text = menu?.nameKr - binding.menuRating.text = "${menu?.score?.times(10)?.let { round(it) / 10 } ?: "0.0"}" - binding.menuStars.rating = menu?.score?.toFloat() ?: 0.0f - binding.reviewCount.text = " ${menu?.reviewCount ?: 0}" - // Handle menu likes - menu.isLiked?.let { isLiked -> - binding.menuLikeButton.isSelected = isLiked - } - - // Handle like count - menu.likeCount?.let { count -> - binding.menuLikeCount.text = menu.likeCount?.let { "좋아요 $it 개" } ?: "-" - } - } - - vm.reviewDistribution.observe(viewLifecycleOwner) { distList -> - if (distList.isEmpty()) return@observe - val distBarList = listOf( - binding.distBar1, - binding.distBar2, - binding.distBar3, - binding.distBar4, - binding.distBar5 +// super.onViewCreated(view, savedInstanceState) +// +// reviewsAdapter = MenuReviewsAdapter(true, childFragmentManager) +// +// binding.reviewList.apply { +// layoutManager = LinearLayoutManager(context) +// adapter = reviewsAdapter +// } +// +// lifecycleScope.launch { +// reviewsAdapter.loadStateFlow +// .collectLatest { +// if (it.refresh is LoadState.NotLoading) { +// (reviewsAdapter.itemCount < 1).let { empty -> +// binding.emptyList.setVisibleOrGone(empty) +// binding.reviewList.setVisibleOrGone(empty.not()) +// } +// } +// } +// } +// +// vm.refreshMenu(args.menuId) +// vm.refreshImages(args.menuId) +// vm.refreshReviewDistribution(args.menuId) +// +// vm.networkResultState.observe(viewLifecycleOwner) { +// binding.menuInfoContainer.setVisibleOrGone(it == MenuDetailViewModel.State.SUCCESS) +// binding.onErrorContainer.root.setVisibleOrGone(it == MenuDetailViewModel.State.FAILED) +// binding.onLoadingContainer.root.setVisibleOrGone(it == MenuDetailViewModel.State.LOADING) +// } +// +// vm.menu.observe(viewLifecycleOwner) { menu -> +// // for marquee +// binding.menuTitle.isSelected = true +// binding.menuTitle.text = menu?.nameKr +// binding.menuRating.text = "${menu?.score?.times(10)?.let { round(it) / 10 } ?: "0.0"}" +// binding.menuStars.rating = menu?.score?.toFloat() ?: 0.0f +// binding.reviewCount.text = " ${menu?.reviewCount ?: 0}" +// // Handle menu likes +// menu.isLiked?.let { isLiked -> +// binding.menuLikeButton.isSelected = isLiked +// } +// +// // Handle like count +// menu.likeCount?.let { count -> +// binding.menuLikeCount.text = menu.likeCount?.let { "좋아요 $it 개" } ?: "-" +// } +// } +// +// vm.reviewDistribution.observe(viewLifecycleOwner) { distList -> +// if (distList.isEmpty()) return@observe +// val distBarList = listOf( +// binding.distBar1, +// binding.distBar2, +// binding.distBar3, +// binding.distBar4, +// binding.distBar5 +// ) +// var maxCount = 1L +// distList.forEach { if (maxCount < it) maxCount = it } +// distBarList.forEachIndexed { index, bar -> +// val params = bar.layoutParams +// val ratio = distList[index].toDouble() / maxCount.toDouble() +// if (ratio != 0.0) { +// params.width = +// (requireContext().dp(MAX_REVIEW_DIST_BAR_WIDTH_DP) * ratio).toInt() +// } else { +// params.width = requireContext().dp(NO_REVIEW_DIST_BAR_WIDTH_DP) +// } +// bar.layoutParams = params +// bar.requestLayout() +// } +// } +// +// vm.imageCount.observe(viewLifecycleOwner) { imageCount -> +// binding.layoutPhotoReview.setVisibleOrGone(imageCount > 0) +// if (imageCount > 3) { +// binding.reviewImageView3.showMorePhotos(imageCount - 3) +// binding.reviewImageView3.setOnClickListener { +// val action = +// MenuDetailFragmentDirections.actionMenuDetailFragmentToReviewPhotoFragment( +// args.menuId +// ) +// findNavController().navigate(action) +// } +// } +// } +// +// vm.imageUrlList.observe(viewLifecycleOwner) { imageUrlList -> +// val imageReviewList = +// listOf(binding.reviewImageView1, binding.reviewImageView2, binding.reviewImageView3) +// for (i in 0 until 3) { +// if (i < imageUrlList.size) { +// imageReviewList[i].run { +// setImage(imageUrlList[i]) +// setVisibleOrGone(true) +// } +// } +// } +// for (i in 0 until 2) { +// if (i < imageUrlList.size) { +// imageReviewList[i].setOnClickListener { +// val dialog = ReviewImageDialog(imageUrlList[i]) +// dialog.show(childFragmentManager, "review_image_${imageUrlList[i]}") +// } +// } +// } +// } +// +// lifecycleScope.launch { +// vm.getReviews(args.menuId).collectLatest { +// reviewsAdapter.submitData(it) +// } +// } +// +// binding.backButton.setOnClickListener { +// findNavController().popBackStack() +// } +// +// binding.layoutCollectPhotoReviews.setOnClickListener { +// val action = +// MenuDetailFragmentDirections.actionMenuDetailFragmentToReviewFragment(args.menuId, true) +// findNavController().navigate(action) +// } +// +// binding.layoutCollectReviews.setOnClickListener { +// val action = +// MenuDetailFragmentDirections.actionMenuDetailFragmentToReviewFragment(args.menuId, false) +// findNavController().navigate(action) +// } +// +// binding.leaveReviewButton.setOnClickListener { +// if (args.isTodayMenu) { +// val action = +// MenuDetailFragmentDirections.actionMenuDetailFragmentToLeaveReviewFragment() +// findNavController().navigate(action) +// } else { +// showToast("오늘 메뉴만 평가할 수 있습니다.") +// } +// } +// +// binding.menuLikeButton.setOnClickListener { +// vm.menu.value?.isLiked?.let { +// vm.toggleLike(args.menuId, it) +// } +// } + + + binding.menuDetailComposeView.setContent { + MenuDetailScreen( + navController = findNavController(), + menuId = args.menuId, + menuDetailViewModel = vm ) - var maxCount = 1L - distList.forEach { if (maxCount < it) maxCount = it } - distBarList.forEachIndexed { index, bar -> - val params = bar.layoutParams - val ratio = distList[index].toDouble() / maxCount.toDouble() - if (ratio != 0.0) { - params.width = - (requireContext().dp(MAX_REVIEW_DIST_BAR_WIDTH_DP) * ratio).toInt() - } else { - params.width = requireContext().dp(NO_REVIEW_DIST_BAR_WIDTH_DP) - } - bar.layoutParams = params - bar.requestLayout() - } - } - - vm.imageCount.observe(viewLifecycleOwner) { imageCount -> - binding.layoutPhotoReview.setVisibleOrGone(imageCount > 0) - if (imageCount > 3) { - binding.reviewImageView3.showMorePhotos(imageCount - 3) - binding.reviewImageView3.setOnClickListener { - val action = - MenuDetailFragmentDirections.actionMenuDetailFragmentToReviewPhotoFragment( - args.menuId - ) - findNavController().navigate(action) - } - } - } - - vm.imageUrlList.observe(viewLifecycleOwner) { imageUrlList -> - val imageReviewList = - listOf(binding.reviewImageView1, binding.reviewImageView2, binding.reviewImageView3) - for (i in 0 until 3) { - if (i < imageUrlList.size) { - imageReviewList[i].run { - setImage(imageUrlList[i]) - setVisibleOrGone(true) - } - } - } - for (i in 0 until 2) { - if (i < imageUrlList.size) { - imageReviewList[i].setOnClickListener { - val dialog = ReviewImageDialog(imageUrlList[i]) - dialog.show(childFragmentManager, "review_image_${imageUrlList[i]}") - } - } - } - } - - lifecycleScope.launch { - vm.getReviews(args.menuId).collectLatest { - reviewsAdapter.submitData(it) - } - } - - binding.backButton.setOnClickListener { - findNavController().popBackStack() - } - - binding.layoutCollectPhotoReviews.setOnClickListener { - val action = - MenuDetailFragmentDirections.actionMenuDetailFragmentToReviewFragment(args.menuId, true) - findNavController().navigate(action) - } - - binding.layoutCollectReviews.setOnClickListener { - val action = - MenuDetailFragmentDirections.actionMenuDetailFragmentToReviewFragment(args.menuId, false) - findNavController().navigate(action) - } - - binding.leaveReviewButton.setOnClickListener { - if (args.isTodayMenu) { - val action = - MenuDetailFragmentDirections.actionMenuDetailFragmentToLeaveReviewFragment() - findNavController().navigate(action) - } else { - showToast("오늘 메뉴만 평가할 수 있습니다.") - } - } - - binding.menuLikeButton.setOnClickListener { - vm.menu.value?.isLiked?.let { - vm.toggleLike(args.menuId, it) - } } } diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt index e0af3a86..13eb71df 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt @@ -182,6 +182,12 @@ class MenuDetailViewModel @Inject constructor( _leaveReviewState.value = ReviewState.WAITING } + fun toggleLike(){ + if(menu.value != null) { + toggleLike(menu.value!!.id, menu.value!!.isLiked ?: false) + } + } + fun toggleLike(id: Long, isCurrentlyLiked: Boolean) { viewModelScope.launch { val menuItem = menuRepository.getMenuById(id) diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt index cedc90cf..d23185d5 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt @@ -8,7 +8,7 @@ import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.navArgs -import com.wafflestudio.siksha2.compose.ui.review.ReviewScreen +import com.wafflestudio.siksha2.compose.ui.menuDetail.review.ReviewScreen import com.wafflestudio.siksha2.databinding.FragmentReviewBinding import com.wafflestudio.siksha2.ui.menuDetail.MenuDetailViewModel diff --git a/app/src/main/res/layout/fragment_menu_detail.xml b/app/src/main/res/layout/fragment_menu_detail.xml index c8f4840f..9a6d9736 100644 --- a/app/src/main/res/layout/fragment_menu_detail.xml +++ b/app/src/main/res/layout/fragment_menu_detail.xml @@ -499,4 +499,9 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/tool_bar" /> + + \ No newline at end of file From 9f1de0ae9beb3758769fdd6e37cdb66bacb87b09 Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Sun, 11 Feb 2024 17:15:51 +0900 Subject: [PATCH 32/68] =?UTF-8?q?MenuDetailScreen(=EB=82=B4=EC=9A=A9?= =?UTF-8?q?=EB=B6=80=EB=B6=84)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../compose/ui/menuDetail/MenuDetailScreen.kt | 296 ++++-- .../main/res/layout/fragment_menu_detail.xml | 980 +++++++++--------- 2 files changed, 725 insertions(+), 551 deletions(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt index e41cb5d0..8d6fe77a 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt @@ -2,6 +2,7 @@ package com.wafflestudio.siksha2.compose.ui.menuDetail import androidx.compose.foundation.Image import androidx.compose.foundation.background +import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column @@ -12,7 +13,9 @@ 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.lazy.LazyColumn +import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.Divider import androidx.compose.material.Text import androidx.compose.runtime.Composable @@ -22,6 +25,8 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.livedata.observeAsState import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.rotate +import androidx.compose.ui.graphics.ColorFilter import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextOverflow @@ -30,11 +35,15 @@ import androidx.hilt.navigation.compose.hiltViewModel import androidx.navigation.NavController import androidx.paging.compose.collectAsLazyPagingItems import com.wafflestudio.siksha2.R +import com.wafflestudio.siksha2.components.compose.menuDetail.ItemRatingBars +import com.wafflestudio.siksha2.components.compose.menuDetail.ItemRatingStars import com.wafflestudio.siksha2.components.compose.menuDetail.ItemReview import com.wafflestudio.siksha2.components.compose.menuDetail.LikeButton import com.wafflestudio.siksha2.ui.SikshaColors +import com.wafflestudio.siksha2.ui.menuDetail.MenuDetailFragmentDirections import com.wafflestudio.siksha2.ui.menuDetail.MenuDetailViewModel import com.wafflestudio.siksha2.utils.dpToSp +import kotlin.math.round @Composable fun MenuDetailScreen( @@ -46,9 +55,13 @@ fun MenuDetailScreen( val menu by menuDetailViewModel.menu.observeAsState() val reviewFlow by menuDetailViewModel.reviews.collectAsState() val reviews = reviewFlow?.collectAsLazyPagingItems() + val imageReviewFlow by menuDetailViewModel.reviewsWithImage.collectAsState() + val imageReviews = imageReviewFlow?.collectAsLazyPagingItems() + val loadingState = menuDetailViewModel.networkResultState.observeAsState() LaunchedEffect(menuDetailViewModel) { menuDetailViewModel.refreshMenu(menuId) + menuDetailViewModel.refreshReviewDistribution(menuId) } Column( @@ -66,6 +79,9 @@ fun MenuDetailScreen( modifier = Modifier .padding(horizontal = 20.dp, vertical = 16.dp) .align(Alignment.CenterStart) + .clickable { + navController.popBackStack() + } ) Text( text = menu?.nameKr ?: "리뷰", @@ -79,74 +95,232 @@ fun MenuDetailScreen( color = SikshaColors.White900 ) } + + when(loadingState.value){ + MenuDetailViewModel.State.SUCCESS -> { + LazyColumn( + modifier = Modifier + .fillMaxWidth() + .background(SikshaColors.White900) + ) { + // 상단 별점 정보 + a + item { + Column( + modifier = Modifier.fillMaxWidth() + ) { + Column( + modifier = Modifier + .fillMaxWidth() + .padding(vertical = 18.dp), + verticalArrangement = Arrangement.spacedBy(9.dp), + horizontalAlignment = Alignment.CenterHorizontally + ) { + LikeButton( + isChecked = menu?.isLiked ?: false, + onClick = { menuDetailViewModel.toggleLike() }, + modifier = Modifier.size(21.dp) + ) + Text( + text = "좋아요 " + (menu?.likeCount ?: 0).toString() + "개", + fontSize = dpToSp(14.dp) + ) + } - Column( - modifier = Modifier - .fillMaxWidth() - .background(SikshaColors.White900) - ) { - Column( - modifier = Modifier - .fillMaxWidth() - .padding(vertical = 18.dp), - verticalArrangement = Arrangement.spacedBy(9.dp), - horizontalAlignment = Alignment.CenterHorizontally - ) { - LikeButton( - isChecked = menu?.isLiked ?: false, - onClick = { menuDetailViewModel.toggleLike() }, - modifier = Modifier.size(21.dp) - ) - Text( - text = "좋아요 " + (menu?.likeCount?:0).toString() + "개", - fontSize = dpToSp(14.dp) - ) - } + Divider( + modifier = Modifier.padding(horizontal = 17.dp), + color = SikshaColors.OrangeMain, + thickness = 1.dp + ) - Divider( - modifier = Modifier.padding(horizontal = 17.dp), - color = SikshaColors.OrangeMain, - thickness = 1.dp - ) + Column( + modifier = Modifier + .fillMaxWidth() + .padding(top = 15.dp, bottom = 15.dp, start = 45.dp, end = 25.dp) + ) { + Row( + modifier = Modifier.align(Alignment.CenterHorizontally), + horizontalArrangement = Arrangement.Center + ) { + Text( + text = "총 ", + color = SikshaColors.Gray800, + fontSize = dpToSp(10.dp) + ) + Text( + text = reviews?.itemCount.toString(), + color = SikshaColors.OrangeMain, + fontSize = dpToSp(10.dp) + ) + Text( + text = "명", + color = SikshaColors.OrangeMain, + fontSize = dpToSp(10.dp) + ) + Text( + text = "이 평가했어요!", + color = SikshaColors.Gray800, + fontSize = dpToSp(10.dp) + ) + } -// Column( -// modifier = Modifier.fillMaxWidth() -// .padding(top = 15.dp, bottom = 15.dp, start = 45.dp, end = 25.dp) -// ) { -// Row { -// Text( -// -// ) -// Text( -// -// ) -// Text( -// -// ) -// } -// } - } + Row( + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 20.dp, vertical = 10.dp), + horizontalArrangement = Arrangement.spacedBy(20.dp), + verticalAlignment = Alignment.CenterVertically + ) { + Column( + horizontalAlignment = Alignment.CenterHorizontally + ) { + Text( + text = "${ + menu?.score?.times(10)?.let { round(it) / 10 } ?: "0.0" + }", + fontSize = dpToSp(32.dp) + ) + ItemRatingStars( + rating = menu?.score?.toFloat() ?: 0.0f + ) + } + menuDetailViewModel.reviewDistribution.value?.let { + ItemRatingBars( + distList = it, + modifier = Modifier.weight(1f) + ) + } + } - Spacer(modifier = Modifier - .height(10.dp) - .background(SikshaColors.Gray600)) + Box( + modifier = Modifier + .width(200.dp) + .height(32.dp) + .background( + color = SikshaColors.OrangeMain, + shape = RoundedCornerShape(50.dp) + ) + .clickable { } + .align(Alignment.CenterHorizontally) + ) { + Text( + text = "나의 평가 남기기", + fontSize = dpToSp(14.dp), + color = SikshaColors.White900, + modifier = Modifier.align(Alignment.Center) + .clickable{ + navController.navigate(MenuDetailFragmentDirections.actionMenuDetailFragmentToLeaveReviewFragment()) + } + ) + } + } + Spacer(modifier = Modifier + .fillMaxWidth() + .height(10.dp) + .background(SikshaColors.Gray100)) + } + } - LazyColumn( - modifier = Modifier - .fillMaxWidth() - .background(color = SikshaColors.White900) - ) { - if(reviews != null) { - items(reviews.itemCount) { - ItemReview( - review = reviews[it], - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 16.dp), - showImage = true - ) + // 사진 리뷰 + if (imageReviews != null && imageReviews.itemCount > 0) { + item{ + Box( + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 16.dp) + .height(50.dp) + ) { + Text( + text = "사진 리뷰 모아보기", + fontSize = dpToSp(14.dp), + modifier = Modifier.align(Alignment.CenterStart) + ) + Image( + painter = painterResource(R.drawable.ic_back_arrow), + contentDescription = "사진 리뷰 모아보기", + colorFilter = ColorFilter.tint(SikshaColors.Gray400), + modifier = Modifier + .align(Alignment.CenterEnd) + .rotate(180f) + .clickable { + navController.navigate( + MenuDetailFragmentDirections.actionMenuDetailFragmentToReviewFragment( + menuId, + true + ) + ) + } + ) + } + } + } + + // 일반 리뷰 + if(reviews != null && reviews.itemCount > 0) { + item { + Box( + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 16.dp) + .height(50.dp) + ) { + Text( + text = "리뷰", + fontSize = dpToSp(14.dp), + modifier = Modifier.align(Alignment.CenterStart) + ) + Image( + painter = painterResource(R.drawable.ic_back_arrow), + contentDescription = "리뷰", + colorFilter = ColorFilter.tint(SikshaColors.Gray400), + modifier = Modifier + .align(Alignment.CenterEnd) + .rotate(180f) + .clickable { + navController.navigate( + MenuDetailFragmentDirections.actionMenuDetailFragmentToReviewFragment( + menuId, + false + ) + ) + } + ) + } + } + items(reviews.itemCount) { + ItemReview( + review = reviews[it], + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 16.dp), + showImage = true + ) + } + } + else{ + item { + Box( + modifier = Modifier + .padding(vertical = 36.dp) + .fillMaxWidth() + ) { + Text( + text = "리뷰가 없습니다.", + fontSize = dpToSp(18.dp), + modifier = Modifier.align(Alignment.Center), + color = SikshaColors.Gray600 + ) + } + } + } } } + MenuDetailViewModel.State.LOADING -> { + + } + MenuDetailViewModel.State.FAILED -> { + + } + else -> {} } } } diff --git a/app/src/main/res/layout/fragment_menu_detail.xml b/app/src/main/res/layout/fragment_menu_detail.xml index 9a6d9736..87352b0b 100644 --- a/app/src/main/res/layout/fragment_menu_detail.xml +++ b/app/src/main/res/layout/fragment_menu_detail.xml @@ -8,496 +8,496 @@ android:orientation="vertical" tools:context=".ui.menuDetail.MenuDetailFragment"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Date: Sun, 11 Feb 2024 17:57:07 +0900 Subject: [PATCH 33/68] ErrorComponent --- .../components/compose/ErrorComponent.kt | 40 +++++++++++++++++++ .../compose/ui/menuDetail/MenuDetailScreen.kt | 18 +++++++-- 2 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/com/wafflestudio/siksha2/components/compose/ErrorComponent.kt diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/ErrorComponent.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/ErrorComponent.kt new file mode 100644 index 00000000..c95b7117 --- /dev/null +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/ErrorComponent.kt @@ -0,0 +1,40 @@ +package com.wafflestudio.siksha2.components.compose + +import androidx.compose.foundation.Image +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.material.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.ColorFilter +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.unit.dp +import com.wafflestudio.siksha2.R +import com.wafflestudio.siksha2.ui.SikshaColors +import com.wafflestudio.siksha2.utils.dpToSp + +@Composable +fun ErrorComponent( + modifier: Modifier = Modifier +){ + Column( + modifier = modifier, + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.Center + ){ + Image( + painter = painterResource(R.drawable.ic_warning), + contentDescription = null, + colorFilter = ColorFilter.tint(SikshaColors.Gray800), + modifier = Modifier.size(34.dp) + ) + Text( + text = "네트워크 연결이 불안정합니다.", + fontSize = dpToSp(20.dp), + modifier = Modifier.padding(top = 20.dp) + ) + } +} diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt index 8d6fe77a..601772b9 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt @@ -35,6 +35,7 @@ import androidx.hilt.navigation.compose.hiltViewModel import androidx.navigation.NavController import androidx.paging.compose.collectAsLazyPagingItems import com.wafflestudio.siksha2.R +import com.wafflestudio.siksha2.components.compose.ErrorComponent import com.wafflestudio.siksha2.components.compose.menuDetail.ItemRatingBars import com.wafflestudio.siksha2.components.compose.menuDetail.ItemRatingStars import com.wafflestudio.siksha2.components.compose.menuDetail.ItemReview @@ -135,7 +136,12 @@ fun MenuDetailScreen( Column( modifier = Modifier .fillMaxWidth() - .padding(top = 15.dp, bottom = 15.dp, start = 45.dp, end = 25.dp) + .padding( + top = 15.dp, + bottom = 15.dp, + start = 45.dp, + end = 25.dp + ) ) { Row( modifier = Modifier.align(Alignment.CenterHorizontally), @@ -206,8 +212,9 @@ fun MenuDetailScreen( text = "나의 평가 남기기", fontSize = dpToSp(14.dp), color = SikshaColors.White900, - modifier = Modifier.align(Alignment.Center) - .clickable{ + modifier = Modifier + .align(Alignment.Center) + .clickable { navController.navigate(MenuDetailFragmentDirections.actionMenuDetailFragmentToLeaveReviewFragment()) } ) @@ -318,7 +325,10 @@ fun MenuDetailScreen( } MenuDetailViewModel.State.FAILED -> { - + ErrorComponent( + modifier = Modifier.fillMaxWidth() + .weight(1f) + ) } else -> {} } From 52727e2965ec22342962240219eec9ca307e66d7 Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Sun, 11 Feb 2024 18:01:28 +0900 Subject: [PATCH 34/68] =?UTF-8?q?ReviewScreen=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../compose/ui/menuDetail/review/ReviewScreen.kt | 12 ++++-------- .../siksha2/ui/menuDetail/review/ReviewFragment.kt | 1 - 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt index abae7884..2ba69c6b 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt @@ -2,6 +2,7 @@ package com.wafflestudio.siksha2.compose.ui.menuDetail.review import androidx.compose.foundation.Image import androidx.compose.foundation.background +import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer @@ -12,7 +13,6 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.material.Text import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment @@ -28,11 +28,9 @@ import com.wafflestudio.siksha2.ui.SikshaColors import com.wafflestudio.siksha2.ui.menuDetail.MenuDetailViewModel import com.wafflestudio.siksha2.utils.dpToSp -// TODO: menuId 없애기? @Composable fun ReviewScreen( navController: NavController, - menuId: Long, modifier: Modifier = Modifier, menuDetailViewModel: MenuDetailViewModel = hiltViewModel(), showImages: Boolean = false, @@ -42,11 +40,6 @@ fun ReviewScreen( else menuDetailViewModel.reviewsWithImage.collectAsState() val reviews = reviewFlow?.collectAsLazyPagingItems() - // TODO: MenuDetailScreen에서만 리프레시하도록 바꾸기 - LaunchedEffect(menuDetailViewModel){ - menuDetailViewModel.refreshMenu(menuId) - } - Column( modifier = modifier.fillMaxSize() ) { @@ -62,6 +55,9 @@ fun ReviewScreen( modifier = Modifier .padding(horizontal = 20.dp, vertical = 16.dp) .align(Alignment.CenterStart) + .clickable{ + navController.popBackStack() + } ) Text( text = "리뷰", diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt index d23185d5..e3a0f42e 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt @@ -32,7 +32,6 @@ class ReviewFragment : Fragment() { binding.reviewComposeView.setContent { ReviewScreen( navController = findNavController(), - menuId = args.menuId, showImages = args.showImages, menuDetailViewModel = vm ) From 02093afaa1334fdccfeb3100f9b1f5b3a3b6543b Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Mon, 12 Feb 2024 22:17:38 +0900 Subject: [PATCH 35/68] =?UTF-8?q?LoadingComponent=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle.kts | 1 + .../components/compose/LoadingComponent.kt | 33 +++++++++++++++++++ .../compose/ui/menuDetail/MenuDetailScreen.kt | 14 ++++++-- 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/com/wafflestudio/siksha2/components/compose/LoadingComponent.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 615fd367..c38a957b 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -187,6 +187,7 @@ dependencies { implementation("androidx.paging:paging-compose:${Deps.Version.PagingCompose}") implementation("androidx.lifecycle:lifecycle-viewmodel-compose:${Deps.Version.ComposeViewModel}") implementation("androidx.hilt:hilt-navigation-compose:${Deps.Version.ComposeHiltNavigation}") + implementation("com.airbnb.android:lottie-compose:6.3.0") // Coil implementation("io.coil-kt:coil:2.5.0") diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/LoadingComponent.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/LoadingComponent.kt new file mode 100644 index 00000000..dd7f3c53 --- /dev/null +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/LoadingComponent.kt @@ -0,0 +1,33 @@ +package com.wafflestudio.siksha2.components.compose + +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.size +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import com.airbnb.lottie.compose.LottieAnimation +import com.airbnb.lottie.compose.LottieCompositionSpec +import com.airbnb.lottie.compose.animateLottieCompositionAsState +import com.airbnb.lottie.compose.rememberLottieComposition +import com.wafflestudio.siksha2.R + +@Composable +fun LoadingComponent( + modifier: Modifier = Modifier +) { + val composition by rememberLottieComposition(LottieCompositionSpec.RawRes(R.raw.ani_loading)) + val progress by animateLottieCompositionAsState(composition) + Box( + modifier = modifier, + contentAlignment = Alignment.Center + ){ + LottieAnimation( + composition = composition, + progress = { progress }, + modifier = Modifier.size(70.dp) + ) + } +} diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt index 601772b9..0a3cdb9b 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt @@ -34,8 +34,13 @@ import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel import androidx.navigation.NavController import androidx.paging.compose.collectAsLazyPagingItems +import com.airbnb.lottie.compose.LottieAnimation +import com.airbnb.lottie.compose.LottieCompositionSpec +import com.airbnb.lottie.compose.animateLottieCompositionAsState +import com.airbnb.lottie.compose.rememberLottieComposition import com.wafflestudio.siksha2.R import com.wafflestudio.siksha2.components.compose.ErrorComponent +import com.wafflestudio.siksha2.components.compose.LoadingComponent import com.wafflestudio.siksha2.components.compose.menuDetail.ItemRatingBars import com.wafflestudio.siksha2.components.compose.menuDetail.ItemRatingStars import com.wafflestudio.siksha2.components.compose.menuDetail.ItemReview @@ -322,11 +327,16 @@ fun MenuDetailScreen( } } MenuDetailViewModel.State.LOADING -> { - + LoadingComponent( + modifier = Modifier + .fillMaxWidth() + .weight(1f) + ) } MenuDetailViewModel.State.FAILED -> { ErrorComponent( - modifier = Modifier.fillMaxWidth() + modifier = Modifier + .fillMaxWidth() .weight(1f) ) } From 0d08b1c0130cd17a6b3a7ac59e5d6d22b5efbcff Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Mon, 12 Feb 2024 22:18:36 +0900 Subject: [PATCH 36/68] LoadingComponent(lottianimation) --- .../siksha2/components/compose/LoadingComponent.kt | 1 - .../siksha2/compose/ui/menuDetail/MenuDetailScreen.kt | 4 ---- 2 files changed, 5 deletions(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/LoadingComponent.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/LoadingComponent.kt index dd7f3c53..36bc0659 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/components/compose/LoadingComponent.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/LoadingComponent.kt @@ -1,7 +1,6 @@ package com.wafflestudio.siksha2.components.compose import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.size import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt index 0a3cdb9b..a9154cb3 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt @@ -34,10 +34,6 @@ import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel import androidx.navigation.NavController import androidx.paging.compose.collectAsLazyPagingItems -import com.airbnb.lottie.compose.LottieAnimation -import com.airbnb.lottie.compose.LottieCompositionSpec -import com.airbnb.lottie.compose.animateLottieCompositionAsState -import com.airbnb.lottie.compose.rememberLottieComposition import com.wafflestudio.siksha2.R import com.wafflestudio.siksha2.components.compose.ErrorComponent import com.wafflestudio.siksha2.components.compose.LoadingComponent From af244295dbb1e8a6cb6031a9830f1009ed77b35d Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Mon, 12 Feb 2024 23:15:36 +0900 Subject: [PATCH 37/68] =?UTF-8?q?MenuDetailScreen=20=EC=82=AC=EC=A7=84=20?= =?UTF-8?q?=EB=AF=B8=EB=A6=AC=EB=B3=B4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../compose/menuDetail/ItemReview.kt | 7 ++- .../compose/menuDetail/ItemReviewImage.kt | 6 --- .../compose/ui/menuDetail/MenuDetailScreen.kt | 49 +++++++++++++++++++ 3 files changed, 55 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReview.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReview.kt index 3f5afa2c..a01639d1 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReview.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReview.kt @@ -12,12 +12,15 @@ import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.defaultMinSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip import androidx.compose.ui.res.painterResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp @@ -105,7 +108,9 @@ fun ItemReview( ) { for(imageUri in review?.etc?.images ?: listOf()){ ItemReviewImage( - imageUri = Uri.parse(imageUri) + imageUri = Uri.parse(imageUri), + modifier = Modifier.size(100.dp) + .clip(shape = RoundedCornerShape(8.dp)) ) } } diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReviewImage.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReviewImage.kt index 72ed18b8..32d3c43b 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReviewImage.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReviewImage.kt @@ -8,14 +8,10 @@ import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.width -import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.Text import androidx.compose.runtime.Composable 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.layout.ContentScale import androidx.compose.ui.res.painterResource @@ -40,8 +36,6 @@ fun ItemReviewImage( ) { Box( modifier = modifier - .width(100.dp).height(100.dp) - .clip(shape = RoundedCornerShape(8.dp)) ) { Image( modifier = Modifier.fillMaxSize() diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt index a9154cb3..9c47c41e 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt @@ -1,8 +1,10 @@ package com.wafflestudio.siksha2.compose.ui.menuDetail +import android.net.Uri import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.clickable +import androidx.compose.foundation.horizontalScroll import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column @@ -15,6 +17,7 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.Divider import androidx.compose.material.Text @@ -25,6 +28,7 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.livedata.observeAsState import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.rotate import androidx.compose.ui.graphics.ColorFilter import androidx.compose.ui.res.painterResource @@ -40,11 +44,13 @@ import com.wafflestudio.siksha2.components.compose.LoadingComponent import com.wafflestudio.siksha2.components.compose.menuDetail.ItemRatingBars import com.wafflestudio.siksha2.components.compose.menuDetail.ItemRatingStars import com.wafflestudio.siksha2.components.compose.menuDetail.ItemReview +import com.wafflestudio.siksha2.components.compose.menuDetail.ItemReviewImage import com.wafflestudio.siksha2.components.compose.menuDetail.LikeButton import com.wafflestudio.siksha2.ui.SikshaColors import com.wafflestudio.siksha2.ui.menuDetail.MenuDetailFragmentDirections import com.wafflestudio.siksha2.ui.menuDetail.MenuDetailViewModel import com.wafflestudio.siksha2.utils.dpToSp +import kotlin.math.min import kotlin.math.round @Composable @@ -60,6 +66,7 @@ fun MenuDetailScreen( val imageReviewFlow by menuDetailViewModel.reviewsWithImage.collectAsState() val imageReviews = imageReviewFlow?.collectAsLazyPagingItems() val loadingState = menuDetailViewModel.networkResultState.observeAsState() + val imagePreviewScrollState = rememberScrollState() LaunchedEffect(menuDetailViewModel) { menuDetailViewModel.refreshMenu(menuId) @@ -259,6 +266,48 @@ fun MenuDetailScreen( } ) } + Row( + modifier = Modifier + .padding(horizontal = 16.dp) + .horizontalScroll(imagePreviewScrollState), + horizontalArrangement = Arrangement.spacedBy(8.dp) + ){ + for(i: Int in 1..min(imageReviews.itemCount,3)){ + when(val it = imageReviews.itemSnapshotList.items[i-1].etc?.images?.get(0)){ + null -> Box(modifier= Modifier + .size(120.dp) + .background(SikshaColors.Gray100) + .clip(RoundedCornerShape(10.dp))) + else -> { + if(i==3) { + ItemReviewImage( + imageUri = Uri.parse(it), + modifier = Modifier + .size(120.dp) + .clip(RoundedCornerShape(10.dp)), + showMore = imageReviews.itemCount - 2, + onShowMore = { + navController.navigate( + MenuDetailFragmentDirections.actionMenuDetailFragmentToReviewFragment( + menuId, + true + ) + ) + } + ) + } + else{ + ItemReviewImage( + imageUri = Uri.parse(it), + modifier = Modifier + .size(120.dp) + .clip(RoundedCornerShape(10.dp)) + ) + } + } + } + } + } } } From 61001ea49172edf6bd37bd59c2ab8003b7b78ea6 Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Thu, 15 Feb 2024 18:36:32 +0900 Subject: [PATCH 38/68] =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=EB=82=A8=EA=B8=B0?= =?UTF-8?q?=EA=B8=B0=20=EB=B2=84=ED=8A=BC=20=ED=81=B4=EB=A6=AD=20=EC=8B=9C?= =?UTF-8?q?=20=ED=86=A0=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt index 8b5fa3bc..d92c2a75 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt @@ -26,7 +26,6 @@ class MenuDetailFragment : Fragment() { private val vm: MenuDetailViewModel by activityViewModels() private lateinit var binding: FragmentMenuDetailBinding - private lateinit var reviewsAdapter: MenuReviewsAdapter private val args: MenuDetailFragmentArgs by navArgs() @@ -192,6 +191,7 @@ class MenuDetailFragment : Fragment() { MenuDetailScreen( navController = findNavController(), menuId = args.menuId, + isTodayMenu = args.isTodayMenu, menuDetailViewModel = vm ) } From 0769f105e82e37fc1a5343a1866328fd8ef2cf07 Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Thu, 15 Feb 2024 18:41:21 +0900 Subject: [PATCH 39/68] =?UTF-8?q?=ED=8F=B0=ED=8A=B8=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/compose/ErrorComponent.kt | 3 ++ .../components/compose/NanumFontFamily.kt | 13 +++++ .../compose/menuDetail/ItemRatingBars.kt | 4 ++ .../compose/menuDetail/ItemReview.kt | 12 ++++- .../compose/ui/menuDetail/MenuDetailScreen.kt | 49 ++++++++++++++++--- .../ui/menuDetail/review/ReviewScreen.kt | 6 +++ .../siksha2/repositories/MenuRepository.kt | 19 ++++--- .../ui/menuDetail/MenuDetailViewModel.kt | 48 +++++++++--------- 8 files changed, 111 insertions(+), 43 deletions(-) create mode 100644 app/src/main/java/com/wafflestudio/siksha2/components/compose/NanumFontFamily.kt diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/ErrorComponent.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/ErrorComponent.kt index c95b7117..53d96fa4 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/components/compose/ErrorComponent.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/ErrorComponent.kt @@ -11,6 +11,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.ColorFilter import androidx.compose.ui.res.painterResource +import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import com.wafflestudio.siksha2.R import com.wafflestudio.siksha2.ui.SikshaColors @@ -34,6 +35,8 @@ fun ErrorComponent( Text( text = "네트워크 연결이 불안정합니다.", fontSize = dpToSp(20.dp), + fontFamily = NanumSquareFontFamily, + fontWeight = FontWeight.Light, modifier = Modifier.padding(top = 20.dp) ) } diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/NanumFontFamily.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/NanumFontFamily.kt new file mode 100644 index 00000000..12a64ace --- /dev/null +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/NanumFontFamily.kt @@ -0,0 +1,13 @@ +package com.wafflestudio.siksha2.components.compose + +import androidx.compose.ui.text.font.Font +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontWeight +import com.wafflestudio.siksha2.R + +val NanumSquareFontFamily = FontFamily( + Font(R.font.nanum_square_regular, FontWeight.Normal), + Font(R.font.nanum_square_bold, FontWeight.Bold), + Font(R.font.nanum_square_light, FontWeight.Light), + Font(R.font.nanum_square_extra_bold, FontWeight.ExtraBold) +) diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemRatingBars.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemRatingBars.kt index f2fc07f2..0b9181a2 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemRatingBars.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemRatingBars.kt @@ -17,9 +17,11 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource +import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import com.wafflestudio.siksha2.R +import com.wafflestudio.siksha2.components.compose.NanumSquareFontFamily import com.wafflestudio.siksha2.ui.SikshaColors import com.wafflestudio.siksha2.utils.dpToSp @@ -38,6 +40,8 @@ fun ItemRatingBar( text = ratingIndex.toString(), modifier = Modifier.padding(end = 3.dp), fontSize = dpToSp(8.dp), + fontFamily = NanumSquareFontFamily, + fontWeight = FontWeight.Bold, color = SikshaColors.Gray500 ) Image( diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReview.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReview.kt index a01639d1..76cd7a99 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReview.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReview.kt @@ -22,9 +22,11 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.res.painterResource +import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import com.wafflestudio.siksha2.R +import com.wafflestudio.siksha2.components.compose.NanumSquareFontFamily import com.wafflestudio.siksha2.models.Etc import com.wafflestudio.siksha2.models.Review import com.wafflestudio.siksha2.ui.SikshaColors @@ -64,7 +66,9 @@ fun ItemReview( Text( text = "ID" + (review?.userId ?: ""), color = SikshaColors.Black900, - fontSize = dpToSp(12.dp) + fontSize = dpToSp(12.dp), + fontFamily = NanumSquareFontFamily, + fontWeight = FontWeight.Bold ) ItemRatingStars(review?.score?.toFloat() ?: 0.0f) } @@ -75,6 +79,8 @@ fun ItemReview( .align(Alignment.TopEnd) .padding(end = 10.dp), fontSize = dpToSp(12.dp), + fontFamily = NanumSquareFontFamily, + fontWeight = FontWeight.Bold, color = SikshaColors.Gray500 ) } @@ -96,7 +102,9 @@ fun ItemReview( .fillMaxWidth() .padding(start = 30.dp, end = 10.dp, top = 13.dp, bottom = 15.dp), color = SikshaColors.Gray800, - fontSize = dpToSp(dp = 12.dp) + fontSize = dpToSp(dp = 12.dp), + fontFamily = NanumSquareFontFamily, + fontWeight = FontWeight.Normal ) } if (showImage) { diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt index 9c47c41e..e603ae5b 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt @@ -1,6 +1,7 @@ package com.wafflestudio.siksha2.compose.ui.menuDetail import android.net.Uri +import android.widget.Toast import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.clickable @@ -31,7 +32,9 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.rotate import androidx.compose.ui.graphics.ColorFilter +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.painterResource +import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp @@ -41,6 +44,7 @@ import androidx.paging.compose.collectAsLazyPagingItems import com.wafflestudio.siksha2.R import com.wafflestudio.siksha2.components.compose.ErrorComponent import com.wafflestudio.siksha2.components.compose.LoadingComponent +import com.wafflestudio.siksha2.components.compose.NanumSquareFontFamily import com.wafflestudio.siksha2.components.compose.menuDetail.ItemRatingBars import com.wafflestudio.siksha2.components.compose.menuDetail.ItemRatingStars import com.wafflestudio.siksha2.components.compose.menuDetail.ItemReview @@ -57,6 +61,7 @@ import kotlin.math.round fun MenuDetailScreen( navController: NavController, menuId: Long, + isTodayMenu: Boolean, modifier: Modifier = Modifier, menuDetailViewModel: MenuDetailViewModel = hiltViewModel(), ) { @@ -67,6 +72,7 @@ fun MenuDetailScreen( val imageReviews = imageReviewFlow?.collectAsLazyPagingItems() val loadingState = menuDetailViewModel.networkResultState.observeAsState() val imagePreviewScrollState = rememberScrollState() + val context = LocalContext.current LaunchedEffect(menuDetailViewModel) { menuDetailViewModel.refreshMenu(menuId) @@ -99,6 +105,8 @@ fun MenuDetailScreen( .fillMaxWidth(0.72f) .align(Alignment.Center), fontSize = dpToSp(20.dp), + fontFamily = NanumSquareFontFamily, + fontWeight = FontWeight.Bold, overflow = TextOverflow.Ellipsis, textAlign = TextAlign.Center, color = SikshaColors.White900 @@ -131,7 +139,9 @@ fun MenuDetailScreen( ) Text( text = "좋아요 " + (menu?.likeCount ?: 0).toString() + "개", - fontSize = dpToSp(14.dp) + fontSize = dpToSp(14.dp), + fontFamily = NanumSquareFontFamily, + fontWeight = FontWeight.Normal ) } @@ -158,22 +168,30 @@ fun MenuDetailScreen( Text( text = "총 ", color = SikshaColors.Gray800, - fontSize = dpToSp(10.dp) + fontSize = dpToSp(10.dp), + fontFamily = NanumSquareFontFamily, + fontWeight = FontWeight.Bold ) Text( text = reviews?.itemCount.toString(), color = SikshaColors.OrangeMain, - fontSize = dpToSp(10.dp) + fontSize = dpToSp(10.dp), + fontFamily = NanumSquareFontFamily, + fontWeight = FontWeight.Bold ) Text( text = "명", color = SikshaColors.OrangeMain, - fontSize = dpToSp(10.dp) + fontSize = dpToSp(10.dp), + fontFamily = NanumSquareFontFamily, + fontWeight = FontWeight.Bold ) Text( text = "이 평가했어요!", color = SikshaColors.Gray800, - fontSize = dpToSp(10.dp) + fontSize = dpToSp(10.dp), + fontFamily = NanumSquareFontFamily, + fontWeight = FontWeight.Bold ) } @@ -191,7 +209,9 @@ fun MenuDetailScreen( text = "${ menu?.score?.times(10)?.let { round(it) / 10 } ?: "0.0" }", - fontSize = dpToSp(32.dp) + fontSize = dpToSp(32.dp), + fontFamily = NanumSquareFontFamily, + fontWeight = FontWeight.ExtraBold ) ItemRatingStars( rating = menu?.score?.toFloat() ?: 0.0f @@ -219,11 +239,20 @@ fun MenuDetailScreen( Text( text = "나의 평가 남기기", fontSize = dpToSp(14.dp), + fontFamily = NanumSquareFontFamily, + fontWeight = FontWeight.ExtraBold, color = SikshaColors.White900, modifier = Modifier .align(Alignment.Center) .clickable { - navController.navigate(MenuDetailFragmentDirections.actionMenuDetailFragmentToLeaveReviewFragment()) + if(isTodayMenu) + navController.navigate(MenuDetailFragmentDirections.actionMenuDetailFragmentToLeaveReviewFragment()) + else + Toast.makeText( + context, + "오늘 메뉴만 평가할 수 있습니다.", + Toast.LENGTH_SHORT + ).show() } ) } @@ -247,6 +276,8 @@ fun MenuDetailScreen( Text( text = "사진 리뷰 모아보기", fontSize = dpToSp(14.dp), + fontFamily = NanumSquareFontFamily, + fontWeight = FontWeight.Normal, modifier = Modifier.align(Alignment.CenterStart) ) Image( @@ -323,6 +354,8 @@ fun MenuDetailScreen( Text( text = "리뷰", fontSize = dpToSp(14.dp), + fontFamily = NanumSquareFontFamily, + fontWeight = FontWeight.Normal, modifier = Modifier.align(Alignment.CenterStart) ) Image( @@ -363,6 +396,8 @@ fun MenuDetailScreen( Text( text = "리뷰가 없습니다.", fontSize = dpToSp(18.dp), + fontFamily = NanumSquareFontFamily, + fontWeight = FontWeight.Light, modifier = Modifier.align(Alignment.Center), color = SikshaColors.Gray600 ) diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt index 2ba69c6b..9fbd7da7 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt @@ -18,11 +18,13 @@ import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource +import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel import androidx.navigation.NavController import androidx.paging.compose.collectAsLazyPagingItems import com.wafflestudio.siksha2.R +import com.wafflestudio.siksha2.components.compose.NanumSquareFontFamily import com.wafflestudio.siksha2.components.compose.menuDetail.ItemReview import com.wafflestudio.siksha2.ui.SikshaColors import com.wafflestudio.siksha2.ui.menuDetail.MenuDetailViewModel @@ -65,6 +67,8 @@ fun ReviewScreen( .padding(horizontal = 10.dp, vertical = 12.dp) .align(Alignment.Center), fontSize = dpToSp(20.dp), + fontFamily = NanumSquareFontFamily, + fontWeight = FontWeight.Bold, color = SikshaColors.White900 ) } @@ -78,6 +82,8 @@ fun ReviewScreen( Text( text = "리뷰가 없습니다.", fontSize = dpToSp(18.dp), + fontFamily = NanumSquareFontFamily, + fontWeight = FontWeight.Normal, modifier = Modifier.align(Alignment.Center), color = SikshaColors.Gray600 ) diff --git a/app/src/main/java/com/wafflestudio/siksha2/repositories/MenuRepository.kt b/app/src/main/java/com/wafflestudio/siksha2/repositories/MenuRepository.kt index 72879b8c..ff4e4078 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/repositories/MenuRepository.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/repositories/MenuRepository.kt @@ -55,13 +55,12 @@ class MenuRepository @Inject constructor( return sikshaApi.fetchMenuById(menuId) } - // TODO: 리포지토리에서 Pager 제거 - fun getPagedReviewsByMenuIdFlow(menuId: Long): Flow> { - return Pager( - config = MenuReviewPagingSource.Config, - pagingSourceFactory = { MenuReviewPagingSource(sikshaApi, menuId) } - ).flow - } +// fun getPagedReviewsByMenuIdFlow(menuId: Long): Flow> { +// return Pager( +// config = MenuReviewPagingSource.Config, +// pagingSourceFactory = { MenuReviewPagingSource(sikshaApi, menuId) } +// ).flow +// } fun getPagedReviewsOnlyHaveImagesByMenuIdFlow(menuId: Long): Flow> { return Pager( @@ -92,9 +91,9 @@ class MenuRepository @Inject constructor( return sikshaApi.fetchReviewDistribution(menuId).dist } - suspend fun getFirstReviewPhotoByMenuId(menuId: Long): FetchReviewsResult { - return sikshaApi.fetchReviewsWithImage(menuId, 1L, 5) - } +// suspend fun getFirstReviewPhotoByMenuId(menuId: Long): FetchReviewsResult { +// return sikshaApi.fetchReviewsWithImage(menuId, 1L, 5) +// } suspend fun toggleLike(menuId: Long, isCurrentlyLiked: Boolean): MenuLikeOrUnlikeResponse { return if (isCurrentlyLiked) { diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt index 13eb71df..70e10b66 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt @@ -104,30 +104,30 @@ class MenuDetailViewModel @Inject constructor( } } - fun refreshImages(menuId: Long) { - viewModelScope.launch { - try { - val data = menuRepository.getFirstReviewPhotoByMenuId(menuId) - _imageCount.value = data.totalCount - val urlList = emptyList().toMutableList() - for (i in 0 until 3) { - if (i < data.result.size) { - data.result[i].etc?.images?.get(0)?.let { - urlList.add(it) - } - } - } - _imageUrlList.value = urlList - } catch (e: IOException) { - _imageUrlList.value = emptyList() - _networkResultState.value = State.FAILED - } - } - } - - fun getReviews(menuId: Long): Flow> { - return menuRepository.getPagedReviewsByMenuIdFlow(menuId).cachedIn(viewModelScope) - } +// fun refreshImages(menuId: Long) { +// viewModelScope.launch { +// try { +// val data = menuRepository.getFirstReviewPhotoByMenuId(menuId) +// _imageCount.value = data.totalCount +// val urlList = emptyList().toMutableList() +// for (i in 0 until 3) { +// if (i < data.result.size) { +// data.result[i].etc?.images?.get(0)?.let { +// urlList.add(it) +// } +// } +// } +// _imageUrlList.value = urlList +// } catch (e: IOException) { +// _imageUrlList.value = emptyList() +// _networkResultState.value = State.FAILED +// } +// } +// } + +// fun getReviews(menuId: Long): Flow> { +// return menuRepository.getPagedReviewsByMenuIdFlow(menuId).cachedIn(viewModelScope) +// } fun getReviewsWithImages(menuId: Long): Flow> { return menuRepository.getPagedReviewsOnlyHaveImagesByMenuIdFlow(menuId) From 9eb5e8bf3a68324313bf82bca3cf09f887c40792 Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Thu, 15 Feb 2024 19:22:22 +0900 Subject: [PATCH 40/68] =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=EC=82=AC=EC=A7=84?= =?UTF-8?q?=20dialog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../compose/menuDetail/ItemReviewImage.kt | 17 ++++- .../menuDetail/ItemReviewImageDialog.kt | 65 +++++++++++++++++++ .../ui/menuDetail/MenuDetailFragment.kt | 8 +-- 3 files changed, 83 insertions(+), 7 deletions(-) create mode 100644 app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReviewImageDialog.kt diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReviewImage.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReviewImage.kt index 32d3c43b..38d170d1 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReviewImage.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReviewImage.kt @@ -10,6 +10,10 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material.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.graphics.Color @@ -28,19 +32,26 @@ import com.wafflestudio.siksha2.utils.dpToSp fun ItemReviewImage( imageUri: Uri, modifier: Modifier = Modifier, - onClick: () -> Unit = {}, onDelete: () -> Unit = {}, onShowMore: () -> Unit = {}, showMore: Int? = null, deletable: Boolean = false ) { + var imageDialogState by remember{ mutableStateOf(false) } + Box( modifier = modifier ) { + if(imageDialogState && showMore == null){ + ItemReviewImageDialog(url = imageUri, onDismiss = { imageDialogState = false }) + } Image( - modifier = Modifier.fillMaxSize() + modifier = Modifier + .fillMaxSize() .align(Alignment.Center) - .clickable { if(showMore == null) onClick() }, + .clickable { + if (showMore == null) imageDialogState = true + }, painter = rememberAsyncImagePainter(imageUri), contentDescription = null, contentScale = ContentScale.Crop diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReviewImageDialog.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReviewImageDialog.kt new file mode 100644 index 00000000..7d9fab85 --- /dev/null +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReviewImageDialog.kt @@ -0,0 +1,65 @@ +package com.wafflestudio.siksha2.components.compose.menuDetail + +import android.net.Uri +import androidx.compose.foundation.Image +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.heightIn +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.layout.widthIn +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.unit.dp +import androidx.compose.ui.window.Dialog +import androidx.compose.ui.window.DialogProperties +import coil.compose.rememberAsyncImagePainter +import com.wafflestudio.siksha2.R + +@Composable +fun ItemReviewImageDialog( + url: Uri, + onDismiss: () -> Unit, + modifier: Modifier = Modifier +) { + Dialog( + onDismissRequest = onDismiss, + content = { + Column( + modifier = Modifier + .padding(20.dp) + .heightIn(0.dp, 330.dp) + .widthIn(0.dp, 300.dp) + .fillMaxSize() + ) { + Image( + painter = painterResource(id = R.drawable.ic_close_white), + contentDescription = "닫기", + modifier = Modifier.padding(bottom = 10.dp) + .size(20.dp) + .clickable { + onDismiss() + } + .align(Alignment.End) + ) + Image( + painter = rememberAsyncImagePainter(url), + contentDescription = null, + contentScale = ContentScale.Crop, + modifier = Modifier + .heightIn(0.dp, 300.dp) + .widthIn(0.dp, 300.dp) + .align(Alignment.CenterHorizontally) + ) + } + } + ) +} diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt index d92c2a75..872de836 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt @@ -197,8 +197,8 @@ class MenuDetailFragment : Fragment() { } } - companion object { - private const val NO_REVIEW_DIST_BAR_WIDTH_DP = 8 - private const val MAX_REVIEW_DIST_BAR_WIDTH_DP = 180 - } +// companion object { +// private const val NO_REVIEW_DIST_BAR_WIDTH_DP = 8 +// private const val MAX_REVIEW_DIST_BAR_WIDTH_DP = 180 +// } } From 480dc369a2ff3ea1963fb2be8ebab5edc090655d Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Thu, 15 Feb 2024 19:23:38 +0900 Subject: [PATCH 41/68] formatting --- .../components/compose/ErrorComponent.kt | 4 +- .../components/compose/LoadingComponent.kt | 2 +- .../compose/menuDetail/ItemRatingBars.kt | 12 +++-- .../compose/menuDetail/ItemRatingStars.kt | 2 +- .../compose/menuDetail/ItemReview.kt | 4 +- .../compose/menuDetail/ItemReviewImage.kt | 5 +- .../menuDetail/ItemReviewImageDialog.kt | 5 -- .../compose/menuDetail/LikeButton.kt | 9 ++-- .../compose/ui/menuDetail/MenuDetailScreen.kt | 51 ++++++++++--------- .../ui/menuDetail/review/ReviewScreen.kt | 11 ++-- .../siksha2/repositories/MenuRepository.kt | 9 ++-- .../ui/menuDetail/MenuDetailFragment.kt | 10 ---- .../ui/menuDetail/MenuDetailViewModel.kt | 49 ++++++++++-------- .../ui/menuDetail/review/ReviewFragment.kt | 2 +- 14 files changed, 87 insertions(+), 88 deletions(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/ErrorComponent.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/ErrorComponent.kt index 53d96fa4..975bf329 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/components/compose/ErrorComponent.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/ErrorComponent.kt @@ -20,12 +20,12 @@ import com.wafflestudio.siksha2.utils.dpToSp @Composable fun ErrorComponent( modifier: Modifier = Modifier -){ +) { Column( modifier = modifier, horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center - ){ + ) { Image( painter = painterResource(R.drawable.ic_warning), contentDescription = null, diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/LoadingComponent.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/LoadingComponent.kt index 36bc0659..8b3a5404 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/components/compose/LoadingComponent.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/LoadingComponent.kt @@ -22,7 +22,7 @@ fun LoadingComponent( Box( modifier = modifier, contentAlignment = Alignment.Center - ){ + ) { LottieAnimation( composition = composition, progress = { progress }, diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemRatingBars.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemRatingBars.kt index 0b9181a2..308f2f90 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemRatingBars.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemRatingBars.kt @@ -52,7 +52,7 @@ fun ItemRatingBar( .width(8.dp) .height(8.dp) ) - if(ratio > 0.0f) + if (ratio > 0.0f) { Box( modifier = Modifier .weight(ratio) @@ -66,9 +66,11 @@ fun ItemRatingBar( bottomStart = CornerSize(0.dp) ) ) - ){} - if(ratio < 1.0f) + ) {} + } + if (ratio < 1.0f) { Spacer(modifier = Modifier.weight(1.0f - ratio)) + } } } @@ -83,9 +85,9 @@ fun ItemRatingBars( modifier = modifier, verticalArrangement = Arrangement.spacedBy(5.dp) ) { - distList.reversed().forEachIndexed{ index, cnt -> + distList.reversed().forEachIndexed { index, cnt -> ItemRatingBar( - ratingIndex = 5-index, + ratingIndex = 5 - index, ratio = cnt.toFloat() / maxCount.toFloat() ) } diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemRatingStars.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemRatingStars.kt index 8d906922..1bbb5049 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemRatingStars.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemRatingStars.kt @@ -52,7 +52,7 @@ fun ItemRatingStars( Row( horizontalArrangement = Arrangement.spacedBy(gap) ) { - for (i in 1..5){ + for (i in 1..5) { ItemReviewSingleStar( flag = i * 2 - rounds, modifier = Modifier diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReview.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReview.kt index 76cd7a99..da085b39 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReview.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReview.kt @@ -84,7 +84,7 @@ fun ItemReview( color = SikshaColors.Gray500 ) } - Box ( + Box( modifier = Modifier .fillMaxWidth() .defaultMinSize(minHeight = 80.dp) @@ -114,7 +114,7 @@ fun ItemReview( .horizontalScroll(rememberScrollState()), horizontalArrangement = Arrangement.spacedBy(4.dp) ) { - for(imageUri in review?.etc?.images ?: listOf()){ + for (imageUri in review?.etc?.images ?: listOf()) { ItemReviewImage( imageUri = Uri.parse(imageUri), modifier = Modifier.size(100.dp) diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReviewImage.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReviewImage.kt index 38d170d1..06f9ff6a 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReviewImage.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReviewImage.kt @@ -27,7 +27,6 @@ import com.wafflestudio.siksha2.R import com.wafflestudio.siksha2.ui.SikshaColors import com.wafflestudio.siksha2.utils.dpToSp - @Composable fun ItemReviewImage( imageUri: Uri, @@ -37,12 +36,12 @@ fun ItemReviewImage( showMore: Int? = null, deletable: Boolean = false ) { - var imageDialogState by remember{ mutableStateOf(false) } + var imageDialogState by remember { mutableStateOf(false) } Box( modifier = modifier ) { - if(imageDialogState && showMore == null){ + if (imageDialogState && showMore == null) { ItemReviewImageDialog(url = imageUri, onDismiss = { imageDialogState = false }) } Image( diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReviewImageDialog.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReviewImageDialog.kt index 7d9fab85..77c51a8b 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReviewImageDialog.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReviewImageDialog.kt @@ -3,15 +3,11 @@ package com.wafflestudio.siksha2.components.compose.menuDetail import android.net.Uri import androidx.compose.foundation.Image import androidx.compose.foundation.clickable -import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size -import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.widthIn import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment @@ -20,7 +16,6 @@ import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.res.painterResource import androidx.compose.ui.unit.dp import androidx.compose.ui.window.Dialog -import androidx.compose.ui.window.DialogProperties import coil.compose.rememberAsyncImagePainter import com.wafflestudio.siksha2.R diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/LikeButton.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/LikeButton.kt index d331e778..9fe5c152 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/LikeButton.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/LikeButton.kt @@ -11,12 +11,15 @@ import com.wafflestudio.siksha2.R fun LikeButton( isChecked: Boolean, modifier: Modifier = Modifier, - onClick: () -> Unit = {}, + onClick: () -> Unit = {} ) { Image( painter = painterResource( - if(isChecked) R.drawable.ic_full_heart_small - else R.drawable.ic_empty_heart_small + if (isChecked) { + R.drawable.ic_full_heart_small + } else { + R.drawable.ic_empty_heart_small + } ), contentDescription = "좋아요", modifier = modifier.clickable { onClick() } diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt index e603ae5b..ef84f781 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt @@ -63,7 +63,7 @@ fun MenuDetailScreen( menuId: Long, isTodayMenu: Boolean, modifier: Modifier = Modifier, - menuDetailViewModel: MenuDetailViewModel = hiltViewModel(), + menuDetailViewModel: MenuDetailViewModel = hiltViewModel() ) { val menu by menuDetailViewModel.menu.observeAsState() val reviewFlow by menuDetailViewModel.reviews.collectAsState() @@ -112,8 +112,8 @@ fun MenuDetailScreen( color = SikshaColors.White900 ) } - - when(loadingState.value){ + + when (loadingState.value) { MenuDetailViewModel.State.SUCCESS -> { LazyColumn( modifier = Modifier @@ -207,7 +207,7 @@ fun MenuDetailScreen( ) { Text( text = "${ - menu?.score?.times(10)?.let { round(it) / 10 } ?: "0.0" + menu?.score?.times(10)?.let { round(it) / 10 } ?: "0.0" }", fontSize = dpToSp(32.dp), fontFamily = NanumSquareFontFamily, @@ -245,28 +245,31 @@ fun MenuDetailScreen( modifier = Modifier .align(Alignment.Center) .clickable { - if(isTodayMenu) + if (isTodayMenu) { navController.navigate(MenuDetailFragmentDirections.actionMenuDetailFragmentToLeaveReviewFragment()) - else + } else { Toast.makeText( context, "오늘 메뉴만 평가할 수 있습니다.", Toast.LENGTH_SHORT ).show() + } } ) } } - Spacer(modifier = Modifier - .fillMaxWidth() - .height(10.dp) - .background(SikshaColors.Gray100)) + Spacer( + modifier = Modifier + .fillMaxWidth() + .height(10.dp) + .background(SikshaColors.Gray100) + ) } } // 사진 리뷰 if (imageReviews != null && imageReviews.itemCount > 0) { - item{ + item { Box( modifier = Modifier .fillMaxWidth() @@ -302,15 +305,17 @@ fun MenuDetailScreen( .padding(horizontal = 16.dp) .horizontalScroll(imagePreviewScrollState), horizontalArrangement = Arrangement.spacedBy(8.dp) - ){ - for(i: Int in 1..min(imageReviews.itemCount,3)){ - when(val it = imageReviews.itemSnapshotList.items[i-1].etc?.images?.get(0)){ - null -> Box(modifier= Modifier - .size(120.dp) - .background(SikshaColors.Gray100) - .clip(RoundedCornerShape(10.dp))) + ) { + for (i: Int in 1..min(imageReviews.itemCount, 3)) { + when (val it = imageReviews.itemSnapshotList.items[i - 1].etc?.images?.get(0)) { + null -> Box( + modifier = Modifier + .size(120.dp) + .background(SikshaColors.Gray100) + .clip(RoundedCornerShape(10.dp)) + ) else -> { - if(i==3) { + if (i == 3) { ItemReviewImage( imageUri = Uri.parse(it), modifier = Modifier @@ -326,8 +331,7 @@ fun MenuDetailScreen( ) } ) - } - else{ + } else { ItemReviewImage( imageUri = Uri.parse(it), modifier = Modifier @@ -343,7 +347,7 @@ fun MenuDetailScreen( } // 일반 리뷰 - if(reviews != null && reviews.itemCount > 0) { + if (reviews != null && reviews.itemCount > 0) { item { Box( modifier = Modifier @@ -385,8 +389,7 @@ fun MenuDetailScreen( showImage = true ) } - } - else{ + } else { item { Box( modifier = Modifier diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt index 9fbd7da7..79d7029d 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt @@ -35,11 +35,14 @@ fun ReviewScreen( navController: NavController, modifier: Modifier = Modifier, menuDetailViewModel: MenuDetailViewModel = hiltViewModel(), - showImages: Boolean = false, + showImages: Boolean = false ) { val reviewFlow by - if(!showImages) menuDetailViewModel.reviews.collectAsState() - else menuDetailViewModel.reviewsWithImage.collectAsState() + if (!showImages) { + menuDetailViewModel.reviews.collectAsState() + } else { + menuDetailViewModel.reviewsWithImage.collectAsState() + } val reviews = reviewFlow?.collectAsLazyPagingItems() Column( @@ -57,7 +60,7 @@ fun ReviewScreen( modifier = Modifier .padding(horizontal = 20.dp, vertical = 16.dp) .align(Alignment.CenterStart) - .clickable{ + .clickable { navController.popBackStack() } ) diff --git a/app/src/main/java/com/wafflestudio/siksha2/repositories/MenuRepository.kt b/app/src/main/java/com/wafflestudio/siksha2/repositories/MenuRepository.kt index ff4e4078..d31607a0 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/repositories/MenuRepository.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/repositories/MenuRepository.kt @@ -7,7 +7,6 @@ import com.wafflestudio.siksha2.models.DailyMenu import com.wafflestudio.siksha2.models.Menu import com.wafflestudio.siksha2.models.Review import com.wafflestudio.siksha2.network.SikshaApi -import com.wafflestudio.siksha2.network.dto.FetchReviewsResult import com.wafflestudio.siksha2.network.dto.LeaveReviewParam import com.wafflestudio.siksha2.network.dto.LeaveReviewResult import com.wafflestudio.siksha2.network.dto.MenuLikeOrUnlikeResponse @@ -69,11 +68,11 @@ class MenuRepository @Inject constructor( ).flow } - fun menuReviewPagingSource(menuId: Long): MenuReviewPagingSource - = MenuReviewPagingSource(sikshaApi, menuId) + fun menuReviewPagingSource(menuId: Long): MenuReviewPagingSource = + MenuReviewPagingSource(sikshaApi, menuId) - fun menuReviewWithImagePagingSource(menuId: Long): MenuReviewWithImagePagingSource - = MenuReviewWithImagePagingSource(sikshaApi, menuId) + fun menuReviewWithImagePagingSource(menuId: Long): MenuReviewWithImagePagingSource = + MenuReviewWithImagePagingSource(sikshaApi, menuId) suspend fun leaveMenuReview(menuId: Long, score: Double, comment: String): LeaveReviewResult { return sikshaApi.leaveMenuReview(LeaveReviewParam(menuId, score, comment)) diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt index 872de836..d0ac9e2a 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt @@ -6,20 +6,11 @@ import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels -import androidx.lifecycle.lifecycleScope import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.navArgs -import androidx.paging.LoadState -import androidx.recyclerview.widget.LinearLayoutManager import com.wafflestudio.siksha2.compose.ui.menuDetail.MenuDetailScreen import com.wafflestudio.siksha2.databinding.FragmentMenuDetailBinding -import com.wafflestudio.siksha2.utils.dp -import com.wafflestudio.siksha2.utils.showToast -import com.wafflestudio.siksha2.utils.setVisibleOrGone import dagger.hilt.android.AndroidEntryPoint -import kotlinx.coroutines.flow.collectLatest -import kotlinx.coroutines.launch -import kotlin.math.round @AndroidEntryPoint class MenuDetailFragment : Fragment() { @@ -186,7 +177,6 @@ class MenuDetailFragment : Fragment() { // } // } - binding.menuDetailComposeView.setContent { MenuDetailScreen( navController = findNavController(), diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt index 70e10b66..3ce7bd76 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt @@ -10,7 +10,6 @@ import androidx.lifecycle.asFlow import androidx.lifecycle.viewModelScope import androidx.paging.Pager import androidx.paging.PagingData -import androidx.paging.cachedIn import com.wafflestudio.siksha2.models.Menu import com.wafflestudio.siksha2.models.Review import com.wafflestudio.siksha2.repositories.MenuRepository @@ -70,27 +69,33 @@ class MenuDetailViewModel @Inject constructor( val leaveReviewState: LiveData get() = _leaveReviewState - val reviews: StateFlow>?> - = _menu.asFlow().map { menu -> - if(menu != null) Pager( - config = MenuReviewPagingSource.Config, - pagingSourceFactory = { - menuRepository.menuReviewPagingSource(menu.id) + val reviews: StateFlow>?> = + _menu.asFlow().map { menu -> + if (menu != null) { + Pager( + config = MenuReviewPagingSource.Config, + pagingSourceFactory = { + menuRepository.menuReviewPagingSource(menu.id) + } + ).flow + } else { + null } - ).flow - else null - }.stateIn(viewModelScope, SharingStarted.Eagerly, initialValue = null) - - val reviewsWithImage: StateFlow>?> - = _menu.asFlow().map { menu -> - if(menu != null) Pager( - config = MenuReviewWithImagePagingSource.Config, - pagingSourceFactory = { - menuRepository.menuReviewWithImagePagingSource(menu.id) + }.stateIn(viewModelScope, SharingStarted.Eagerly, initialValue = null) + + val reviewsWithImage: StateFlow>?> = + _menu.asFlow().map { menu -> + if (menu != null) { + Pager( + config = MenuReviewWithImagePagingSource.Config, + pagingSourceFactory = { + menuRepository.menuReviewWithImagePagingSource(menu.id) + } + ).flow + } else { + null } - ).flow - else null - }.stateIn(viewModelScope, SharingStarted.Eagerly, initialValue = null) + }.stateIn(viewModelScope, SharingStarted.Eagerly, initialValue = null) fun refreshMenu(menuId: Long) { _networkResultState.value = State.LOADING @@ -182,8 +187,8 @@ class MenuDetailViewModel @Inject constructor( _leaveReviewState.value = ReviewState.WAITING } - fun toggleLike(){ - if(menu.value != null) { + fun toggleLike() { + if (menu.value != null) { toggleLike(menu.value!!.id, menu.value!!.isLiked ?: false) } } diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt index e3a0f42e..418acb00 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt @@ -29,7 +29,7 @@ class ReviewFragment : Fragment() { } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - binding.reviewComposeView.setContent { + binding.reviewComposeView.setContent { ReviewScreen( navController = findNavController(), showImages = args.showImages, From 8a391ea518312b44dc940be256af950db0d2c917 Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Wed, 28 Feb 2024 02:39:23 +0900 Subject: [PATCH 42/68] =?UTF-8?q?=EC=9D=B4=EB=A6=84=20=EC=88=98=EC=A0=95?= =?UTF-8?q?=20+=20=EC=9E=90=EC=9E=98=ED=95=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...{ErrorComponent.kt => ErrorPlaceHolder.kt} | 2 +- ...dingComponent.kt => LoadingPlaceHolder.kt} | 2 +- .../compose/menuDetail/ItemReview.kt | 4 +- .../{ItemRatingBars.kt => MenuRatingBars.kt} | 23 +-- ...{ItemRatingStars.kt => MenuRatingStars.kt} | 18 +-- ...{ItemReviewImage.kt => MenuReviewImage.kt} | 26 +-- ...mageDialog.kt => MenuReviewImageDialog.kt} | 4 +- .../compose/ui/menuDetail/MenuDetailScreen.kt | 24 +-- .../ui/menuDetail/review/ReviewScreen.kt | 1 + .../ui/menuDetail/MenuDetailFragment.kt | 152 ------------------ .../ui/menuDetail/MenuDetailViewModel.kt | 25 --- 11 files changed, 31 insertions(+), 250 deletions(-) rename app/src/main/java/com/wafflestudio/siksha2/components/compose/{ErrorComponent.kt => ErrorPlaceHolder.kt} (98%) rename app/src/main/java/com/wafflestudio/siksha2/components/compose/{LoadingComponent.kt => LoadingPlaceHolder.kt} (97%) rename app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/{ItemRatingBars.kt => MenuRatingBars.kt} (88%) rename app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/{ItemRatingStars.kt => MenuRatingStars.kt} (81%) rename app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/{ItemReviewImage.kt => MenuReviewImage.kt} (72%) rename app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/{ItemReviewImageDialog.kt => MenuReviewImageDialog.kt} (97%) diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/ErrorComponent.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/ErrorPlaceHolder.kt similarity index 98% rename from app/src/main/java/com/wafflestudio/siksha2/components/compose/ErrorComponent.kt rename to app/src/main/java/com/wafflestudio/siksha2/components/compose/ErrorPlaceHolder.kt index 975bf329..d56db6ee 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/components/compose/ErrorComponent.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/ErrorPlaceHolder.kt @@ -18,7 +18,7 @@ import com.wafflestudio.siksha2.ui.SikshaColors import com.wafflestudio.siksha2.utils.dpToSp @Composable -fun ErrorComponent( +fun ErrorPlaceHolder( modifier: Modifier = Modifier ) { Column( diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/LoadingComponent.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/LoadingPlaceHolder.kt similarity index 97% rename from app/src/main/java/com/wafflestudio/siksha2/components/compose/LoadingComponent.kt rename to app/src/main/java/com/wafflestudio/siksha2/components/compose/LoadingPlaceHolder.kt index 8b3a5404..36744e93 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/components/compose/LoadingComponent.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/LoadingPlaceHolder.kt @@ -14,7 +14,7 @@ import com.airbnb.lottie.compose.rememberLottieComposition import com.wafflestudio.siksha2.R @Composable -fun LoadingComponent( +fun LoadingPlaceHolder( modifier: Modifier = Modifier ) { val composition by rememberLottieComposition(LottieCompositionSpec.RawRes(R.raw.ani_loading)) diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReview.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReview.kt index da085b39..16d82584 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReview.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReview.kt @@ -70,7 +70,7 @@ fun ItemReview( fontFamily = NanumSquareFontFamily, fontWeight = FontWeight.Bold ) - ItemRatingStars(review?.score?.toFloat() ?: 0.0f) + MenuRatingStars(review?.score?.toFloat() ?: 0.0f) } } Text( @@ -115,7 +115,7 @@ fun ItemReview( horizontalArrangement = Arrangement.spacedBy(4.dp) ) { for (imageUri in review?.etc?.images ?: listOf()) { - ItemReviewImage( + MenuReviewImage( imageUri = Uri.parse(imageUri), modifier = Modifier.size(100.dp) .clip(shape = RoundedCornerShape(8.dp)) diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemRatingBars.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuRatingBars.kt similarity index 88% rename from app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemRatingBars.kt rename to app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuRatingBars.kt index 308f2f90..5bbea98d 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemRatingBars.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuRatingBars.kt @@ -24,9 +24,10 @@ import com.wafflestudio.siksha2.R import com.wafflestudio.siksha2.components.compose.NanumSquareFontFamily import com.wafflestudio.siksha2.ui.SikshaColors import com.wafflestudio.siksha2.utils.dpToSp +import kotlin.math.max @Composable -fun ItemRatingBar( +fun MenuRatingBar( ratingIndex: Int, ratio: Float, modifier: Modifier = Modifier @@ -75,30 +76,20 @@ fun ItemRatingBar( } @Composable -fun ItemRatingBars( - distList: List, +fun MenuRatingBars( + distributions: List, modifier: Modifier = Modifier ) { - var maxCount = 1L - distList.forEach { if (maxCount < it) maxCount = it } + val maxCount = max(distributions.max(), 1L) Column( modifier = modifier, verticalArrangement = Arrangement.spacedBy(5.dp) ) { - distList.reversed().forEachIndexed { index, cnt -> - ItemRatingBar( + distributions.reversed().forEachIndexed { index, cnt -> + MenuRatingBar( ratingIndex = 5 - index, ratio = cnt.toFloat() / maxCount.toFloat() ) } } } - -@Composable -@Preview -fun ItemRatingBarsPreview() { - ItemRatingBars( - distList = listOf(5L, 2L, 1L, 0L, 2L), - modifier = Modifier.width(160.dp) - ) -} diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemRatingStars.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuRatingStars.kt similarity index 81% rename from app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemRatingStars.kt rename to app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuRatingStars.kt index 1bbb5049..d58b0c0e 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemRatingStars.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuRatingStars.kt @@ -15,7 +15,7 @@ import com.wafflestudio.siksha2.R import kotlin.math.roundToInt @Composable -private fun ItemReviewSingleStar( +private fun MenuReviewSingleStar( modifier: Modifier = Modifier, flag: Int ) { @@ -33,7 +33,7 @@ private fun ItemReviewSingleStar( } @Composable -fun ItemRatingStars( +fun MenuRatingStars( rating: Float, dragEnabled: Boolean = false, size: Int = 0 @@ -53,7 +53,7 @@ fun ItemRatingStars( horizontalArrangement = Arrangement.spacedBy(gap) ) { for (i in 1..5) { - ItemReviewSingleStar( + MenuReviewSingleStar( flag = i * 2 - rounds, modifier = Modifier .width(starMeasure) @@ -62,15 +62,3 @@ fun ItemRatingStars( } } } - -@Composable -@Preview -private fun StarsPreview() { - Column() { - ItemRatingStars(rating = 0.0f) - ItemRatingStars(rating = 1.0f, size = 2) - ItemRatingStars(rating = 2.5f, size = 1) - ItemRatingStars(rating = 3.5f) - ItemRatingStars(rating = 5.0f) - } -} diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReviewImage.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuReviewImage.kt similarity index 72% rename from app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReviewImage.kt rename to app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuReviewImage.kt index 06f9ff6a..75f2288d 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReviewImage.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuReviewImage.kt @@ -4,7 +4,6 @@ import android.net.Uri import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.clickable -import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize @@ -19,7 +18,6 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color 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.compose.ui.zIndex import coil.compose.rememberAsyncImagePainter @@ -28,7 +26,7 @@ import com.wafflestudio.siksha2.ui.SikshaColors import com.wafflestudio.siksha2.utils.dpToSp @Composable -fun ItemReviewImage( +fun MenuReviewImage( imageUri: Uri, modifier: Modifier = Modifier, onDelete: () -> Unit = {}, @@ -42,7 +40,7 @@ fun ItemReviewImage( modifier = modifier ) { if (imageDialogState && showMore == null) { - ItemReviewImageDialog(url = imageUri, onDismiss = { imageDialogState = false }) + MenuReviewImageDialog(url = imageUri, onDismiss = { imageDialogState = false }) } Image( modifier = Modifier @@ -92,23 +90,3 @@ fun ItemReviewImage( } } } - -@Composable -@Preview -fun ItemReviewImagePreview() { - Column( - verticalArrangement = Arrangement.SpaceBetween - ) { - ItemReviewImage( - imageUri = Uri.parse("https://postfiles.pstatic.net/MjAyMzExMjVfMjkw/MDAxNzAwOTIyODAzODEw.QqyDtG40dMPBGRLsCcplMuOgz-wTVx6aZ4UeeykP65Qg.Hscm0YN_F9pcPE2lndK0YV8eDKz7m2Hi1RMa0ocu2Wog.JPEG.jyurisenpai/20231125010057_1.jpg?type=w773") - ) - ItemReviewImage( - imageUri = Uri.parse("https://postfiles.pstatic.net/MjAyMzExMjZfMjcy/MDAxNzAwOTI3NTczMDY5.c9qVmjXE0nBVZpKukBxB9EB0LytpB5Olc6psLGQdWLQg.-D-zLjlG7bIPYm8XmYzK9-l1vitTZAGcimoHM57QATAg.JPEG.jyurisenpai/20231121203650_1.jpg?type=w773"), - deletable = true - ) - ItemReviewImage( - imageUri = Uri.parse("https://postfiles.pstatic.net/MjAyMzExMjZfMjU5/MDAxNzAwOTI3MjgxMjAz.f7jMVmS7vYGWKWswaOnnxCjgmaN0qgSt0_2VLB-XZrog.WMa7r-nHh9zw_QXO15bA4ts2NabuiEtQQkM6XYSiA1Ug.JPEG.jyurisenpai/20231118200550_1.jpg?type=w773"), - showMore = 3 - ) - } -} diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReviewImageDialog.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuReviewImageDialog.kt similarity index 97% rename from app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReviewImageDialog.kt rename to app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuReviewImageDialog.kt index 77c51a8b..e3e9f8fd 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReviewImageDialog.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuReviewImageDialog.kt @@ -20,7 +20,7 @@ import coil.compose.rememberAsyncImagePainter import com.wafflestudio.siksha2.R @Composable -fun ItemReviewImageDialog( +fun MenuReviewImageDialog( url: Uri, onDismiss: () -> Unit, modifier: Modifier = Modifier @@ -29,7 +29,7 @@ fun ItemReviewImageDialog( onDismissRequest = onDismiss, content = { Column( - modifier = Modifier + modifier = modifier .padding(20.dp) .heightIn(0.dp, 330.dp) .widthIn(0.dp, 300.dp) diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt index ef84f781..c540f286 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt @@ -42,13 +42,13 @@ import androidx.hilt.navigation.compose.hiltViewModel import androidx.navigation.NavController import androidx.paging.compose.collectAsLazyPagingItems import com.wafflestudio.siksha2.R -import com.wafflestudio.siksha2.components.compose.ErrorComponent -import com.wafflestudio.siksha2.components.compose.LoadingComponent +import com.wafflestudio.siksha2.components.compose.ErrorPlaceHolder +import com.wafflestudio.siksha2.components.compose.LoadingPlaceHolder import com.wafflestudio.siksha2.components.compose.NanumSquareFontFamily -import com.wafflestudio.siksha2.components.compose.menuDetail.ItemRatingBars -import com.wafflestudio.siksha2.components.compose.menuDetail.ItemRatingStars +import com.wafflestudio.siksha2.components.compose.menuDetail.MenuRatingBars +import com.wafflestudio.siksha2.components.compose.menuDetail.MenuRatingStars import com.wafflestudio.siksha2.components.compose.menuDetail.ItemReview -import com.wafflestudio.siksha2.components.compose.menuDetail.ItemReviewImage +import com.wafflestudio.siksha2.components.compose.menuDetail.MenuReviewImage import com.wafflestudio.siksha2.components.compose.menuDetail.LikeButton import com.wafflestudio.siksha2.ui.SikshaColors import com.wafflestudio.siksha2.ui.menuDetail.MenuDetailFragmentDirections @@ -213,13 +213,13 @@ fun MenuDetailScreen( fontFamily = NanumSquareFontFamily, fontWeight = FontWeight.ExtraBold ) - ItemRatingStars( + MenuRatingStars( rating = menu?.score?.toFloat() ?: 0.0f ) } menuDetailViewModel.reviewDistribution.value?.let { - ItemRatingBars( - distList = it, + MenuRatingBars( + distributions = it, modifier = Modifier.weight(1f) ) } @@ -316,7 +316,7 @@ fun MenuDetailScreen( ) else -> { if (i == 3) { - ItemReviewImage( + MenuReviewImage( imageUri = Uri.parse(it), modifier = Modifier .size(120.dp) @@ -332,7 +332,7 @@ fun MenuDetailScreen( } ) } else { - ItemReviewImage( + MenuReviewImage( imageUri = Uri.parse(it), modifier = Modifier .size(120.dp) @@ -410,14 +410,14 @@ fun MenuDetailScreen( } } MenuDetailViewModel.State.LOADING -> { - LoadingComponent( + LoadingPlaceHolder( modifier = Modifier .fillMaxWidth() .weight(1f) ) } MenuDetailViewModel.State.FAILED -> { - ErrorComponent( + ErrorPlaceHolder( modifier = Modifier .fillMaxWidth() .weight(1f) diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt index 79d7029d..fd46d9dd 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt @@ -48,6 +48,7 @@ fun ReviewScreen( Column( modifier = modifier.fillMaxSize() ) { + // TODO: 커뮤니티탭 머지 후 TopBar로 수정 Box( modifier = Modifier .fillMaxWidth() diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt index d0ac9e2a..796b6f8e 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt @@ -30,153 +30,6 @@ class MenuDetailFragment : Fragment() { } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { -// super.onViewCreated(view, savedInstanceState) -// -// reviewsAdapter = MenuReviewsAdapter(true, childFragmentManager) -// -// binding.reviewList.apply { -// layoutManager = LinearLayoutManager(context) -// adapter = reviewsAdapter -// } -// -// lifecycleScope.launch { -// reviewsAdapter.loadStateFlow -// .collectLatest { -// if (it.refresh is LoadState.NotLoading) { -// (reviewsAdapter.itemCount < 1).let { empty -> -// binding.emptyList.setVisibleOrGone(empty) -// binding.reviewList.setVisibleOrGone(empty.not()) -// } -// } -// } -// } -// -// vm.refreshMenu(args.menuId) -// vm.refreshImages(args.menuId) -// vm.refreshReviewDistribution(args.menuId) -// -// vm.networkResultState.observe(viewLifecycleOwner) { -// binding.menuInfoContainer.setVisibleOrGone(it == MenuDetailViewModel.State.SUCCESS) -// binding.onErrorContainer.root.setVisibleOrGone(it == MenuDetailViewModel.State.FAILED) -// binding.onLoadingContainer.root.setVisibleOrGone(it == MenuDetailViewModel.State.LOADING) -// } -// -// vm.menu.observe(viewLifecycleOwner) { menu -> -// // for marquee -// binding.menuTitle.isSelected = true -// binding.menuTitle.text = menu?.nameKr -// binding.menuRating.text = "${menu?.score?.times(10)?.let { round(it) / 10 } ?: "0.0"}" -// binding.menuStars.rating = menu?.score?.toFloat() ?: 0.0f -// binding.reviewCount.text = " ${menu?.reviewCount ?: 0}" -// // Handle menu likes -// menu.isLiked?.let { isLiked -> -// binding.menuLikeButton.isSelected = isLiked -// } -// -// // Handle like count -// menu.likeCount?.let { count -> -// binding.menuLikeCount.text = menu.likeCount?.let { "좋아요 $it 개" } ?: "-" -// } -// } -// -// vm.reviewDistribution.observe(viewLifecycleOwner) { distList -> -// if (distList.isEmpty()) return@observe -// val distBarList = listOf( -// binding.distBar1, -// binding.distBar2, -// binding.distBar3, -// binding.distBar4, -// binding.distBar5 -// ) -// var maxCount = 1L -// distList.forEach { if (maxCount < it) maxCount = it } -// distBarList.forEachIndexed { index, bar -> -// val params = bar.layoutParams -// val ratio = distList[index].toDouble() / maxCount.toDouble() -// if (ratio != 0.0) { -// params.width = -// (requireContext().dp(MAX_REVIEW_DIST_BAR_WIDTH_DP) * ratio).toInt() -// } else { -// params.width = requireContext().dp(NO_REVIEW_DIST_BAR_WIDTH_DP) -// } -// bar.layoutParams = params -// bar.requestLayout() -// } -// } -// -// vm.imageCount.observe(viewLifecycleOwner) { imageCount -> -// binding.layoutPhotoReview.setVisibleOrGone(imageCount > 0) -// if (imageCount > 3) { -// binding.reviewImageView3.showMorePhotos(imageCount - 3) -// binding.reviewImageView3.setOnClickListener { -// val action = -// MenuDetailFragmentDirections.actionMenuDetailFragmentToReviewPhotoFragment( -// args.menuId -// ) -// findNavController().navigate(action) -// } -// } -// } -// -// vm.imageUrlList.observe(viewLifecycleOwner) { imageUrlList -> -// val imageReviewList = -// listOf(binding.reviewImageView1, binding.reviewImageView2, binding.reviewImageView3) -// for (i in 0 until 3) { -// if (i < imageUrlList.size) { -// imageReviewList[i].run { -// setImage(imageUrlList[i]) -// setVisibleOrGone(true) -// } -// } -// } -// for (i in 0 until 2) { -// if (i < imageUrlList.size) { -// imageReviewList[i].setOnClickListener { -// val dialog = ReviewImageDialog(imageUrlList[i]) -// dialog.show(childFragmentManager, "review_image_${imageUrlList[i]}") -// } -// } -// } -// } -// -// lifecycleScope.launch { -// vm.getReviews(args.menuId).collectLatest { -// reviewsAdapter.submitData(it) -// } -// } -// -// binding.backButton.setOnClickListener { -// findNavController().popBackStack() -// } -// -// binding.layoutCollectPhotoReviews.setOnClickListener { -// val action = -// MenuDetailFragmentDirections.actionMenuDetailFragmentToReviewFragment(args.menuId, true) -// findNavController().navigate(action) -// } -// -// binding.layoutCollectReviews.setOnClickListener { -// val action = -// MenuDetailFragmentDirections.actionMenuDetailFragmentToReviewFragment(args.menuId, false) -// findNavController().navigate(action) -// } -// -// binding.leaveReviewButton.setOnClickListener { -// if (args.isTodayMenu) { -// val action = -// MenuDetailFragmentDirections.actionMenuDetailFragmentToLeaveReviewFragment() -// findNavController().navigate(action) -// } else { -// showToast("오늘 메뉴만 평가할 수 있습니다.") -// } -// } -// -// binding.menuLikeButton.setOnClickListener { -// vm.menu.value?.isLiked?.let { -// vm.toggleLike(args.menuId, it) -// } -// } - binding.menuDetailComposeView.setContent { MenuDetailScreen( navController = findNavController(), @@ -186,9 +39,4 @@ class MenuDetailFragment : Fragment() { ) } } - -// companion object { -// private const val NO_REVIEW_DIST_BAR_WIDTH_DP = 8 -// private const val MAX_REVIEW_DIST_BAR_WIDTH_DP = 180 -// } } diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt index 3ce7bd76..46b8bedd 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt @@ -109,31 +109,6 @@ class MenuDetailViewModel @Inject constructor( } } -// fun refreshImages(menuId: Long) { -// viewModelScope.launch { -// try { -// val data = menuRepository.getFirstReviewPhotoByMenuId(menuId) -// _imageCount.value = data.totalCount -// val urlList = emptyList().toMutableList() -// for (i in 0 until 3) { -// if (i < data.result.size) { -// data.result[i].etc?.images?.get(0)?.let { -// urlList.add(it) -// } -// } -// } -// _imageUrlList.value = urlList -// } catch (e: IOException) { -// _imageUrlList.value = emptyList() -// _networkResultState.value = State.FAILED -// } -// } -// } - -// fun getReviews(menuId: Long): Flow> { -// return menuRepository.getPagedReviewsByMenuIdFlow(menuId).cachedIn(viewModelScope) -// } - fun getReviewsWithImages(menuId: Long): Flow> { return menuRepository.getPagedReviewsOnlyHaveImagesByMenuIdFlow(menuId) } From e61f25bc226eb1b958637f3728b03489bf54676c Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Wed, 28 Feb 2024 21:51:36 +0900 Subject: [PATCH 43/68] =?UTF-8?q?MenuRatingStars=20=ED=81=AC=EA=B8=B0=20?= =?UTF-8?q?=EA=B3=84=EC=82=B0=20=EB=B0=A9=EC=8B=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../compose/menuDetail/ItemReview.kt | 5 +++- .../compose/menuDetail/MenuRatingStars.kt | 27 +++++++------------ 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReview.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReview.kt index 16d82584..746729ad 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReview.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReview.kt @@ -11,6 +11,7 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.defaultMinSize 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 @@ -70,7 +71,9 @@ fun ItemReview( fontFamily = NanumSquareFontFamily, fontWeight = FontWeight.Bold ) - MenuRatingStars(review?.score?.toFloat() ?: 0.0f) + MenuRatingStars( + rating = review?.score?.toFloat() ?: 0.0f + ) } } Text( diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuRatingStars.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuRatingStars.kt index d58b0c0e..8cd6c9ac 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuRatingStars.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuRatingStars.kt @@ -4,7 +4,10 @@ import androidx.compose.foundation.Image import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.aspectRatio +import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.width import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier @@ -28,36 +31,24 @@ private fun MenuReviewSingleStar( } ), contentDescription = null, - modifier = modifier + modifier = modifier.heightIn(max = 48.dp).fillMaxHeight().aspectRatio(1f) ) } @Composable fun MenuRatingStars( rating: Float, - dragEnabled: Boolean = false, - size: Int = 0 + modifier: Modifier = Modifier.width(100.dp).height(18.dp), + dragEnabled: Boolean = false ) { val rounds = (rating * 2).roundToInt() - val starMeasure = when (size) { - 2 -> 48.dp - 1 -> 33.dp - else -> 18.dp - } - val gap = when (size) { - 2 -> 12.dp - 1 -> 8.dp - else -> 4.dp - } Row( - horizontalArrangement = Arrangement.spacedBy(gap) + modifier = modifier, + horizontalArrangement = Arrangement.SpaceBetween ) { for (i in 1..5) { MenuReviewSingleStar( - flag = i * 2 - rounds, - modifier = Modifier - .width(starMeasure) - .height(starMeasure) + flag = i * 2 - rounds ) } } From 672295fbd9c295f590e8480783f00bcc5fc8620b Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Wed, 28 Feb 2024 21:57:01 +0900 Subject: [PATCH 44/68] =?UTF-8?q?MenuReview=20=ED=8C=8C=EB=9D=BC=EB=AF=B8?= =?UTF-8?q?=ED=84=B0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{ItemReview.kt => MenuReview.kt} | 63 +++---------------- .../compose/ui/menuDetail/MenuDetailScreen.kt | 18 +++--- .../ui/menuDetail/review/ReviewScreen.kt | 18 +++--- 3 files changed, 27 insertions(+), 72 deletions(-) rename app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/{ItemReview.kt => MenuReview.kt} (61%) diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReview.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuReview.kt similarity index 61% rename from app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReview.kt rename to app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuReview.kt index 746729ad..2f478f33 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/ItemReview.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuReview.kt @@ -11,7 +11,6 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.defaultMinSize 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 @@ -24,11 +23,9 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.font.FontWeight -import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import com.wafflestudio.siksha2.R import com.wafflestudio.siksha2.components.compose.NanumSquareFontFamily -import com.wafflestudio.siksha2.models.Etc import com.wafflestudio.siksha2.models.Review import com.wafflestudio.siksha2.ui.SikshaColors import com.wafflestudio.siksha2.utils.dpToSp @@ -36,8 +33,8 @@ import com.wafflestudio.siksha2.utils.toKoreanDate import com.wafflestudio.siksha2.utils.toLocalDateTime @Composable -fun ItemReview( - review: Review?, +fun MenuReview( + review: Review, modifier: Modifier = Modifier, showImage: Boolean = true ) { @@ -65,19 +62,19 @@ fun ItemReview( horizontalAlignment = Alignment.Start ) { Text( - text = "ID" + (review?.userId ?: ""), + text = "ID" + (review.userId), color = SikshaColors.Black900, fontSize = dpToSp(12.dp), fontFamily = NanumSquareFontFamily, fontWeight = FontWeight.Bold ) MenuRatingStars( - rating = review?.score?.toFloat() ?: 0.0f + rating = review.score.toFloat() ) } } Text( - text = review?.createdAt?.toLocalDateTime()?.toLocalDate()?.toKoreanDate() ?: "-", + text = review.createdAt.toLocalDateTime().toLocalDate()?.toKoreanDate() ?: "-", modifier = Modifier .align(Alignment.TopEnd) .padding(end = 10.dp), @@ -99,7 +96,7 @@ fun ItemReview( .matchParentSize() ) Text( - text = review?.comment ?: "", + text = review.comment ?: "", modifier = Modifier .align(Alignment.Center) .fillMaxWidth() @@ -117,7 +114,7 @@ fun ItemReview( .horizontalScroll(rememberScrollState()), horizontalArrangement = Arrangement.spacedBy(4.dp) ) { - for (imageUri in review?.etc?.images ?: listOf()) { + for (imageUri in review.etc?.images ?: listOf()) { MenuReviewImage( imageUri = Uri.parse(imageUri), modifier = Modifier.size(100.dp) @@ -128,49 +125,3 @@ fun ItemReview( } } } - -@Preview -@Composable -fun ItemReviewPreview() { - Column { - ItemReview( - review = Review( - id = 0, - menuId = 0, - userId = 1234, - score = 5.0, - comment = "그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 그냥저냥 먹을만해요 ", - createdAt = "2023-11-29T09:40:10.322Z", - etc = Etc( - images = listOf( - "https://postfiles.pstatic.net/MjAyMzExMjZfMjcy/MDAxNzAwOTI3NTczMDY5.c9qVmjXE0nBVZpKukBxB9EB0LytpB5Olc6psLGQdWLQg.-D-zLjlG7bIPYm8XmYzK9-l1vitTZAGcimoHM57QATAg.JPEG.jyurisenpai/20231121203650_1.jpg?type=w773", - "https://postfiles.pstatic.net/MjAyMzExMjZfMjU5/MDAxNzAwOTI3MjgxMjAz.f7jMVmS7vYGWKWswaOnnxCjgmaN0qgSt0_2VLB-XZrog.WMa7r-nHh9zw_QXO15bA4ts2NabuiEtQQkM6XYSiA1Ug.JPEG.jyurisenpai/20231118200550_1.jpg?type=w773", - "https://postfiles.pstatic.net/MjAyMzExMjZfODAg/MDAxNzAwOTI5MDI4NDE3.kprldbXZmLtHlIh2AFuu9jCeWiXbXeO6pF5OpxpJB3Mg.U8aqpMqPJz4bORV05B8M8oVBF9KXTTJhY1oN17NlkaAg.JPEG.jyurisenpai/20231121211321_1.jpg?type=w773" - ) - ) - ) - ) - ItemReview( - review = Review( - id = 0, - menuId = 0, - userId = 1234, - score = 3.5, - comment = "그냥저냥 먹을만해요 ", - createdAt = "2023-11-29T09:40:10.322Z", - etc = null - ) - ) - ItemReview( - review = Review( - id = 0, - menuId = 0, - userId = 1234, - score = 1.0, - comment = "맛없어요\n\n\nㅠ", - createdAt = "2023-11-29T09:40:10.322Z", - etc = null - ) - ) - } -} diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt index c540f286..0519d1cb 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt @@ -47,7 +47,7 @@ import com.wafflestudio.siksha2.components.compose.LoadingPlaceHolder import com.wafflestudio.siksha2.components.compose.NanumSquareFontFamily import com.wafflestudio.siksha2.components.compose.menuDetail.MenuRatingBars import com.wafflestudio.siksha2.components.compose.menuDetail.MenuRatingStars -import com.wafflestudio.siksha2.components.compose.menuDetail.ItemReview +import com.wafflestudio.siksha2.components.compose.menuDetail.MenuReview import com.wafflestudio.siksha2.components.compose.menuDetail.MenuReviewImage import com.wafflestudio.siksha2.components.compose.menuDetail.LikeButton import com.wafflestudio.siksha2.ui.SikshaColors @@ -381,13 +381,15 @@ fun MenuDetailScreen( } } items(reviews.itemCount) { - ItemReview( - review = reviews[it], - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 16.dp), - showImage = true - ) + reviews[it]?.let { review -> + MenuReview( + review = review, + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 16.dp), + showImage = true + ) + } } } else { item { diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt index fd46d9dd..5703e84e 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt @@ -25,7 +25,7 @@ import androidx.navigation.NavController import androidx.paging.compose.collectAsLazyPagingItems import com.wafflestudio.siksha2.R import com.wafflestudio.siksha2.components.compose.NanumSquareFontFamily -import com.wafflestudio.siksha2.components.compose.menuDetail.ItemReview +import com.wafflestudio.siksha2.components.compose.menuDetail.MenuReview import com.wafflestudio.siksha2.ui.SikshaColors import com.wafflestudio.siksha2.ui.menuDetail.MenuDetailViewModel import com.wafflestudio.siksha2.utils.dpToSp @@ -101,13 +101,15 @@ fun ReviewScreen( Spacer(modifier = Modifier.height(16.dp)) } items(reviews.itemCount) { - ItemReview( - review = reviews[it], - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 16.dp), - showImage = showImages - ) + reviews[it]?.let { review -> + MenuReview( + review = review, + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 16.dp), + showImage = showImages + ) + } } item { Spacer(modifier = Modifier.height(20.dp)) From 44d4599715d88f33dc7980707632646eb2599c5c Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Wed, 28 Feb 2024 22:07:16 +0900 Subject: [PATCH 45/68] =?UTF-8?q?NanumFontFamily=20=EC=82=AD=EC=A0=9C=20Me?= =?UTF-8?q?nuReviewImageDialog=20=ED=81=AC=EA=B8=B0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../siksha2/components/compose/ErrorPlaceHolder.kt | 1 - .../siksha2/components/compose/NanumFontFamily.kt | 13 ------------- .../components/compose/menuDetail/MenuRatingBars.kt | 3 --- .../components/compose/menuDetail/MenuReview.kt | 6 +----- .../compose/menuDetail/MenuReviewImageDialog.kt | 3 +-- .../compose/ui/menuDetail/MenuDetailScreen.kt | 12 ------------ .../compose/ui/menuDetail/review/ReviewScreen.kt | 3 --- 7 files changed, 2 insertions(+), 39 deletions(-) delete mode 100644 app/src/main/java/com/wafflestudio/siksha2/components/compose/NanumFontFamily.kt diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/ErrorPlaceHolder.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/ErrorPlaceHolder.kt index d56db6ee..d67d2bb3 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/components/compose/ErrorPlaceHolder.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/ErrorPlaceHolder.kt @@ -35,7 +35,6 @@ fun ErrorPlaceHolder( Text( text = "네트워크 연결이 불안정합니다.", fontSize = dpToSp(20.dp), - fontFamily = NanumSquareFontFamily, fontWeight = FontWeight.Light, modifier = Modifier.padding(top = 20.dp) ) diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/NanumFontFamily.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/NanumFontFamily.kt deleted file mode 100644 index 12a64ace..00000000 --- a/app/src/main/java/com/wafflestudio/siksha2/components/compose/NanumFontFamily.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.wafflestudio.siksha2.components.compose - -import androidx.compose.ui.text.font.Font -import androidx.compose.ui.text.font.FontFamily -import androidx.compose.ui.text.font.FontWeight -import com.wafflestudio.siksha2.R - -val NanumSquareFontFamily = FontFamily( - Font(R.font.nanum_square_regular, FontWeight.Normal), - Font(R.font.nanum_square_bold, FontWeight.Bold), - Font(R.font.nanum_square_light, FontWeight.Light), - Font(R.font.nanum_square_extra_bold, FontWeight.ExtraBold) -) diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuRatingBars.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuRatingBars.kt index 5bbea98d..e1316af6 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuRatingBars.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuRatingBars.kt @@ -18,10 +18,8 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.font.FontWeight -import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import com.wafflestudio.siksha2.R -import com.wafflestudio.siksha2.components.compose.NanumSquareFontFamily import com.wafflestudio.siksha2.ui.SikshaColors import com.wafflestudio.siksha2.utils.dpToSp import kotlin.math.max @@ -41,7 +39,6 @@ fun MenuRatingBar( text = ratingIndex.toString(), modifier = Modifier.padding(end = 3.dp), fontSize = dpToSp(8.dp), - fontFamily = NanumSquareFontFamily, fontWeight = FontWeight.Bold, color = SikshaColors.Gray500 ) diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuReview.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuReview.kt index 2f478f33..f157df09 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuReview.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuReview.kt @@ -25,7 +25,6 @@ import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import com.wafflestudio.siksha2.R -import com.wafflestudio.siksha2.components.compose.NanumSquareFontFamily import com.wafflestudio.siksha2.models.Review import com.wafflestudio.siksha2.ui.SikshaColors import com.wafflestudio.siksha2.utils.dpToSp @@ -65,7 +64,6 @@ fun MenuReview( text = "ID" + (review.userId), color = SikshaColors.Black900, fontSize = dpToSp(12.dp), - fontFamily = NanumSquareFontFamily, fontWeight = FontWeight.Bold ) MenuRatingStars( @@ -79,7 +77,6 @@ fun MenuReview( .align(Alignment.TopEnd) .padding(end = 10.dp), fontSize = dpToSp(12.dp), - fontFamily = NanumSquareFontFamily, fontWeight = FontWeight.Bold, color = SikshaColors.Gray500 ) @@ -98,12 +95,11 @@ fun MenuReview( Text( text = review.comment ?: "", modifier = Modifier - .align(Alignment.Center) + .align(Alignment.TopCenter) .fillMaxWidth() .padding(start = 30.dp, end = 10.dp, top = 13.dp, bottom = 15.dp), color = SikshaColors.Gray800, fontSize = dpToSp(dp = 12.dp), - fontFamily = NanumSquareFontFamily, fontWeight = FontWeight.Normal ) } diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuReviewImageDialog.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuReviewImageDialog.kt index e3e9f8fd..c85ca0c2 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuReviewImageDialog.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuReviewImageDialog.kt @@ -31,8 +31,7 @@ fun MenuReviewImageDialog( Column( modifier = modifier .padding(20.dp) - .heightIn(0.dp, 330.dp) - .widthIn(0.dp, 300.dp) + .size(width = 300.dp, height = 300.dp) .fillMaxSize() ) { Image( diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt index 0519d1cb..10c27953 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt @@ -44,7 +44,6 @@ import androidx.paging.compose.collectAsLazyPagingItems import com.wafflestudio.siksha2.R import com.wafflestudio.siksha2.components.compose.ErrorPlaceHolder import com.wafflestudio.siksha2.components.compose.LoadingPlaceHolder -import com.wafflestudio.siksha2.components.compose.NanumSquareFontFamily import com.wafflestudio.siksha2.components.compose.menuDetail.MenuRatingBars import com.wafflestudio.siksha2.components.compose.menuDetail.MenuRatingStars import com.wafflestudio.siksha2.components.compose.menuDetail.MenuReview @@ -105,7 +104,6 @@ fun MenuDetailScreen( .fillMaxWidth(0.72f) .align(Alignment.Center), fontSize = dpToSp(20.dp), - fontFamily = NanumSquareFontFamily, fontWeight = FontWeight.Bold, overflow = TextOverflow.Ellipsis, textAlign = TextAlign.Center, @@ -140,7 +138,6 @@ fun MenuDetailScreen( Text( text = "좋아요 " + (menu?.likeCount ?: 0).toString() + "개", fontSize = dpToSp(14.dp), - fontFamily = NanumSquareFontFamily, fontWeight = FontWeight.Normal ) } @@ -169,28 +166,24 @@ fun MenuDetailScreen( text = "총 ", color = SikshaColors.Gray800, fontSize = dpToSp(10.dp), - fontFamily = NanumSquareFontFamily, fontWeight = FontWeight.Bold ) Text( text = reviews?.itemCount.toString(), color = SikshaColors.OrangeMain, fontSize = dpToSp(10.dp), - fontFamily = NanumSquareFontFamily, fontWeight = FontWeight.Bold ) Text( text = "명", color = SikshaColors.OrangeMain, fontSize = dpToSp(10.dp), - fontFamily = NanumSquareFontFamily, fontWeight = FontWeight.Bold ) Text( text = "이 평가했어요!", color = SikshaColors.Gray800, fontSize = dpToSp(10.dp), - fontFamily = NanumSquareFontFamily, fontWeight = FontWeight.Bold ) } @@ -210,7 +203,6 @@ fun MenuDetailScreen( menu?.score?.times(10)?.let { round(it) / 10 } ?: "0.0" }", fontSize = dpToSp(32.dp), - fontFamily = NanumSquareFontFamily, fontWeight = FontWeight.ExtraBold ) MenuRatingStars( @@ -239,7 +231,6 @@ fun MenuDetailScreen( Text( text = "나의 평가 남기기", fontSize = dpToSp(14.dp), - fontFamily = NanumSquareFontFamily, fontWeight = FontWeight.ExtraBold, color = SikshaColors.White900, modifier = Modifier @@ -279,7 +270,6 @@ fun MenuDetailScreen( Text( text = "사진 리뷰 모아보기", fontSize = dpToSp(14.dp), - fontFamily = NanumSquareFontFamily, fontWeight = FontWeight.Normal, modifier = Modifier.align(Alignment.CenterStart) ) @@ -358,7 +348,6 @@ fun MenuDetailScreen( Text( text = "리뷰", fontSize = dpToSp(14.dp), - fontFamily = NanumSquareFontFamily, fontWeight = FontWeight.Normal, modifier = Modifier.align(Alignment.CenterStart) ) @@ -401,7 +390,6 @@ fun MenuDetailScreen( Text( text = "리뷰가 없습니다.", fontSize = dpToSp(18.dp), - fontFamily = NanumSquareFontFamily, fontWeight = FontWeight.Light, modifier = Modifier.align(Alignment.Center), color = SikshaColors.Gray600 diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt index 5703e84e..7021d877 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt @@ -24,7 +24,6 @@ import androidx.hilt.navigation.compose.hiltViewModel import androidx.navigation.NavController import androidx.paging.compose.collectAsLazyPagingItems import com.wafflestudio.siksha2.R -import com.wafflestudio.siksha2.components.compose.NanumSquareFontFamily import com.wafflestudio.siksha2.components.compose.menuDetail.MenuReview import com.wafflestudio.siksha2.ui.SikshaColors import com.wafflestudio.siksha2.ui.menuDetail.MenuDetailViewModel @@ -71,7 +70,6 @@ fun ReviewScreen( .padding(horizontal = 10.dp, vertical = 12.dp) .align(Alignment.Center), fontSize = dpToSp(20.dp), - fontFamily = NanumSquareFontFamily, fontWeight = FontWeight.Bold, color = SikshaColors.White900 ) @@ -86,7 +84,6 @@ fun ReviewScreen( Text( text = "리뷰가 없습니다.", fontSize = dpToSp(18.dp), - fontFamily = NanumSquareFontFamily, fontWeight = FontWeight.Normal, modifier = Modifier.align(Alignment.Center), color = SikshaColors.Gray600 From fc319df1ab9153588909a844bfff41b7a3b94a16 Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Wed, 28 Feb 2024 22:16:52 +0900 Subject: [PATCH 46/68] =?UTF-8?q?MenuReviewImageShowMore=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../compose/menuDetail/MenuReviewImage.kt | 34 +--------- .../menuDetail/MenuReviewImageShowMore.kt | 67 +++++++++++++++++++ .../compose/ui/menuDetail/MenuDetailScreen.kt | 5 +- 3 files changed, 73 insertions(+), 33 deletions(-) create mode 100644 app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuReviewImageShowMore.kt diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuReviewImage.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuReviewImage.kt index 75f2288d..213afa93 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuReviewImage.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuReviewImage.kt @@ -30,8 +30,6 @@ fun MenuReviewImage( imageUri: Uri, modifier: Modifier = Modifier, onDelete: () -> Unit = {}, - onShowMore: () -> Unit = {}, - showMore: Int? = null, deletable: Boolean = false ) { var imageDialogState by remember { mutableStateOf(false) } @@ -39,15 +37,15 @@ fun MenuReviewImage( Box( modifier = modifier ) { - if (imageDialogState && showMore == null) { + if (imageDialogState) { MenuReviewImageDialog(url = imageUri, onDismiss = { imageDialogState = false }) } Image( modifier = Modifier .fillMaxSize() .align(Alignment.Center) - .clickable { - if (showMore == null) imageDialogState = true + .clickable{ + imageDialogState = true }, painter = rememberAsyncImagePainter(imageUri), contentDescription = null, @@ -62,31 +60,5 @@ fun MenuReviewImage( contentDescription = null ) } - if (showMore != null) { - Box( - modifier = Modifier - .fillMaxSize() - .background(color = Color(0x80000000)) - .zIndex(1f) - .align(Alignment.Center) - .clickable { onShowMore() } - ) { - Column( - modifier = Modifier.align(Alignment.Center), - horizontalAlignment = Alignment.CenterHorizontally - ) { - Text( - text = "+", - fontSize = dpToSp(12.dp), - color = SikshaColors.White900 - ) - Text( - text = showMore.toString() + "건 더 보기", - fontSize = dpToSp(12.dp), - color = SikshaColors.White900 - ) - } - } - } } } diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuReviewImageShowMore.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuReviewImageShowMore.kt new file mode 100644 index 00000000..08aac40d --- /dev/null +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuReviewImageShowMore.kt @@ -0,0 +1,67 @@ +package com.wafflestudio.siksha2.components.compose.menuDetail + +import android.net.Uri +import androidx.compose.foundation.Image +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.material.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.unit.dp +import androidx.compose.ui.zIndex +import coil.compose.rememberAsyncImagePainter +import com.wafflestudio.siksha2.R +import com.wafflestudio.siksha2.ui.SikshaColors +import com.wafflestudio.siksha2.utils.dpToSp + +@Composable +fun MenuReviewImageShowMore( + imageUri: Uri, + modifier: Modifier = Modifier, + onShowMore: () -> Unit = {}, + showMoreCount: Int = 0 +) { + Box( + modifier = modifier + ) { + Image( + modifier = Modifier + .fillMaxSize() + .align(Alignment.Center), + painter = rememberAsyncImagePainter(imageUri), + contentDescription = null, + contentScale = ContentScale.Crop + ) + Box( + modifier = Modifier + .fillMaxSize() + .background(color = Color(0x80000000)) + .zIndex(1f) + .align(Alignment.Center) + .clickable { onShowMore() } + ) { + Column( + modifier = Modifier.align(Alignment.Center), + horizontalAlignment = Alignment.CenterHorizontally + ) { + Text( + text = "+", + fontSize = dpToSp(12.dp), + color = SikshaColors.White900 + ) + Text( + text = showMoreCount.toString() + "건 더 보기", + fontSize = dpToSp(12.dp), + color = SikshaColors.White900 + ) + } + } + } +} diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt index 10c27953..707b2eb6 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt @@ -49,6 +49,7 @@ import com.wafflestudio.siksha2.components.compose.menuDetail.MenuRatingStars import com.wafflestudio.siksha2.components.compose.menuDetail.MenuReview import com.wafflestudio.siksha2.components.compose.menuDetail.MenuReviewImage import com.wafflestudio.siksha2.components.compose.menuDetail.LikeButton +import com.wafflestudio.siksha2.components.compose.menuDetail.MenuReviewImageShowMore import com.wafflestudio.siksha2.ui.SikshaColors import com.wafflestudio.siksha2.ui.menuDetail.MenuDetailFragmentDirections import com.wafflestudio.siksha2.ui.menuDetail.MenuDetailViewModel @@ -306,12 +307,12 @@ fun MenuDetailScreen( ) else -> { if (i == 3) { - MenuReviewImage( + MenuReviewImageShowMore( imageUri = Uri.parse(it), modifier = Modifier .size(120.dp) .clip(RoundedCornerShape(10.dp)), - showMore = imageReviews.itemCount - 2, + showMoreCount = imageReviews.itemCount - 2, onShowMore = { navController.navigate( MenuDetailFragmentDirections.actionMenuDetailFragmentToReviewFragment( From c6743cb6d4329b53f4bf2041b0375d40c2d22241 Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Wed, 28 Feb 2024 22:33:05 +0900 Subject: [PATCH 47/68] =?UTF-8?q?string=20=EB=A6=AC=EC=86=8C=EC=8A=A4=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../compose/ui/menuDetail/MenuDetailScreen.kt | 41 +++++++++++-------- .../ui/menuDetail/review/ReviewScreen.kt | 5 ++- app/src/main/res/values/strings.xml | 5 +++ 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt index 707b2eb6..9fecdd6d 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt @@ -34,6 +34,7 @@ import androidx.compose.ui.draw.rotate import androidx.compose.ui.graphics.ColorFilter import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextOverflow @@ -74,7 +75,7 @@ fun MenuDetailScreen( val imagePreviewScrollState = rememberScrollState() val context = LocalContext.current - LaunchedEffect(menuDetailViewModel) { + LaunchedEffect(Unit) { menuDetailViewModel.refreshMenu(menuId) menuDetailViewModel.refreshReviewDistribution(menuId) } @@ -99,7 +100,7 @@ fun MenuDetailScreen( } ) Text( - text = menu?.nameKr ?: "리뷰", + text = menu?.nameKr ?: stringResource(R.string.review_title), modifier = Modifier .padding(horizontal = 10.dp, vertical = 12.dp) .fillMaxWidth(0.72f) @@ -137,7 +138,9 @@ fun MenuDetailScreen( modifier = Modifier.size(21.dp) ) Text( - text = "좋아요 " + (menu?.likeCount ?: 0).toString() + "개", + text = stringResource(R.string.review_like_prefix) + + (menu?.likeCount ?: 0).toString() + + stringResource(R.string.review_like_suffix), fontSize = dpToSp(14.dp), fontWeight = FontWeight.Normal ) @@ -164,7 +167,7 @@ fun MenuDetailScreen( horizontalArrangement = Arrangement.Center ) { Text( - text = "총 ", + text = stringResource(R.string.review_count_prefix), color = SikshaColors.Gray800, fontSize = dpToSp(10.dp), fontWeight = FontWeight.Bold @@ -176,13 +179,13 @@ fun MenuDetailScreen( fontWeight = FontWeight.Bold ) Text( - text = "명", + text = stringResource(R.string.review_count_suffix_orange), color = SikshaColors.OrangeMain, fontSize = dpToSp(10.dp), fontWeight = FontWeight.Bold ) Text( - text = "이 평가했어요!", + text = stringResource(R.string.review_count_suffix_black), color = SikshaColors.Gray800, fontSize = dpToSp(10.dp), fontWeight = FontWeight.Bold @@ -230,7 +233,7 @@ fun MenuDetailScreen( .align(Alignment.CenterHorizontally) ) { Text( - text = "나의 평가 남기기", + text = stringResource(R.string.menu_detail_leave_review_button), fontSize = dpToSp(14.dp), fontWeight = FontWeight.ExtraBold, color = SikshaColors.White900, @@ -238,13 +241,17 @@ fun MenuDetailScreen( .align(Alignment.Center) .clickable { if (isTodayMenu) { - navController.navigate(MenuDetailFragmentDirections.actionMenuDetailFragmentToLeaveReviewFragment()) + navController.navigate( + MenuDetailFragmentDirections.actionMenuDetailFragmentToLeaveReviewFragment() + ) } else { - Toast.makeText( - context, - "오늘 메뉴만 평가할 수 있습니다.", - Toast.LENGTH_SHORT - ).show() + Toast + .makeText( + context, + "오늘 메뉴만 평가할 수 있습니다.", + Toast.LENGTH_SHORT + ) + .show() } } ) @@ -269,14 +276,14 @@ fun MenuDetailScreen( .height(50.dp) ) { Text( - text = "사진 리뷰 모아보기", + text = stringResource(R.string.menu_detail_photo_review_gather), fontSize = dpToSp(14.dp), fontWeight = FontWeight.Normal, modifier = Modifier.align(Alignment.CenterStart) ) Image( painter = painterResource(R.drawable.ic_back_arrow), - contentDescription = "사진 리뷰 모아보기", + contentDescription = stringResource(R.string.menu_detail_photo_review_gather), colorFilter = ColorFilter.tint(SikshaColors.Gray400), modifier = Modifier .align(Alignment.CenterEnd) @@ -347,7 +354,7 @@ fun MenuDetailScreen( .height(50.dp) ) { Text( - text = "리뷰", + text = stringResource(R.string.menu_detail_review_gather), fontSize = dpToSp(14.dp), fontWeight = FontWeight.Normal, modifier = Modifier.align(Alignment.CenterStart) @@ -389,7 +396,7 @@ fun MenuDetailScreen( .fillMaxWidth() ) { Text( - text = "리뷰가 없습니다.", + text = stringResource(R.string.review_nothing), fontSize = dpToSp(18.dp), fontWeight = FontWeight.Light, modifier = Modifier.align(Alignment.Center), diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt index 7021d877..570b894b 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt @@ -18,6 +18,7 @@ import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel @@ -65,7 +66,7 @@ fun ReviewScreen( } ) Text( - text = "리뷰", + text = stringResource(R.string.review_title), modifier = Modifier .padding(horizontal = 10.dp, vertical = 12.dp) .align(Alignment.Center), @@ -82,7 +83,7 @@ fun ReviewScreen( ) { if (reviews == null || reviews.itemCount == 0) { Text( - text = "리뷰가 없습니다.", + text = stringResource(R.string.review_nothing), fontSize = dpToSp(18.dp), fontWeight = FontWeight.Normal, modifier = Modifier.align(Alignment.Center), diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 060c2899..42d9a8d5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -41,6 +41,11 @@ 사진 리뷰 모아보기 리뷰 리뷰가 없습니다. + 좋아요 + + + + 이 평가했어요! 순서를 지정할 식당이 없습니다. 즐겨찾기에 추가된 식당이 없습니다.\n식당 탭에서 별을 눌러 추가해보세요. 네트워크 연결이 불안정합니다. From 05d8497779ea35c3b40f9990fd3b4b105b13e56d Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Sun, 3 Mar 2024 17:55:35 +0900 Subject: [PATCH 48/68] =?UTF-8?q?=ED=8F=B0=ED=8A=B8=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../siksha2/ui/menuDetail/MenuDetailFragment.kt | 15 +++++++++------ .../ui/menuDetail/review/ReviewFragment.kt | 13 ++++++++----- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt index 796b6f8e..20bdb119 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt @@ -10,6 +10,7 @@ import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.navArgs import com.wafflestudio.siksha2.compose.ui.menuDetail.MenuDetailScreen import com.wafflestudio.siksha2.databinding.FragmentMenuDetailBinding +import com.wafflestudio.siksha2.ui.SikshaTheme import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint @@ -31,12 +32,14 @@ class MenuDetailFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { binding.menuDetailComposeView.setContent { - MenuDetailScreen( - navController = findNavController(), - menuId = args.menuId, - isTodayMenu = args.isTodayMenu, - menuDetailViewModel = vm - ) + SikshaTheme { + MenuDetailScreen( + navController = findNavController(), + menuId = args.menuId, + isTodayMenu = args.isTodayMenu, + menuDetailViewModel = vm + ) + } } } } diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt index 418acb00..f76aaff9 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt @@ -10,6 +10,7 @@ import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.navArgs import com.wafflestudio.siksha2.compose.ui.menuDetail.review.ReviewScreen import com.wafflestudio.siksha2.databinding.FragmentReviewBinding +import com.wafflestudio.siksha2.ui.SikshaTheme import com.wafflestudio.siksha2.ui.menuDetail.MenuDetailViewModel class ReviewFragment : Fragment() { @@ -30,11 +31,13 @@ class ReviewFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { binding.reviewComposeView.setContent { - ReviewScreen( - navController = findNavController(), - showImages = args.showImages, - menuDetailViewModel = vm - ) + SikshaTheme { + ReviewScreen( + navController = findNavController(), + showImages = args.showImages, + menuDetailViewModel = vm + ) + } } } } From c83d812e1c50231f1a224e962c414950e13a4e02 Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Sun, 3 Mar 2024 17:55:35 +0900 Subject: [PATCH 49/68] =?UTF-8?q?=ED=8F=B0=ED=8A=B8=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/compose/menuDetail/MenuReview.kt | 2 +- .../compose/ui/menuDetail/MenuDetailScreen.kt | 6 +++--- .../compose/ui/menuDetail/review/ReviewScreen.kt | 2 +- .../siksha2/ui/menuDetail/MenuDetailFragment.kt | 15 +++++++++------ .../ui/menuDetail/review/ReviewFragment.kt | 13 ++++++++----- app/src/main/res/values/strings.xml | 4 ++-- 6 files changed, 24 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuReview.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuReview.kt index f157df09..82145d21 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuReview.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuReview.kt @@ -100,7 +100,7 @@ fun MenuReview( .padding(start = 30.dp, end = 10.dp, top = 13.dp, bottom = 15.dp), color = SikshaColors.Gray800, fontSize = dpToSp(dp = 12.dp), - fontWeight = FontWeight.Normal + fontWeight = FontWeight.Medium ) } if (showImage) { diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt index 9fecdd6d..3b7b1712 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt @@ -142,7 +142,7 @@ fun MenuDetailScreen( + (menu?.likeCount ?: 0).toString() + stringResource(R.string.review_like_suffix), fontSize = dpToSp(14.dp), - fontWeight = FontWeight.Normal + fontWeight = FontWeight.Medium ) } @@ -278,7 +278,7 @@ fun MenuDetailScreen( Text( text = stringResource(R.string.menu_detail_photo_review_gather), fontSize = dpToSp(14.dp), - fontWeight = FontWeight.Normal, + fontWeight = FontWeight.Medium, modifier = Modifier.align(Alignment.CenterStart) ) Image( @@ -356,7 +356,7 @@ fun MenuDetailScreen( Text( text = stringResource(R.string.menu_detail_review_gather), fontSize = dpToSp(14.dp), - fontWeight = FontWeight.Normal, + fontWeight = FontWeight.Medium, modifier = Modifier.align(Alignment.CenterStart) ) Image( diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt index 570b894b..0d95291d 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt @@ -85,7 +85,7 @@ fun ReviewScreen( Text( text = stringResource(R.string.review_nothing), fontSize = dpToSp(18.dp), - fontWeight = FontWeight.Normal, + fontWeight = FontWeight.Medium, modifier = Modifier.align(Alignment.Center), color = SikshaColors.Gray600 ) diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt index 796b6f8e..20bdb119 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt @@ -10,6 +10,7 @@ import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.navArgs import com.wafflestudio.siksha2.compose.ui.menuDetail.MenuDetailScreen import com.wafflestudio.siksha2.databinding.FragmentMenuDetailBinding +import com.wafflestudio.siksha2.ui.SikshaTheme import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint @@ -31,12 +32,14 @@ class MenuDetailFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { binding.menuDetailComposeView.setContent { - MenuDetailScreen( - navController = findNavController(), - menuId = args.menuId, - isTodayMenu = args.isTodayMenu, - menuDetailViewModel = vm - ) + SikshaTheme { + MenuDetailScreen( + navController = findNavController(), + menuId = args.menuId, + isTodayMenu = args.isTodayMenu, + menuDetailViewModel = vm + ) + } } } } diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt index 418acb00..f76aaff9 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt @@ -10,6 +10,7 @@ import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.navArgs import com.wafflestudio.siksha2.compose.ui.menuDetail.review.ReviewScreen import com.wafflestudio.siksha2.databinding.FragmentReviewBinding +import com.wafflestudio.siksha2.ui.SikshaTheme import com.wafflestudio.siksha2.ui.menuDetail.MenuDetailViewModel class ReviewFragment : Fragment() { @@ -30,11 +31,13 @@ class ReviewFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { binding.reviewComposeView.setContent { - ReviewScreen( - navController = findNavController(), - showImages = args.showImages, - menuDetailViewModel = vm - ) + SikshaTheme { + ReviewScreen( + navController = findNavController(), + showImages = args.showImages, + menuDetailViewModel = vm + ) + } } } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 42d9a8d5..70e804da 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -41,9 +41,9 @@ 사진 리뷰 모아보기 리뷰 리뷰가 없습니다. - 좋아요 + 좋아요  - + 총  이 평가했어요! 순서를 지정할 식당이 없습니다. From 4cbe09d96f4a61b81bc075c868afe88f5ba863e8 Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Sun, 3 Mar 2024 18:18:47 +0900 Subject: [PATCH 50/68] =?UTF-8?q?reviews=EB=A5=BC=20StateFlow=EB=A1=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../compose/ui/menuDetail/MenuDetailScreen.kt | 10 ++-- .../ui/menuDetail/review/ReviewScreen.kt | 10 ++-- .../ui/menuDetail/MenuDetailViewModel.kt | 53 +++++++++---------- 3 files changed, 34 insertions(+), 39 deletions(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt index 3b7b1712..7d9ef77e 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt @@ -67,10 +67,8 @@ fun MenuDetailScreen( menuDetailViewModel: MenuDetailViewModel = hiltViewModel() ) { val menu by menuDetailViewModel.menu.observeAsState() - val reviewFlow by menuDetailViewModel.reviews.collectAsState() - val reviews = reviewFlow?.collectAsLazyPagingItems() - val imageReviewFlow by menuDetailViewModel.reviewsWithImage.collectAsState() - val imageReviews = imageReviewFlow?.collectAsLazyPagingItems() + val reviews = menuDetailViewModel.reviews.collectAsLazyPagingItems() + val imageReviews = menuDetailViewModel.reviewsWithImage.collectAsLazyPagingItems() val loadingState = menuDetailViewModel.networkResultState.observeAsState() val imagePreviewScrollState = rememberScrollState() val context = LocalContext.current @@ -267,7 +265,7 @@ fun MenuDetailScreen( } // 사진 리뷰 - if (imageReviews != null && imageReviews.itemCount > 0) { + if (imageReviews.itemCount > 0) { item { Box( modifier = Modifier @@ -345,7 +343,7 @@ fun MenuDetailScreen( } // 일반 리뷰 - if (reviews != null && reviews.itemCount > 0) { + if (reviews.itemCount > 0) { item { Box( modifier = Modifier diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt index 0d95291d..c81f1fef 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt @@ -37,13 +37,11 @@ fun ReviewScreen( menuDetailViewModel: MenuDetailViewModel = hiltViewModel(), showImages: Boolean = false ) { - val reviewFlow by - if (!showImages) { - menuDetailViewModel.reviews.collectAsState() + val reviews = if (!showImages) { + menuDetailViewModel.reviews.collectAsLazyPagingItems() } else { - menuDetailViewModel.reviewsWithImage.collectAsState() + menuDetailViewModel.reviewsWithImage.collectAsLazyPagingItems() } - val reviews = reviewFlow?.collectAsLazyPagingItems() Column( modifier = modifier.fillMaxSize() @@ -81,7 +79,7 @@ fun ReviewScreen( .fillMaxWidth() .weight(1f) ) { - if (reviews == null || reviews.itemCount == 0) { + if (reviews.itemCount == 0) { Text( text = stringResource(R.string.review_nothing), fontSize = dpToSp(18.dp), diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt index 46b8bedd..cca1c215 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt @@ -10,6 +10,7 @@ import androidx.lifecycle.asFlow import androidx.lifecycle.viewModelScope import androidx.paging.Pager import androidx.paging.PagingData +import androidx.paging.cachedIn import com.wafflestudio.siksha2.models.Menu import com.wafflestudio.siksha2.models.Review import com.wafflestudio.siksha2.repositories.MenuRepository @@ -20,9 +21,13 @@ import id.zelory.compressor.Compressor import id.zelory.compressor.constraint.format import id.zelory.compressor.constraint.resolution import id.zelory.compressor.constraint.size +import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.filter +import kotlinx.coroutines.flow.filterNotNull +import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch @@ -69,33 +74,27 @@ class MenuDetailViewModel @Inject constructor( val leaveReviewState: LiveData get() = _leaveReviewState - val reviews: StateFlow>?> = - _menu.asFlow().map { menu -> - if (menu != null) { - Pager( - config = MenuReviewPagingSource.Config, - pagingSourceFactory = { - menuRepository.menuReviewPagingSource(menu.id) - } - ).flow - } else { - null - } - }.stateIn(viewModelScope, SharingStarted.Eagerly, initialValue = null) - - val reviewsWithImage: StateFlow>?> = - _menu.asFlow().map { menu -> - if (menu != null) { - Pager( - config = MenuReviewWithImagePagingSource.Config, - pagingSourceFactory = { - menuRepository.menuReviewWithImagePagingSource(menu.id) - } - ).flow - } else { - null - } - }.stateIn(viewModelScope, SharingStarted.Eagerly, initialValue = null) + @OptIn(ExperimentalCoroutinesApi::class) + val reviews: StateFlow> = + _menu.asFlow().filterNotNull().flatMapLatest { menu -> + Pager( + config = MenuReviewPagingSource.Config, + pagingSourceFactory = { + menuRepository.menuReviewPagingSource(menu.id) + } + ).flow.cachedIn(viewModelScope) + }.stateIn(viewModelScope, SharingStarted.Eagerly, initialValue = PagingData.empty()) + + @OptIn(ExperimentalCoroutinesApi::class) + val reviewsWithImage: StateFlow> = + _menu.asFlow().filterNotNull().flatMapLatest {menu -> + Pager( + config = MenuReviewWithImagePagingSource.Config, + pagingSourceFactory = { + menuRepository.menuReviewWithImagePagingSource(menu.id) + } + ).flow.cachedIn(viewModelScope) + }.stateIn(viewModelScope, SharingStarted.Eagerly, initialValue = PagingData.empty()) fun refreshMenu(menuId: Long) { _networkResultState.value = State.LOADING From 93bdd5c6c21751b25c1488a1dde3239f535d6d64 Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Sun, 3 Mar 2024 18:27:42 +0900 Subject: [PATCH 51/68] =?UTF-8?q?MenuDetailViewModel=EC=9D=98=20enum=20cla?= =?UTF-8?q?ss=EB=93=A4=EC=9D=84=20=EB=BA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../compose/ui/menuDetail/MenuDetailScreen.kt | 10 ++-- .../ui/menuDetail/LeaveReviewFragment.kt | 2 +- .../ui/menuDetail/MenuDetailViewModel.kt | 50 +++++++++---------- 3 files changed, 30 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt index 7d9ef77e..4b8f1add 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt @@ -24,7 +24,6 @@ import androidx.compose.material.Divider import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.livedata.observeAsState import androidx.compose.ui.Alignment @@ -54,6 +53,7 @@ import com.wafflestudio.siksha2.components.compose.menuDetail.MenuReviewImageSho import com.wafflestudio.siksha2.ui.SikshaColors import com.wafflestudio.siksha2.ui.menuDetail.MenuDetailFragmentDirections import com.wafflestudio.siksha2.ui.menuDetail.MenuDetailViewModel +import com.wafflestudio.siksha2.ui.menuDetail.MenuLoadingState import com.wafflestudio.siksha2.utils.dpToSp import kotlin.math.min import kotlin.math.round @@ -69,7 +69,7 @@ fun MenuDetailScreen( val menu by menuDetailViewModel.menu.observeAsState() val reviews = menuDetailViewModel.reviews.collectAsLazyPagingItems() val imageReviews = menuDetailViewModel.reviewsWithImage.collectAsLazyPagingItems() - val loadingState = menuDetailViewModel.networkResultState.observeAsState() + val loadingState = menuDetailViewModel.networkResultMenuLoadingState.observeAsState() val imagePreviewScrollState = rememberScrollState() val context = LocalContext.current @@ -112,7 +112,7 @@ fun MenuDetailScreen( } when (loadingState.value) { - MenuDetailViewModel.State.SUCCESS -> { + MenuLoadingState.SUCCESS -> { LazyColumn( modifier = Modifier .fillMaxWidth() @@ -405,14 +405,14 @@ fun MenuDetailScreen( } } } - MenuDetailViewModel.State.LOADING -> { + MenuLoadingState.LOADING -> { LoadingPlaceHolder( modifier = Modifier .fillMaxWidth() .weight(1f) ) } - MenuDetailViewModel.State.FAILED -> { + MenuLoadingState.FAILED -> { ErrorPlaceHolder( modifier = Modifier .fillMaxWidth() diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/LeaveReviewFragment.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/LeaveReviewFragment.kt index a2e859bd..42e10fea 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/LeaveReviewFragment.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/LeaveReviewFragment.kt @@ -129,7 +129,7 @@ class LeaveReviewFragment : Fragment() { binding.imageLayout.setVisibleOrGone(imageUriList.isNotEmpty()) } - vm.leaveReviewState.observe(viewLifecycleOwner) { + vm.leaveLeaveReviewState.observe(viewLifecycleOwner) { binding.onLoadingContainer.root.setVisibleOrGone(it == MenuDetailViewModel.ReviewState.COMPRESSING) } diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt index cca1c215..036d1efe 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt @@ -25,10 +25,8 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.filterNotNull import kotlinx.coroutines.flow.flatMapLatest -import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch import okhttp3.MediaType.Companion.toMediaTypeOrNull @@ -38,6 +36,17 @@ import java.io.File import java.io.IOException import javax.inject.Inject +enum class MenuLoadingState { + LOADING, + SUCCESS, + FAILED +} + +enum class LeaveReviewState { + WAITING, + COMPRESSING +} + @HiltViewModel class MenuDetailViewModel @Inject constructor( private val menuRepository: MenuRepository @@ -50,9 +59,9 @@ class MenuDetailViewModel @Inject constructor( val commentHint: LiveData get() = _commentHint - private val _networkResultState = MutableLiveData() - val networkResultState: LiveData - get() = _networkResultState + private val _networkResultMenuLoadingState = MutableLiveData() + val networkResultMenuLoadingState: LiveData + get() = _networkResultMenuLoadingState private val _reviewDistribution = MutableLiveData>() val reviewDistribution: LiveData> @@ -70,9 +79,9 @@ class MenuDetailViewModel @Inject constructor( val imageCount: LiveData get() = _imageCount - private val _leaveReviewState = MutableLiveData(ReviewState.WAITING) - val leaveReviewState: LiveData - get() = _leaveReviewState + private val _leaveLeaveReviewState = MutableLiveData(LeaveReviewState.WAITING) + val leaveLeaveReviewState: LiveData + get() = _leaveLeaveReviewState @OptIn(ExperimentalCoroutinesApi::class) val reviews: StateFlow> = @@ -97,13 +106,13 @@ class MenuDetailViewModel @Inject constructor( }.stateIn(viewModelScope, SharingStarted.Eagerly, initialValue = PagingData.empty()) fun refreshMenu(menuId: Long) { - _networkResultState.value = State.LOADING + _networkResultMenuLoadingState.value = MenuLoadingState.LOADING viewModelScope.launch { try { _menu.value = menuRepository.getMenuById(menuId) - _networkResultState.value = State.SUCCESS + _networkResultMenuLoadingState.value = MenuLoadingState.SUCCESS } catch (e: IOException) { - _networkResultState.value = State.FAILED + _networkResultMenuLoadingState.value = MenuLoadingState.FAILED } } } @@ -158,16 +167,16 @@ class MenuDetailViewModel @Inject constructor( } fun notifySendReviewEnd() { - _leaveReviewState.value = ReviewState.WAITING + _leaveLeaveReviewState.value = LeaveReviewState.WAITING } fun toggleLike() { if (menu.value != null) { - toggleLike(menu.value!!.id, menu.value!!.isLiked ?: false) + _toggleLike(menu.value!!.id, menu.value!!.isLiked ?: false) } } - fun toggleLike(id: Long, isCurrentlyLiked: Boolean) { + private fun _toggleLike(id: Long, isCurrentlyLiked: Boolean) { viewModelScope.launch { val menuItem = menuRepository.getMenuById(id) menuItem.isLiked = !isCurrentlyLiked @@ -188,7 +197,7 @@ class MenuDetailViewModel @Inject constructor( val menuId = _menu.value?.id ?: return if (_imageUriList.value?.isNotEmpty() == true) { context.showToast("이미지 압축 중입니다.") - _leaveReviewState.value = ReviewState.COMPRESSING + _leaveLeaveReviewState.value = LeaveReviewState.COMPRESSING val imageList = _imageUriList.value?.map { getCompressedImage(context, it) } @@ -212,15 +221,4 @@ class MenuDetailViewModel @Inject constructor( val requestBody = file.asRequestBody("image/jpeg".toMediaTypeOrNull()) return MultipartBody.Part.createFormData("images", file.name, requestBody) } - - enum class State { - LOADING, - SUCCESS, - FAILED - } - - enum class ReviewState { - WAITING, - COMPRESSING - } } From 972a7c55718c2e35a2475cb4ddc12ba394b7593f Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Sun, 3 Mar 2024 18:32:10 +0900 Subject: [PATCH 52/68] =?UTF-8?q?formatting=20+=20=EB=B9=8C=EB=93=9C=20?= =?UTF-8?q?=ED=99=95=EC=9D=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/compose/menuDetail/MenuRatingStars.kt | 2 -- .../components/compose/menuDetail/MenuReviewImage.kt | 12 ++---------- .../compose/menuDetail/MenuReviewImageShowMore.kt | 2 -- .../compose/ui/menuDetail/MenuDetailScreen.kt | 8 ++++---- .../compose/ui/menuDetail/review/ReviewScreen.kt | 2 -- .../siksha2/ui/menuDetail/LeaveReviewFragment.kt | 2 +- .../siksha2/ui/menuDetail/MenuDetailViewModel.kt | 2 +- 7 files changed, 8 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuRatingStars.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuRatingStars.kt index 8cd6c9ac..2bb69b60 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuRatingStars.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuRatingStars.kt @@ -2,7 +2,6 @@ package com.wafflestudio.siksha2.components.compose.menuDetail import androidx.compose.foundation.Image import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.aspectRatio import androidx.compose.foundation.layout.fillMaxHeight @@ -12,7 +11,6 @@ import androidx.compose.foundation.layout.width import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource -import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import com.wafflestudio.siksha2.R import kotlin.math.roundToInt diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuReviewImage.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuReviewImage.kt index 213afa93..e45f0eb9 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuReviewImage.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuReviewImage.kt @@ -2,12 +2,9 @@ package com.wafflestudio.siksha2.components.compose.menuDetail import android.net.Uri import androidx.compose.foundation.Image -import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf @@ -15,15 +12,10 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.res.painterResource -import androidx.compose.ui.unit.dp -import androidx.compose.ui.zIndex import coil.compose.rememberAsyncImagePainter import com.wafflestudio.siksha2.R -import com.wafflestudio.siksha2.ui.SikshaColors -import com.wafflestudio.siksha2.utils.dpToSp @Composable fun MenuReviewImage( @@ -44,8 +36,8 @@ fun MenuReviewImage( modifier = Modifier .fillMaxSize() .align(Alignment.Center) - .clickable{ - imageDialogState = true + .clickable { + imageDialogState = true }, painter = rememberAsyncImagePainter(imageUri), contentDescription = null, diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuReviewImageShowMore.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuReviewImageShowMore.kt index 08aac40d..2a9abfd4 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuReviewImageShowMore.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuReviewImageShowMore.kt @@ -13,11 +13,9 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.layout.ContentScale -import androidx.compose.ui.res.painterResource import androidx.compose.ui.unit.dp import androidx.compose.ui.zIndex import coil.compose.rememberAsyncImagePainter -import com.wafflestudio.siksha2.R import com.wafflestudio.siksha2.ui.SikshaColors import com.wafflestudio.siksha2.utils.dpToSp diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt index 4b8f1add..554b0745 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt @@ -136,9 +136,9 @@ fun MenuDetailScreen( modifier = Modifier.size(21.dp) ) Text( - text = stringResource(R.string.review_like_prefix) - + (menu?.likeCount ?: 0).toString() - + stringResource(R.string.review_like_suffix), + text = stringResource(R.string.review_like_prefix) + + (menu?.likeCount ?: 0).toString() + + stringResource(R.string.review_like_suffix), fontSize = dpToSp(14.dp), fontWeight = FontWeight.Medium ) @@ -171,7 +171,7 @@ fun MenuDetailScreen( fontWeight = FontWeight.Bold ) Text( - text = reviews?.itemCount.toString(), + text = reviews.itemCount.toString(), color = SikshaColors.OrangeMain, fontSize = dpToSp(10.dp), fontWeight = FontWeight.Bold diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt index c81f1fef..6232883e 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt @@ -13,8 +13,6 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.material.Text import androidx.compose.runtime.Composable -import androidx.compose.runtime.collectAsState -import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/LeaveReviewFragment.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/LeaveReviewFragment.kt index 42e10fea..126cb73c 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/LeaveReviewFragment.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/LeaveReviewFragment.kt @@ -130,7 +130,7 @@ class LeaveReviewFragment : Fragment() { } vm.leaveLeaveReviewState.observe(viewLifecycleOwner) { - binding.onLoadingContainer.root.setVisibleOrGone(it == MenuDetailViewModel.ReviewState.COMPRESSING) + binding.onLoadingContainer.root.setVisibleOrGone(it == LeaveReviewState.COMPRESSING) } binding.closeButton.setOnClickListener { diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt index 036d1efe..16645b97 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt @@ -96,7 +96,7 @@ class MenuDetailViewModel @Inject constructor( @OptIn(ExperimentalCoroutinesApi::class) val reviewsWithImage: StateFlow> = - _menu.asFlow().filterNotNull().flatMapLatest {menu -> + _menu.asFlow().filterNotNull().flatMapLatest { menu -> Pager( config = MenuReviewWithImagePagingSource.Config, pagingSourceFactory = { From cd8e5cd15e9e531059385158831a77d5d8e5d437 Mon Sep 17 00:00:00 2001 From: eastshine2741 Date: Mon, 4 Mar 2024 13:56:54 +0900 Subject: [PATCH 53/68] =?UTF-8?q?enum=20class=EB=93=A4=20=EB=B3=84?= =?UTF-8?q?=EA=B0=9C=20=ED=8C=8C=EC=9D=BC=EB=A1=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../siksha2/ui/menuDetail/LeaveReviewState.kt | 6 ++++++ .../siksha2/ui/menuDetail/MenuDetailViewModel.kt | 11 ----------- .../siksha2/ui/menuDetail/MenuLoadingState.kt | 7 +++++++ 3 files changed, 13 insertions(+), 11 deletions(-) create mode 100644 app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/LeaveReviewState.kt create mode 100644 app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuLoadingState.kt diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/LeaveReviewState.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/LeaveReviewState.kt new file mode 100644 index 00000000..945106a4 --- /dev/null +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/LeaveReviewState.kt @@ -0,0 +1,6 @@ +package com.wafflestudio.siksha2.ui.menuDetail + +enum class LeaveReviewState { + WAITING, + COMPRESSING +} diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt index 16645b97..23b43d13 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt @@ -36,17 +36,6 @@ import java.io.File import java.io.IOException import javax.inject.Inject -enum class MenuLoadingState { - LOADING, - SUCCESS, - FAILED -} - -enum class LeaveReviewState { - WAITING, - COMPRESSING -} - @HiltViewModel class MenuDetailViewModel @Inject constructor( private val menuRepository: MenuRepository diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuLoadingState.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuLoadingState.kt new file mode 100644 index 00000000..87f83179 --- /dev/null +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuLoadingState.kt @@ -0,0 +1,7 @@ +package com.wafflestudio.siksha2.ui.menuDetail + +enum class MenuLoadingState { + LOADING, + SUCCESS, + FAILED +} From 735416b45a413c27257c9465ee59389346706b2f Mon Sep 17 00:00:00 2001 From: eastshine2741 Date: Mon, 4 Mar 2024 13:59:33 +0900 Subject: [PATCH 54/68] =?UTF-8?q?=EC=95=88=EC=93=B0=EC=9D=B4=EB=8A=94=20St?= =?UTF-8?q?ateFlow=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../siksha2/ui/menuDetail/MenuDetailViewModel.kt | 8 -------- 1 file changed, 8 deletions(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt index 23b43d13..06586010 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt @@ -60,14 +60,6 @@ class MenuDetailViewModel @Inject constructor( val imageUriList: LiveData> get() = _imageUriList - private val _imageUrlList = MutableLiveData>() - val imageUrlList: LiveData> - get() = _imageUrlList - - private val _imageCount = MutableLiveData(0) - val imageCount: LiveData - get() = _imageCount - private val _leaveLeaveReviewState = MutableLiveData(LeaveReviewState.WAITING) val leaveLeaveReviewState: LiveData get() = _leaveLeaveReviewState From 3c2c881fd05871bc73e878c7d26cdf2d702bfc53 Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Thu, 7 Mar 2024 17:17:01 +0900 Subject: [PATCH 55/68] fix typo --- .../siksha2/ui/menuDetail/LeaveReviewFragment.kt | 2 +- .../siksha2/ui/menuDetail/MenuDetailViewModel.kt | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/LeaveReviewFragment.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/LeaveReviewFragment.kt index 126cb73c..8e49e416 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/LeaveReviewFragment.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/LeaveReviewFragment.kt @@ -129,7 +129,7 @@ class LeaveReviewFragment : Fragment() { binding.imageLayout.setVisibleOrGone(imageUriList.isNotEmpty()) } - vm.leaveLeaveReviewState.observe(viewLifecycleOwner) { + vm.leaveReviewState.observe(viewLifecycleOwner) { binding.onLoadingContainer.root.setVisibleOrGone(it == LeaveReviewState.COMPRESSING) } diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt index 06586010..f651427d 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailViewModel.kt @@ -60,9 +60,9 @@ class MenuDetailViewModel @Inject constructor( val imageUriList: LiveData> get() = _imageUriList - private val _leaveLeaveReviewState = MutableLiveData(LeaveReviewState.WAITING) - val leaveLeaveReviewState: LiveData - get() = _leaveLeaveReviewState + private val _leaveReviewState = MutableLiveData(LeaveReviewState.WAITING) + val leaveReviewState: LiveData + get() = _leaveReviewState @OptIn(ExperimentalCoroutinesApi::class) val reviews: StateFlow> = @@ -148,7 +148,7 @@ class MenuDetailViewModel @Inject constructor( } fun notifySendReviewEnd() { - _leaveLeaveReviewState.value = LeaveReviewState.WAITING + _leaveReviewState.value = LeaveReviewState.WAITING } fun toggleLike() { @@ -178,7 +178,7 @@ class MenuDetailViewModel @Inject constructor( val menuId = _menu.value?.id ?: return if (_imageUriList.value?.isNotEmpty() == true) { context.showToast("이미지 압축 중입니다.") - _leaveLeaveReviewState.value = LeaveReviewState.COMPRESSING + _leaveReviewState.value = LeaveReviewState.COMPRESSING val imageList = _imageUriList.value?.map { getCompressedImage(context, it) } From b4e11eb9158bf349f7032d77753b9279b41d1b7a Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Thu, 7 Mar 2024 17:31:23 +0900 Subject: [PATCH 56/68] =?UTF-8?q?MenuRatingStars=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/compose/menuDetail/MenuRatingStars.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuRatingStars.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuRatingStars.kt index 2bb69b60..fa840b4d 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuRatingStars.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/menuDetail/MenuRatingStars.kt @@ -36,12 +36,14 @@ private fun MenuReviewSingleStar( @Composable fun MenuRatingStars( rating: Float, - modifier: Modifier = Modifier.width(100.dp).height(18.dp), - dragEnabled: Boolean = false + modifier: Modifier = Modifier, + dragEnabled: Boolean = false, + width: Int = 100, + height: Int = 18 ) { val rounds = (rating * 2).roundToInt() Row( - modifier = modifier, + modifier = modifier.width(width.dp).height(height.dp), horizontalArrangement = Arrangement.SpaceBetween ) { for (i in 1..5) { From 8533cc6550836ff0220cbba85802683f785fd0a5 Mon Sep 17 00:00:00 2001 From: wjshim2003 Date: Mon, 11 Mar 2024 17:28:56 +0900 Subject: [PATCH 57/68] =?UTF-8?q?ReviewPhotoFragment=20=EB=B6=80=ED=99=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../compose/ui/menuDetail/MenuDetailScreen.kt | 572 +++++++++--------- .../ui/menuDetail/review/ReviewFragment.kt | 2 +- .../menuDetail/review/ReviewPhotoFragment.kt | 36 +- .../main/res/layout/fragment_review_photo.xml | 117 ++-- app/src/main/res/navigation/nav_graph.xml | 4 - 5 files changed, 368 insertions(+), 363 deletions(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt index 554b0745..d4f15de9 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt @@ -40,6 +40,7 @@ import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel import androidx.navigation.NavController +import androidx.paging.compose.LazyPagingItems import androidx.paging.compose.collectAsLazyPagingItems import com.wafflestudio.siksha2.R import com.wafflestudio.siksha2.components.compose.ErrorPlaceHolder @@ -50,6 +51,8 @@ import com.wafflestudio.siksha2.components.compose.menuDetail.MenuReview import com.wafflestudio.siksha2.components.compose.menuDetail.MenuReviewImage import com.wafflestudio.siksha2.components.compose.menuDetail.LikeButton import com.wafflestudio.siksha2.components.compose.menuDetail.MenuReviewImageShowMore +import com.wafflestudio.siksha2.models.Menu +import com.wafflestudio.siksha2.models.Review import com.wafflestudio.siksha2.ui.SikshaColors import com.wafflestudio.siksha2.ui.menuDetail.MenuDetailFragmentDirections import com.wafflestudio.siksha2.ui.menuDetail.MenuDetailViewModel @@ -70,8 +73,6 @@ fun MenuDetailScreen( val reviews = menuDetailViewModel.reviews.collectAsLazyPagingItems() val imageReviews = menuDetailViewModel.reviewsWithImage.collectAsLazyPagingItems() val loadingState = menuDetailViewModel.networkResultMenuLoadingState.observeAsState() - val imagePreviewScrollState = rememberScrollState() - val context = LocalContext.current LaunchedEffect(Unit) { menuDetailViewModel.refreshMenu(menuId) @@ -113,313 +114,334 @@ fun MenuDetailScreen( when (loadingState.value) { MenuLoadingState.SUCCESS -> { - LazyColumn( + MenuDetailContent( + menuId, + menu, + reviews, + imageReviews, + isTodayMenu, + menuDetailViewModel, + navController + ) + } + MenuLoadingState.LOADING -> { + LoadingPlaceHolder( + modifier = Modifier + .fillMaxWidth() + .weight(1f) + ) + } + MenuLoadingState.FAILED -> { + ErrorPlaceHolder( + modifier = Modifier + .fillMaxWidth() + .weight(1f) + ) + } + else -> {} + } + } +} + +@Composable +fun MenuDetailContent( + menuId: Long, + menu: Menu?, + reviews: LazyPagingItems, + imageReviews: LazyPagingItems, + isTodayMenu: Boolean, + menuDetailViewModel: MenuDetailViewModel, + navController: NavController, + modifier: Modifier = Modifier +) { + val context = LocalContext.current + val imagePreviewScrollState = rememberScrollState() + LazyColumn( + modifier = modifier + .fillMaxWidth() + .background(SikshaColors.White900) + ) { + // 상단 별점 정보 + a + item { + Column( + modifier = Modifier.fillMaxWidth() + ) { + Column( modifier = Modifier .fillMaxWidth() - .background(SikshaColors.White900) + .padding(vertical = 18.dp), + verticalArrangement = Arrangement.spacedBy(9.dp), + horizontalAlignment = Alignment.CenterHorizontally ) { - // 상단 별점 정보 + a - item { + LikeButton( + isChecked = menu?.isLiked ?: false, + onClick = { menuDetailViewModel.toggleLike() }, + modifier = Modifier.size(21.dp) + ) + Text( + text = stringResource(R.string.review_like_prefix) + + (menu?.likeCount ?: 0).toString() + + stringResource(R.string.review_like_suffix), + fontSize = dpToSp(14.dp), + fontWeight = FontWeight.Medium + ) + } + + Divider( + modifier = Modifier.padding(horizontal = 17.dp), + color = SikshaColors.OrangeMain, + thickness = 1.dp + ) + + Column( + modifier = Modifier + .fillMaxWidth() + .padding( + top = 15.dp, + bottom = 15.dp, + start = 45.dp, + end = 25.dp + ) + ) { + Row( + modifier = Modifier.align(Alignment.CenterHorizontally), + horizontalArrangement = Arrangement.Center + ) { + Text( + text = stringResource(R.string.review_count_prefix), + color = SikshaColors.Gray800, + fontSize = dpToSp(10.dp), + fontWeight = FontWeight.Bold + ) + Text( + text = reviews.itemCount.toString(), + color = SikshaColors.OrangeMain, + fontSize = dpToSp(10.dp), + fontWeight = FontWeight.Bold + ) + Text( + text = stringResource(R.string.review_count_suffix_orange), + color = SikshaColors.OrangeMain, + fontSize = dpToSp(10.dp), + fontWeight = FontWeight.Bold + ) + Text( + text = stringResource(R.string.review_count_suffix_black), + color = SikshaColors.Gray800, + fontSize = dpToSp(10.dp), + fontWeight = FontWeight.Bold + ) + } + + Row( + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 20.dp, vertical = 10.dp), + horizontalArrangement = Arrangement.spacedBy(20.dp), + verticalAlignment = Alignment.CenterVertically + ) { Column( - modifier = Modifier.fillMaxWidth() + horizontalAlignment = Alignment.CenterHorizontally ) { - Column( - modifier = Modifier - .fillMaxWidth() - .padding(vertical = 18.dp), - verticalArrangement = Arrangement.spacedBy(9.dp), - horizontalAlignment = Alignment.CenterHorizontally - ) { - LikeButton( - isChecked = menu?.isLiked ?: false, - onClick = { menuDetailViewModel.toggleLike() }, - modifier = Modifier.size(21.dp) - ) - Text( - text = stringResource(R.string.review_like_prefix) + - (menu?.likeCount ?: 0).toString() + - stringResource(R.string.review_like_suffix), - fontSize = dpToSp(14.dp), - fontWeight = FontWeight.Medium - ) - } + Text( + text = "${ + menu?.score?.times(10)?.let { round(it) / 10 } ?: "0.0" + }", + fontSize = dpToSp(32.dp), + fontWeight = FontWeight.ExtraBold + ) + MenuRatingStars( + rating = menu?.score?.toFloat() ?: 0.0f + ) + } + menuDetailViewModel.reviewDistribution.value?.let { + MenuRatingBars( + distributions = it, + modifier = Modifier.weight(1f) + ) + } + } - Divider( - modifier = Modifier.padding(horizontal = 17.dp), + Box( + modifier = Modifier + .width(200.dp) + .height(32.dp) + .background( color = SikshaColors.OrangeMain, - thickness = 1.dp + shape = RoundedCornerShape(50.dp) ) - - Column( - modifier = Modifier - .fillMaxWidth() - .padding( - top = 15.dp, - bottom = 15.dp, - start = 45.dp, - end = 25.dp - ) - ) { - Row( - modifier = Modifier.align(Alignment.CenterHorizontally), - horizontalArrangement = Arrangement.Center - ) { - Text( - text = stringResource(R.string.review_count_prefix), - color = SikshaColors.Gray800, - fontSize = dpToSp(10.dp), - fontWeight = FontWeight.Bold - ) - Text( - text = reviews.itemCount.toString(), - color = SikshaColors.OrangeMain, - fontSize = dpToSp(10.dp), - fontWeight = FontWeight.Bold - ) - Text( - text = stringResource(R.string.review_count_suffix_orange), - color = SikshaColors.OrangeMain, - fontSize = dpToSp(10.dp), - fontWeight = FontWeight.Bold - ) - Text( - text = stringResource(R.string.review_count_suffix_black), - color = SikshaColors.Gray800, - fontSize = dpToSp(10.dp), - fontWeight = FontWeight.Bold - ) - } - - Row( - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 20.dp, vertical = 10.dp), - horizontalArrangement = Arrangement.spacedBy(20.dp), - verticalAlignment = Alignment.CenterVertically - ) { - Column( - horizontalAlignment = Alignment.CenterHorizontally - ) { - Text( - text = "${ - menu?.score?.times(10)?.let { round(it) / 10 } ?: "0.0" - }", - fontSize = dpToSp(32.dp), - fontWeight = FontWeight.ExtraBold - ) - MenuRatingStars( - rating = menu?.score?.toFloat() ?: 0.0f - ) - } - menuDetailViewModel.reviewDistribution.value?.let { - MenuRatingBars( - distributions = it, - modifier = Modifier.weight(1f) + .clickable { } + .align(Alignment.CenterHorizontally) + ) { + Text( + text = stringResource(R.string.menu_detail_leave_review_button), + fontSize = dpToSp(14.dp), + fontWeight = FontWeight.ExtraBold, + color = SikshaColors.White900, + modifier = Modifier + .align(Alignment.Center) + .clickable { + if (isTodayMenu) { + navController.navigate( + MenuDetailFragmentDirections.actionMenuDetailFragmentToLeaveReviewFragment() ) + } else { + Toast + .makeText( + context, + "오늘 메뉴만 평가할 수 있습니다.", + Toast.LENGTH_SHORT + ) + .show() } } + ) + } + } + Spacer( + modifier = Modifier + .fillMaxWidth() + .height(10.dp) + .background(SikshaColors.Gray100) + ) + } + } - Box( - modifier = Modifier - .width(200.dp) - .height(32.dp) - .background( - color = SikshaColors.OrangeMain, - shape = RoundedCornerShape(50.dp) - ) - .clickable { } - .align(Alignment.CenterHorizontally) - ) { - Text( - text = stringResource(R.string.menu_detail_leave_review_button), - fontSize = dpToSp(14.dp), - fontWeight = FontWeight.ExtraBold, - color = SikshaColors.White900, - modifier = Modifier - .align(Alignment.Center) - .clickable { - if (isTodayMenu) { - navController.navigate( - MenuDetailFragmentDirections.actionMenuDetailFragmentToLeaveReviewFragment() - ) - } else { - Toast - .makeText( - context, - "오늘 메뉴만 평가할 수 있습니다.", - Toast.LENGTH_SHORT - ) - .show() - } - } + // 사진 리뷰 + if (imageReviews.itemCount > 0) { + item { + Box( + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 16.dp) + .height(50.dp) + ) { + Text( + text = stringResource(R.string.menu_detail_photo_review_gather), + fontSize = dpToSp(14.dp), + fontWeight = FontWeight.Medium, + modifier = Modifier.align(Alignment.CenterStart) + ) + Image( + painter = painterResource(R.drawable.ic_back_arrow), + contentDescription = stringResource(R.string.menu_detail_photo_review_gather), + colorFilter = ColorFilter.tint(SikshaColors.Gray400), + modifier = Modifier + .align(Alignment.CenterEnd) + .rotate(180f) + .clickable { + navController.navigate( + MenuDetailFragmentDirections.actionMenuDetailFragmentToReviewPhotoFragment( + menuId ) - } + ) } - Spacer( + ) + } + Row( + modifier = Modifier + .padding(horizontal = 16.dp) + .horizontalScroll(imagePreviewScrollState), + horizontalArrangement = Arrangement.spacedBy(8.dp) + ) { + for (i: Int in 1..min(imageReviews.itemCount, 3)) { + when (val it = imageReviews.itemSnapshotList.items[i - 1].etc?.images?.get(0)) { + null -> Box( modifier = Modifier - .fillMaxWidth() - .height(10.dp) + .size(120.dp) .background(SikshaColors.Gray100) + .clip(RoundedCornerShape(10.dp)) ) - } - } - - // 사진 리뷰 - if (imageReviews.itemCount > 0) { - item { - Box( - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 16.dp) - .height(50.dp) - ) { - Text( - text = stringResource(R.string.menu_detail_photo_review_gather), - fontSize = dpToSp(14.dp), - fontWeight = FontWeight.Medium, - modifier = Modifier.align(Alignment.CenterStart) - ) - Image( - painter = painterResource(R.drawable.ic_back_arrow), - contentDescription = stringResource(R.string.menu_detail_photo_review_gather), - colorFilter = ColorFilter.tint(SikshaColors.Gray400), - modifier = Modifier - .align(Alignment.CenterEnd) - .rotate(180f) - .clickable { + else -> { + if (i == 3) { + MenuReviewImageShowMore( + imageUri = Uri.parse(it), + modifier = Modifier + .size(120.dp) + .clip(RoundedCornerShape(10.dp)), + showMoreCount = imageReviews.itemCount - 2, + onShowMore = { navController.navigate( - MenuDetailFragmentDirections.actionMenuDetailFragmentToReviewFragment( - menuId, - true + MenuDetailFragmentDirections.actionMenuDetailFragmentToReviewPhotoFragment( + menuId ) ) } - ) - } - Row( - modifier = Modifier - .padding(horizontal = 16.dp) - .horizontalScroll(imagePreviewScrollState), - horizontalArrangement = Arrangement.spacedBy(8.dp) - ) { - for (i: Int in 1..min(imageReviews.itemCount, 3)) { - when (val it = imageReviews.itemSnapshotList.items[i - 1].etc?.images?.get(0)) { - null -> Box( - modifier = Modifier - .size(120.dp) - .background(SikshaColors.Gray100) - .clip(RoundedCornerShape(10.dp)) - ) - else -> { - if (i == 3) { - MenuReviewImageShowMore( - imageUri = Uri.parse(it), - modifier = Modifier - .size(120.dp) - .clip(RoundedCornerShape(10.dp)), - showMoreCount = imageReviews.itemCount - 2, - onShowMore = { - navController.navigate( - MenuDetailFragmentDirections.actionMenuDetailFragmentToReviewFragment( - menuId, - true - ) - ) - } - ) - } else { - MenuReviewImage( - imageUri = Uri.parse(it), - modifier = Modifier - .size(120.dp) - .clip(RoundedCornerShape(10.dp)) - ) - } - } - } + ) + } else { + MenuReviewImage( + imageUri = Uri.parse(it), + modifier = Modifier + .size(120.dp) + .clip(RoundedCornerShape(10.dp)) + ) } } } } + } + } + } - // 일반 리뷰 - if (reviews.itemCount > 0) { - item { - Box( - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 16.dp) - .height(50.dp) - ) { - Text( - text = stringResource(R.string.menu_detail_review_gather), - fontSize = dpToSp(14.dp), - fontWeight = FontWeight.Medium, - modifier = Modifier.align(Alignment.CenterStart) - ) - Image( - painter = painterResource(R.drawable.ic_back_arrow), - contentDescription = "리뷰", - colorFilter = ColorFilter.tint(SikshaColors.Gray400), - modifier = Modifier - .align(Alignment.CenterEnd) - .rotate(180f) - .clickable { - navController.navigate( - MenuDetailFragmentDirections.actionMenuDetailFragmentToReviewFragment( - menuId, - false - ) - ) - } - ) - } - } - items(reviews.itemCount) { - reviews[it]?.let { review -> - MenuReview( - review = review, - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 16.dp), - showImage = true - ) - } - } - } else { - item { - Box( - modifier = Modifier - .padding(vertical = 36.dp) - .fillMaxWidth() - ) { - Text( - text = stringResource(R.string.review_nothing), - fontSize = dpToSp(18.dp), - fontWeight = FontWeight.Light, - modifier = Modifier.align(Alignment.Center), - color = SikshaColors.Gray600 + // 일반 리뷰 + if (reviews.itemCount > 0) { + item { + Box( + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 16.dp) + .height(50.dp) + ) { + Text( + text = stringResource(R.string.menu_detail_review_gather), + fontSize = dpToSp(14.dp), + fontWeight = FontWeight.Medium, + modifier = Modifier.align(Alignment.CenterStart) + ) + Image( + painter = painterResource(R.drawable.ic_back_arrow), + contentDescription = "리뷰", + colorFilter = ColorFilter.tint(SikshaColors.Gray400), + modifier = Modifier + .align(Alignment.CenterEnd) + .rotate(180f) + .clickable { + navController.navigate( + MenuDetailFragmentDirections.actionMenuDetailFragmentToReviewFragment( + menuId + ) ) } - } - } + ) } } - MenuLoadingState.LOADING -> { - LoadingPlaceHolder( - modifier = Modifier - .fillMaxWidth() - .weight(1f) - ) + items(reviews.itemCount) { + reviews[it]?.let { review -> + MenuReview( + review = review, + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 16.dp), + showImage = true + ) + } } - MenuLoadingState.FAILED -> { - ErrorPlaceHolder( + } else { + item { + Box( modifier = Modifier + .padding(vertical = 36.dp) .fillMaxWidth() - .weight(1f) - ) + ) { + Text( + text = stringResource(R.string.review_nothing), + fontSize = dpToSp(18.dp), + fontWeight = FontWeight.Light, + modifier = Modifier.align(Alignment.Center), + color = SikshaColors.Gray600 + ) + } } - else -> {} } } } diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt index f76aaff9..e238c982 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt @@ -34,7 +34,7 @@ class ReviewFragment : Fragment() { SikshaTheme { ReviewScreen( navController = findNavController(), - showImages = args.showImages, + showImages = true, menuDetailViewModel = vm ) } diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewPhotoFragment.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewPhotoFragment.kt index 95e47c87..dcb52a40 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewPhotoFragment.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewPhotoFragment.kt @@ -11,7 +11,9 @@ import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.navArgs import androidx.paging.LoadState import androidx.recyclerview.widget.LinearLayoutManager +import com.wafflestudio.siksha2.compose.ui.menuDetail.review.ReviewScreen import com.wafflestudio.siksha2.databinding.FragmentReviewPhotoBinding +import com.wafflestudio.siksha2.ui.SikshaTheme import com.wafflestudio.siksha2.ui.menuDetail.MenuDetailViewModel import com.wafflestudio.siksha2.ui.menuDetail.MenuReviewsAdapter import com.wafflestudio.siksha2.utils.setVisibleOrGone @@ -22,7 +24,6 @@ class ReviewPhotoFragment : Fragment() { private lateinit var binding: FragmentReviewPhotoBinding private val vm: MenuDetailViewModel by activityViewModels() private val args: ReviewPhotoFragmentArgs by navArgs() - private lateinit var reviewsAdapter: MenuReviewsAdapter override fun onCreateView( inflater: LayoutInflater, @@ -35,33 +36,14 @@ class ReviewPhotoFragment : Fragment() { } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - reviewsAdapter = MenuReviewsAdapter(true, childFragmentManager) - - binding.reviewList.apply { - layoutManager = LinearLayoutManager(context) - adapter = reviewsAdapter - } - - lifecycleScope.launch { - reviewsAdapter.loadStateFlow - .collectLatest { - if (it.refresh is LoadState.NotLoading) { - (reviewsAdapter.itemCount < 1).let { empty -> - binding.reviewList.setVisibleOrGone(empty.not()) - binding.textNoReviews.setVisibleOrGone(empty) - } - } - } - } - - lifecycleScope.launch { - vm.getReviewsWithImages(args.menuId).collectLatest { - reviewsAdapter.submitData(it) + binding.reviewPhotoComposeView.setContent { + SikshaTheme { + ReviewScreen( + navController = findNavController(), + showImages = true, + menuDetailViewModel = vm + ) } } - - binding.closeButton.setOnClickListener { - findNavController().popBackStack() - } } } diff --git a/app/src/main/res/layout/fragment_review_photo.xml b/app/src/main/res/layout/fragment_review_photo.xml index b9803614..7997eb0c 100644 --- a/app/src/main/res/layout/fragment_review_photo.xml +++ b/app/src/main/res/layout/fragment_review_photo.xml @@ -8,68 +8,73 @@ android:orientation="vertical" tools:context=".ui.menuDetail.review.ReviewPhotoFragment"> - + + + + + + + - + + + + + + + - + + + + + + + + + + + - - + + + + + + + + + - + - + + + + + + + + + + + + + + + + + + + + + + + - + android:layout_height="match_parent" + android:id="@+id/review_photo_compose_view"/> \ No newline at end of file diff --git a/app/src/main/res/navigation/nav_graph.xml b/app/src/main/res/navigation/nav_graph.xml index 588f827a..efbc1811 100644 --- a/app/src/main/res/navigation/nav_graph.xml +++ b/app/src/main/res/navigation/nav_graph.xml @@ -100,10 +100,6 @@ - Date: Thu, 7 Mar 2024 17:31:23 +0900 Subject: [PATCH 58/68] =?UTF-8?q?MenuDetailScreen=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=A0=95=EB=A6=AC,=20fix=20typo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../compose/ui/menuDetail/MenuDetailScreen.kt | 449 ++++++++++-------- .../ui/menuDetail/review/ReviewFragment.kt | 4 +- .../menuDetail/review/ReviewPhotoFragment.kt | 9 - 3 files changed, 241 insertions(+), 221 deletions(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt index d4f15de9..7d54de06 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt @@ -155,7 +155,6 @@ fun MenuDetailContent( modifier: Modifier = Modifier ) { val context = LocalContext.current - val imagePreviewScrollState = rememberScrollState() LazyColumn( modifier = modifier .fillMaxWidth() @@ -163,223 +162,36 @@ fun MenuDetailContent( ) { // 상단 별점 정보 + a item { - Column( - modifier = Modifier.fillMaxWidth() - ) { - Column( - modifier = Modifier - .fillMaxWidth() - .padding(vertical = 18.dp), - verticalArrangement = Arrangement.spacedBy(9.dp), - horizontalAlignment = Alignment.CenterHorizontally - ) { - LikeButton( - isChecked = menu?.isLiked ?: false, - onClick = { menuDetailViewModel.toggleLike() }, - modifier = Modifier.size(21.dp) - ) - Text( - text = stringResource(R.string.review_like_prefix) + - (menu?.likeCount ?: 0).toString() + - stringResource(R.string.review_like_suffix), - fontSize = dpToSp(14.dp), - fontWeight = FontWeight.Medium - ) - } - - Divider( - modifier = Modifier.padding(horizontal = 17.dp), - color = SikshaColors.OrangeMain, - thickness = 1.dp - ) - - Column( - modifier = Modifier - .fillMaxWidth() - .padding( - top = 15.dp, - bottom = 15.dp, - start = 45.dp, - end = 25.dp - ) - ) { - Row( - modifier = Modifier.align(Alignment.CenterHorizontally), - horizontalArrangement = Arrangement.Center - ) { - Text( - text = stringResource(R.string.review_count_prefix), - color = SikshaColors.Gray800, - fontSize = dpToSp(10.dp), - fontWeight = FontWeight.Bold - ) - Text( - text = reviews.itemCount.toString(), - color = SikshaColors.OrangeMain, - fontSize = dpToSp(10.dp), - fontWeight = FontWeight.Bold + MenuStatistics( + menu, + reviews, + menuDetailViewModel, + { + if (isTodayMenu) { + navController.navigate( + MenuDetailFragmentDirections.actionMenuDetailFragmentToLeaveReviewFragment() ) - Text( - text = stringResource(R.string.review_count_suffix_orange), - color = SikshaColors.OrangeMain, - fontSize = dpToSp(10.dp), - fontWeight = FontWeight.Bold - ) - Text( - text = stringResource(R.string.review_count_suffix_black), - color = SikshaColors.Gray800, - fontSize = dpToSp(10.dp), - fontWeight = FontWeight.Bold - ) - } - - Row( - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 20.dp, vertical = 10.dp), - horizontalArrangement = Arrangement.spacedBy(20.dp), - verticalAlignment = Alignment.CenterVertically - ) { - Column( - horizontalAlignment = Alignment.CenterHorizontally - ) { - Text( - text = "${ - menu?.score?.times(10)?.let { round(it) / 10 } ?: "0.0" - }", - fontSize = dpToSp(32.dp), - fontWeight = FontWeight.ExtraBold - ) - MenuRatingStars( - rating = menu?.score?.toFloat() ?: 0.0f - ) - } - menuDetailViewModel.reviewDistribution.value?.let { - MenuRatingBars( - distributions = it, - modifier = Modifier.weight(1f) - ) - } - } - - Box( - modifier = Modifier - .width(200.dp) - .height(32.dp) - .background( - color = SikshaColors.OrangeMain, - shape = RoundedCornerShape(50.dp) + } else { + Toast + .makeText( + context, + "오늘 메뉴만 평가할 수 있습니다.", + Toast.LENGTH_SHORT ) - .clickable { } - .align(Alignment.CenterHorizontally) - ) { - Text( - text = stringResource(R.string.menu_detail_leave_review_button), - fontSize = dpToSp(14.dp), - fontWeight = FontWeight.ExtraBold, - color = SikshaColors.White900, - modifier = Modifier - .align(Alignment.Center) - .clickable { - if (isTodayMenu) { - navController.navigate( - MenuDetailFragmentDirections.actionMenuDetailFragmentToLeaveReviewFragment() - ) - } else { - Toast - .makeText( - context, - "오늘 메뉴만 평가할 수 있습니다.", - Toast.LENGTH_SHORT - ) - .show() - } - } - ) + .show() } } - Spacer( - modifier = Modifier - .fillMaxWidth() - .height(10.dp) - .background(SikshaColors.Gray100) - ) - } + ) } // 사진 리뷰 if (imageReviews.itemCount > 0) { item { - Box( - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 16.dp) - .height(50.dp) - ) { - Text( - text = stringResource(R.string.menu_detail_photo_review_gather), - fontSize = dpToSp(14.dp), - fontWeight = FontWeight.Medium, - modifier = Modifier.align(Alignment.CenterStart) - ) - Image( - painter = painterResource(R.drawable.ic_back_arrow), - contentDescription = stringResource(R.string.menu_detail_photo_review_gather), - colorFilter = ColorFilter.tint(SikshaColors.Gray400), - modifier = Modifier - .align(Alignment.CenterEnd) - .rotate(180f) - .clickable { - navController.navigate( - MenuDetailFragmentDirections.actionMenuDetailFragmentToReviewPhotoFragment( - menuId - ) - ) - } - ) - } - Row( - modifier = Modifier - .padding(horizontal = 16.dp) - .horizontalScroll(imagePreviewScrollState), - horizontalArrangement = Arrangement.spacedBy(8.dp) - ) { - for (i: Int in 1..min(imageReviews.itemCount, 3)) { - when (val it = imageReviews.itemSnapshotList.items[i - 1].etc?.images?.get(0)) { - null -> Box( - modifier = Modifier - .size(120.dp) - .background(SikshaColors.Gray100) - .clip(RoundedCornerShape(10.dp)) - ) - else -> { - if (i == 3) { - MenuReviewImageShowMore( - imageUri = Uri.parse(it), - modifier = Modifier - .size(120.dp) - .clip(RoundedCornerShape(10.dp)), - showMoreCount = imageReviews.itemCount - 2, - onShowMore = { - navController.navigate( - MenuDetailFragmentDirections.actionMenuDetailFragmentToReviewPhotoFragment( - menuId - ) - ) - } - ) - } else { - MenuReviewImage( - imageUri = Uri.parse(it), - modifier = Modifier - .size(120.dp) - .clip(RoundedCornerShape(10.dp)) - ) - } - } - } - } - } + MenuPhotoPreview( + menuId, + imageReviews, + navController + ) } } @@ -445,3 +257,222 @@ fun MenuDetailContent( } } } + +@Composable +fun MenuStatistics( + menu: Menu?, + reviews: LazyPagingItems, + menuDetailViewModel: MenuDetailViewModel, + onLeaveReview: () -> Unit, + modifier: Modifier = Modifier +) { + Column( + modifier = modifier.fillMaxWidth() + ) { + Column( + modifier = Modifier + .fillMaxWidth() + .padding(vertical = 18.dp), + verticalArrangement = Arrangement.spacedBy(9.dp), + horizontalAlignment = Alignment.CenterHorizontally + ) { + LikeButton( + isChecked = menu?.isLiked ?: false, + onClick = { menuDetailViewModel.toggleLike() }, + modifier = Modifier.size(21.dp) + ) + Text( + text = stringResource(R.string.review_like_prefix) + + (menu?.likeCount ?: 0).toString() + + stringResource(R.string.review_like_suffix), + fontSize = dpToSp(14.dp), + fontWeight = FontWeight.Medium + ) + } + + Divider( + modifier = Modifier.padding(horizontal = 17.dp), + color = SikshaColors.OrangeMain, + thickness = 1.dp + ) + + Column( + modifier = Modifier + .fillMaxWidth() + .padding( + top = 15.dp, + bottom = 15.dp, + start = 45.dp, + end = 25.dp + ) + ) { + Row( + modifier = Modifier.align(Alignment.CenterHorizontally), + horizontalArrangement = Arrangement.Center + ) { + Text( + text = stringResource(R.string.review_count_prefix), + color = SikshaColors.Gray800, + fontSize = dpToSp(10.dp), + fontWeight = FontWeight.Bold + ) + Text( + text = reviews.itemCount.toString(), + color = SikshaColors.OrangeMain, + fontSize = dpToSp(10.dp), + fontWeight = FontWeight.Bold + ) + Text( + text = stringResource(R.string.review_count_suffix_orange), + color = SikshaColors.OrangeMain, + fontSize = dpToSp(10.dp), + fontWeight = FontWeight.Bold + ) + Text( + text = stringResource(R.string.review_count_suffix_black), + color = SikshaColors.Gray800, + fontSize = dpToSp(10.dp), + fontWeight = FontWeight.Bold + ) + } + + Row( + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 20.dp, vertical = 10.dp), + horizontalArrangement = Arrangement.spacedBy(20.dp), + verticalAlignment = Alignment.CenterVertically + ) { + Column( + horizontalAlignment = Alignment.CenterHorizontally + ) { + Text( + text = "${ + menu?.score?.times(10)?.let { round(it) / 10 } ?: "0.0" + }", + fontSize = dpToSp(32.dp), + fontWeight = FontWeight.ExtraBold + ) + MenuRatingStars( + rating = menu?.score?.toFloat() ?: 0.0f + ) + } + menuDetailViewModel.reviewDistribution.value?.let { + MenuRatingBars( + distributions = it, + modifier = Modifier.weight(1f) + ) + } + } + + Box( + modifier = Modifier + .width(200.dp) + .height(32.dp) + .background( + color = SikshaColors.OrangeMain, + shape = RoundedCornerShape(50.dp) + ) + .clickable { + onLeaveReview() + } + .align(Alignment.CenterHorizontally) + ) { + Text( + text = stringResource(R.string.menu_detail_leave_review_button), + fontSize = dpToSp(14.dp), + fontWeight = FontWeight.ExtraBold, + color = SikshaColors.White900, + modifier = Modifier + .align(Alignment.Center) + ) + } + } + Spacer( + modifier = Modifier + .fillMaxWidth() + .height(10.dp) + .background(SikshaColors.Gray100) + ) + } +} + +@Composable +fun MenuPhotoPreview( + menuId: Long, + imageReviews: LazyPagingItems, + navController: NavController, + modifier: Modifier = Modifier +) { + val imagePreviewScrollState = rememberScrollState() + Box( + modifier = modifier + .fillMaxWidth() + .padding(horizontal = 16.dp) + .height(50.dp) + ) { + Text( + text = stringResource(R.string.menu_detail_photo_review_gather), + fontSize = dpToSp(14.dp), + fontWeight = FontWeight.Medium, + modifier = Modifier.align(Alignment.CenterStart) + ) + Image( + painter = painterResource(R.drawable.ic_back_arrow), + contentDescription = stringResource(R.string.menu_detail_photo_review_gather), + colorFilter = ColorFilter.tint(SikshaColors.Gray400), + modifier = Modifier + .align(Alignment.CenterEnd) + .rotate(180f) + .clickable { + navController.navigate( + MenuDetailFragmentDirections.actionMenuDetailFragmentToReviewPhotoFragment( + menuId + ) + ) + } + ) + } + Row( + modifier = Modifier + .padding(horizontal = 16.dp) + .horizontalScroll(imagePreviewScrollState), + horizontalArrangement = Arrangement.spacedBy(8.dp) + ) { + for (i: Int in 1..min(imageReviews.itemCount, 3)) { + when (val it = imageReviews.itemSnapshotList.items[i - 1].etc?.images?.get(0)) { + null -> Box( + modifier = Modifier + .size(120.dp) + .background(SikshaColors.Gray100) + .clip(RoundedCornerShape(10.dp)) + ) + else -> { + if (i == 3) { + MenuReviewImageShowMore( + imageUri = Uri.parse(it), + modifier = Modifier + .size(120.dp) + .clip(RoundedCornerShape(10.dp)), + showMoreCount = imageReviews.itemCount - 2, + onShowMore = { + navController.navigate( + MenuDetailFragmentDirections.actionMenuDetailFragmentToReviewPhotoFragment( + menuId + ) + ) + } + ) + } else { + MenuReviewImage( + imageUri = Uri.parse(it), + modifier = Modifier + .size(120.dp) + .clip(RoundedCornerShape(10.dp)) + ) + } + } + } + } + } +} diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt index e238c982..b178765b 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt @@ -7,7 +7,6 @@ import android.view.ViewGroup import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels import androidx.navigation.fragment.findNavController -import androidx.navigation.fragment.navArgs import com.wafflestudio.siksha2.compose.ui.menuDetail.review.ReviewScreen import com.wafflestudio.siksha2.databinding.FragmentReviewBinding import com.wafflestudio.siksha2.ui.SikshaTheme @@ -17,7 +16,6 @@ class ReviewFragment : Fragment() { private lateinit var binding: FragmentReviewBinding private val vm: MenuDetailViewModel by activityViewModels() - private val args: ReviewFragmentArgs by navArgs() override fun onCreateView( inflater: LayoutInflater, @@ -34,7 +32,7 @@ class ReviewFragment : Fragment() { SikshaTheme { ReviewScreen( navController = findNavController(), - showImages = true, + showImages = false, menuDetailViewModel = vm ) } diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewPhotoFragment.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewPhotoFragment.kt index dcb52a40..8a828378 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewPhotoFragment.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewPhotoFragment.kt @@ -6,24 +6,15 @@ import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels -import androidx.lifecycle.lifecycleScope import androidx.navigation.fragment.findNavController -import androidx.navigation.fragment.navArgs -import androidx.paging.LoadState -import androidx.recyclerview.widget.LinearLayoutManager import com.wafflestudio.siksha2.compose.ui.menuDetail.review.ReviewScreen import com.wafflestudio.siksha2.databinding.FragmentReviewPhotoBinding import com.wafflestudio.siksha2.ui.SikshaTheme import com.wafflestudio.siksha2.ui.menuDetail.MenuDetailViewModel -import com.wafflestudio.siksha2.ui.menuDetail.MenuReviewsAdapter -import com.wafflestudio.siksha2.utils.setVisibleOrGone -import kotlinx.coroutines.flow.collectLatest -import kotlinx.coroutines.launch class ReviewPhotoFragment : Fragment() { private lateinit var binding: FragmentReviewPhotoBinding private val vm: MenuDetailViewModel by activityViewModels() - private val args: ReviewPhotoFragmentArgs by navArgs() override fun onCreateView( inflater: LayoutInflater, From f5cc7acda27c3c9e2aa9881bdf0254c6a36cc25b Mon Sep 17 00:00:00 2001 From: eastshine2741 Date: Fri, 26 Jul 2024 22:05:54 +0900 Subject: [PATCH 59/68] =?UTF-8?q?MenuDetail=20Screen,=20Route=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../compose/ui/menuDetail/MenuDetailScreen.kt | 138 +++++++++++------- .../ui/menuDetail/MenuDetailFragment.kt | 23 ++- 2 files changed, 107 insertions(+), 54 deletions(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt index 7d54de06..2e1d4092 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt @@ -39,22 +39,20 @@ import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel -import androidx.navigation.NavController import androidx.paging.compose.LazyPagingItems import androidx.paging.compose.collectAsLazyPagingItems import com.wafflestudio.siksha2.R import com.wafflestudio.siksha2.components.compose.ErrorPlaceHolder import com.wafflestudio.siksha2.components.compose.LoadingPlaceHolder +import com.wafflestudio.siksha2.components.compose.menuDetail.LikeButton import com.wafflestudio.siksha2.components.compose.menuDetail.MenuRatingBars import com.wafflestudio.siksha2.components.compose.menuDetail.MenuRatingStars import com.wafflestudio.siksha2.components.compose.menuDetail.MenuReview import com.wafflestudio.siksha2.components.compose.menuDetail.MenuReviewImage -import com.wafflestudio.siksha2.components.compose.menuDetail.LikeButton import com.wafflestudio.siksha2.components.compose.menuDetail.MenuReviewImageShowMore import com.wafflestudio.siksha2.models.Menu import com.wafflestudio.siksha2.models.Review import com.wafflestudio.siksha2.ui.SikshaColors -import com.wafflestudio.siksha2.ui.menuDetail.MenuDetailFragmentDirections import com.wafflestudio.siksha2.ui.menuDetail.MenuDetailViewModel import com.wafflestudio.siksha2.ui.menuDetail.MenuLoadingState import com.wafflestudio.siksha2.utils.dpToSp @@ -62,23 +60,59 @@ import kotlin.math.min import kotlin.math.round @Composable -fun MenuDetailScreen( - navController: NavController, +fun MenuDetailRoute( menuId: Long, isTodayMenu: Boolean, + onNavigateUp: () -> Unit, + onNavigateToLeaveReview: () -> Unit, + onNavigateToReviewPhoto: (Long) -> Unit, + onNavigateToReview: (Long) -> Unit, modifier: Modifier = Modifier, menuDetailViewModel: MenuDetailViewModel = hiltViewModel() ) { - val menu by menuDetailViewModel.menu.observeAsState() + val menu by menuDetailViewModel.menu.observeAsState() // todo: LiveData대신 StateFlow 써서 non-null로 만들기 + val reviewDistribution by menuDetailViewModel.reviewDistribution.observeAsState() val reviews = menuDetailViewModel.reviews.collectAsLazyPagingItems() val imageReviews = menuDetailViewModel.reviewsWithImage.collectAsLazyPagingItems() - val loadingState = menuDetailViewModel.networkResultMenuLoadingState.observeAsState() + val loadingState by menuDetailViewModel.networkResultMenuLoadingState.observeAsState() LaunchedEffect(Unit) { menuDetailViewModel.refreshMenu(menuId) menuDetailViewModel.refreshReviewDistribution(menuId) } + MenuDetailScreen( + menu = menu, + reviewDistribution = reviewDistribution, + reviews = reviews, + imageReviews = imageReviews, + loadingState = loadingState, + isTodayMenu = isTodayMenu, + onClickLike = { menuDetailViewModel.toggleLike() }, + onNavigateUp = onNavigateUp, + onNavigateToLeaveReview = onNavigateToLeaveReview, + onNavigateToReviewPhoto = onNavigateToReviewPhoto, + onNavigateToReview = onNavigateToReview, + modifier = modifier, + ) +} + +@Composable +fun MenuDetailScreen( + menu: Menu?, + reviewDistribution: List?, + reviews: LazyPagingItems, + imageReviews: LazyPagingItems, + loadingState: MenuLoadingState?, + isTodayMenu: Boolean, + onClickLike: () -> Unit, + onNavigateUp: () -> Unit, + onNavigateToLeaveReview: () -> Unit, + onNavigateToReviewPhoto: (Long) -> Unit, + onNavigateToReview: (Long) -> Unit, + modifier: Modifier = Modifier, +) { + Column( modifier = modifier.fillMaxSize() ) { @@ -95,7 +129,7 @@ fun MenuDetailScreen( .padding(horizontal = 20.dp, vertical = 16.dp) .align(Alignment.CenterStart) .clickable { - navController.popBackStack() + onNavigateUp() } ) Text( @@ -112,18 +146,21 @@ fun MenuDetailScreen( ) } - when (loadingState.value) { + when (loadingState) { MenuLoadingState.SUCCESS -> { MenuDetailContent( - menuId, - menu, - reviews, - imageReviews, - isTodayMenu, - menuDetailViewModel, - navController + menu = menu, + reviewDistribution = reviewDistribution, + reviews = reviews, + imageReviews = imageReviews, + isTodayMenu = isTodayMenu, + onClickLike = onClickLike, + onNavigateToLeaveReview = onNavigateToLeaveReview, + onNavigateToReviewPhoto = onNavigateToReviewPhoto, + onNavigateToReview = onNavigateToReview ) } + MenuLoadingState.LOADING -> { LoadingPlaceHolder( modifier = Modifier @@ -131,6 +168,7 @@ fun MenuDetailScreen( .weight(1f) ) } + MenuLoadingState.FAILED -> { ErrorPlaceHolder( modifier = Modifier @@ -138,6 +176,7 @@ fun MenuDetailScreen( .weight(1f) ) } + else -> {} } } @@ -145,13 +184,15 @@ fun MenuDetailScreen( @Composable fun MenuDetailContent( - menuId: Long, menu: Menu?, + reviewDistribution: List?, reviews: LazyPagingItems, imageReviews: LazyPagingItems, isTodayMenu: Boolean, - menuDetailViewModel: MenuDetailViewModel, - navController: NavController, + onClickLike: () -> Unit, + onNavigateToLeaveReview: () -> Unit, + onNavigateToReviewPhoto: (Long) -> Unit, + onNavigateToReview: (Long) -> Unit, modifier: Modifier = Modifier ) { val context = LocalContext.current @@ -163,14 +204,13 @@ fun MenuDetailContent( // 상단 별점 정보 + a item { MenuStatistics( - menu, - reviews, - menuDetailViewModel, - { + menu = menu, + reviewDistribution = reviewDistribution, + reviews = reviews, + onClickLike = onClickLike, + onLeaveReview = { if (isTodayMenu) { - navController.navigate( - MenuDetailFragmentDirections.actionMenuDetailFragmentToLeaveReviewFragment() - ) + onNavigateToLeaveReview() } else { Toast .makeText( @@ -188,9 +228,9 @@ fun MenuDetailContent( if (imageReviews.itemCount > 0) { item { MenuPhotoPreview( - menuId, - imageReviews, - navController + menu = menu, + imageReviews = imageReviews, + onNavigateToReviewPhoto = onNavigateToReviewPhoto ) } } @@ -218,11 +258,9 @@ fun MenuDetailContent( .align(Alignment.CenterEnd) .rotate(180f) .clickable { - navController.navigate( - MenuDetailFragmentDirections.actionMenuDetailFragmentToReviewFragment( - menuId - ) - ) + menu?.let { + onNavigateToReview(it.id) + } } ) } @@ -261,8 +299,9 @@ fun MenuDetailContent( @Composable fun MenuStatistics( menu: Menu?, + reviewDistribution: List?, reviews: LazyPagingItems, - menuDetailViewModel: MenuDetailViewModel, + onClickLike: () -> Unit, onLeaveReview: () -> Unit, modifier: Modifier = Modifier ) { @@ -278,7 +317,7 @@ fun MenuStatistics( ) { LikeButton( isChecked = menu?.isLiked ?: false, - onClick = { menuDetailViewModel.toggleLike() }, + onClick = onClickLike, modifier = Modifier.size(21.dp) ) Text( @@ -348,7 +387,7 @@ fun MenuStatistics( ) { Text( text = "${ - menu?.score?.times(10)?.let { round(it) / 10 } ?: "0.0" + menu?.score?.times(10)?.let { round(it) / 10 } ?: "0.0" }", fontSize = dpToSp(32.dp), fontWeight = FontWeight.ExtraBold @@ -357,7 +396,7 @@ fun MenuStatistics( rating = menu?.score?.toFloat() ?: 0.0f ) } - menuDetailViewModel.reviewDistribution.value?.let { + reviewDistribution?.let { MenuRatingBars( distributions = it, modifier = Modifier.weight(1f) @@ -398,10 +437,10 @@ fun MenuStatistics( } @Composable -fun MenuPhotoPreview( - menuId: Long, +fun MenuPhotoPreview( // TODO: 네이밍 변경 + menu: Menu?, imageReviews: LazyPagingItems, - navController: NavController, + onNavigateToReviewPhoto: (Long) -> Unit, modifier: Modifier = Modifier ) { val imagePreviewScrollState = rememberScrollState() @@ -425,11 +464,9 @@ fun MenuPhotoPreview( .align(Alignment.CenterEnd) .rotate(180f) .clickable { - navController.navigate( - MenuDetailFragmentDirections.actionMenuDetailFragmentToReviewPhotoFragment( - menuId - ) - ) + menu?.let { + onNavigateToReviewPhoto(it.id) + } } ) } @@ -447,6 +484,7 @@ fun MenuPhotoPreview( .background(SikshaColors.Gray100) .clip(RoundedCornerShape(10.dp)) ) + else -> { if (i == 3) { MenuReviewImageShowMore( @@ -456,11 +494,9 @@ fun MenuPhotoPreview( .clip(RoundedCornerShape(10.dp)), showMoreCount = imageReviews.itemCount - 2, onShowMore = { - navController.navigate( - MenuDetailFragmentDirections.actionMenuDetailFragmentToReviewPhotoFragment( - menuId - ) - ) + menu?.let { + onNavigateToReviewPhoto(it.id) + } } ) } else { diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt index 20bdb119..4b415997 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt @@ -8,7 +8,7 @@ import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.navArgs -import com.wafflestudio.siksha2.compose.ui.menuDetail.MenuDetailScreen +import com.wafflestudio.siksha2.compose.ui.menuDetail.MenuDetailRoute import com.wafflestudio.siksha2.databinding.FragmentMenuDetailBinding import com.wafflestudio.siksha2.ui.SikshaTheme import dagger.hilt.android.AndroidEntryPoint @@ -33,10 +33,27 @@ class MenuDetailFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { binding.menuDetailComposeView.setContent { SikshaTheme { - MenuDetailScreen( - navController = findNavController(), + MenuDetailRoute( menuId = args.menuId, isTodayMenu = args.isTodayMenu, + onNavigateUp = { + findNavController().popBackStack() + }, + onNavigateToLeaveReview = { + findNavController().navigate( + MenuDetailFragmentDirections.actionMenuDetailFragmentToLeaveReviewFragment() // TODO: leaveReviewFragment로 이동 시 menuId arguement 전달하는 식으로 바꾸기 + ) + }, + onNavigateToReviewPhoto = { menuId -> + findNavController().navigate( + MenuDetailFragmentDirections.actionMenuDetailFragmentToReviewPhotoFragment(menuId) + ) + }, + onNavigateToReview = { menuId -> + findNavController().navigate( + MenuDetailFragmentDirections.actionMenuDetailFragmentToReviewFragment(menuId) + ) + }, menuDetailViewModel = vm ) } From bd162b52fe387633cbcd5b372db746a7fa22792f Mon Sep 17 00:00:00 2001 From: eastshine2741 Date: Fri, 26 Jul 2024 22:29:17 +0900 Subject: [PATCH 60/68] =?UTF-8?q?MenuPhotoPreview=20->=20BriefImageReviews?= =?UTF-8?q?=20=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../siksha2/compose/ui/menuDetail/MenuDetailScreen.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt index 2e1d4092..fded2490 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt @@ -437,7 +437,7 @@ fun MenuStatistics( } @Composable -fun MenuPhotoPreview( // TODO: 네이밍 변경 +fun BriefImageReviews( menu: Menu?, imageReviews: LazyPagingItems, onNavigateToReviewPhoto: (Long) -> Unit, From b57c323eef1c330c4ec49d99a9a58a75d6185a4b Mon Sep 17 00:00:00 2001 From: eastshine2741 Date: Fri, 26 Jul 2024 22:29:53 +0900 Subject: [PATCH 61/68] =?UTF-8?q?MenuDetailScreenPreview=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 세부 컴포저블에도 preview 추가 필요 --- .../compose/ui/menuDetail/MenuDetailScreen.kt | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt index fded2490..46eb7841 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt @@ -37,8 +37,10 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign 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 androidx.paging.PagingData import androidx.paging.compose.LazyPagingItems import androidx.paging.compose.collectAsLazyPagingItems import com.wafflestudio.siksha2.R @@ -50,12 +52,16 @@ import com.wafflestudio.siksha2.components.compose.menuDetail.MenuRatingStars import com.wafflestudio.siksha2.components.compose.menuDetail.MenuReview import com.wafflestudio.siksha2.components.compose.menuDetail.MenuReviewImage import com.wafflestudio.siksha2.components.compose.menuDetail.MenuReviewImageShowMore +import com.wafflestudio.siksha2.models.MealsOfDay import com.wafflestudio.siksha2.models.Menu import com.wafflestudio.siksha2.models.Review import com.wafflestudio.siksha2.ui.SikshaColors +import com.wafflestudio.siksha2.ui.SikshaTheme import com.wafflestudio.siksha2.ui.menuDetail.MenuDetailViewModel import com.wafflestudio.siksha2.ui.menuDetail.MenuLoadingState import com.wafflestudio.siksha2.utils.dpToSp +import kotlinx.coroutines.flow.flowOf +import java.time.LocalDate import kotlin.math.min import kotlin.math.round @@ -227,7 +233,7 @@ fun MenuDetailContent( // 사진 리뷰 if (imageReviews.itemCount > 0) { item { - MenuPhotoPreview( + BriefImageReviews( menu = menu, imageReviews = imageReviews, onNavigateToReviewPhoto = onNavigateToReviewPhoto @@ -512,3 +518,40 @@ fun BriefImageReviews( } } } + +private val testMenu = Menu( + id = 0L, + code = "", + date = LocalDate.now(), + type = MealsOfDay.BR, + restaurantId = 0L, + nameKr = "nameKr", + nameEn = "nameEn", + price = 10000L, + score = 3.39, + etc = listOf("https://picsum.photos/200", "https://picsum.photos/201"), + reviewCount = 10L, + isLiked = true, + likeCount = 100L, +) + +@Preview +@Composable +fun MenuDetailScreenPreview() { + SikshaTheme { + MenuDetailScreen( + menu = testMenu, + reviewDistribution = listOf(1L, 2L, 3L, 4L, 5L), + reviews = flowOf(PagingData.empty()).collectAsLazyPagingItems(), + imageReviews = flowOf(PagingData.empty()).collectAsLazyPagingItems(), + loadingState = MenuLoadingState.SUCCESS, + isTodayMenu = true, + onClickLike = {}, + onNavigateUp = {}, + onNavigateToLeaveReview = {}, + onNavigateToReviewPhoto = {}, + onNavigateToReview = {}, + modifier = Modifier + ) + } +} From ddb90764ca5c8a415acdc8392eb3e9acf8674b6c Mon Sep 17 00:00:00 2001 From: eastshine2741 Date: Fri, 26 Jul 2024 22:57:21 +0900 Subject: [PATCH 62/68] =?UTF-8?q?MenuDetailScreen=20TopBar=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../siksha2/components/compose/TopBar.kt | 5 +- .../compose/ui/menuDetail/MenuDetailScreen.kt | 51 ++++++++----------- 2 files changed, 23 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/components/compose/TopBar.kt b/app/src/main/java/com/wafflestudio/siksha2/components/compose/TopBar.kt index 1100c18d..e3e5b988 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/components/compose/TopBar.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/components/compose/TopBar.kt @@ -10,15 +10,16 @@ import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import com.wafflestudio.siksha2.ui.SikshaColors -import com.wafflestudio.siksha2.ui.SikshaTypography @Composable fun TopBar( title: String, modifier: Modifier = Modifier, + textStyle: TextStyle = MaterialTheme.typography.subtitle1, navigationButton: @Composable () -> Unit = {} ) { Box( @@ -32,7 +33,7 @@ fun TopBar( modifier = Modifier.align(Alignment.Center), color = SikshaColors.White900, fontWeight = FontWeight.ExtraBold, - style = SikshaTypography.subtitle1 + style = textStyle ) Box( modifier = Modifier diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt index 3bd00c52..243c1b4f 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt @@ -21,6 +21,7 @@ import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.Divider +import androidx.compose.material.MaterialTheme import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect @@ -32,11 +33,10 @@ import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.rotate import androidx.compose.ui.graphics.ColorFilter import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight -import androidx.compose.ui.text.style.TextAlign -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 @@ -46,6 +46,7 @@ import androidx.paging.compose.collectAsLazyPagingItems import com.wafflestudio.siksha2.R import com.wafflestudio.siksha2.components.compose.ErrorPlaceHolder import com.wafflestudio.siksha2.components.compose.LoadingPlaceHolder +import com.wafflestudio.siksha2.components.compose.TopBar import com.wafflestudio.siksha2.components.compose.menuDetail.LikeButton import com.wafflestudio.siksha2.components.compose.menuDetail.MenuRatingBars import com.wafflestudio.siksha2.components.compose.menuDetail.MenuRatingStars @@ -126,35 +127,23 @@ fun MenuDetailScreen( Column( modifier = modifier.fillMaxSize() ) { - Box( - modifier = Modifier - .fillMaxWidth() - .height(56.dp) - .background(color = SikshaColors.OrangeMain) - ) { - Image( - painter = painterResource(R.drawable.ic_back_arrow), - contentDescription = "뒤로가기", - modifier = Modifier - .padding(horizontal = 20.dp, vertical = 16.dp) - .align(Alignment.CenterStart) - .clickable { - onNavigateUp() - } - ) - Text( - text = menu?.nameKr ?: stringResource(R.string.review_title), - modifier = Modifier - .padding(horizontal = 10.dp, vertical = 12.dp) - .fillMaxWidth(0.72f) - .align(Alignment.Center), - fontSize = dpToSp(20.dp), - fontWeight = FontWeight.Bold, - overflow = TextOverflow.Ellipsis, - textAlign = TextAlign.Center, - color = SikshaColors.White900 - ) - } + TopBar( + title = menu?.nameKr ?: stringResource(R.string.review_title), + textStyle = MaterialTheme.typography.subtitle1.copy( + fontSize = with(LocalDensity.current) { 20.dp.toSp() }, + ), + navigationButton = { + Image( + painter = painterResource(R.drawable.ic_back_arrow), + contentDescription = "뒤로가기", + modifier = Modifier + .size(16.dp) + .clickable { + onNavigateUp() + } + ) + } + ) when (loadingState) { MenuLoadingState.SUCCESS -> { From d8cdebdd8bda4fad8df34d66e6836820a806bacc Mon Sep 17 00:00:00 2001 From: eastshine2741 Date: Fri, 26 Jul 2024 23:24:32 +0900 Subject: [PATCH 63/68] =?UTF-8?q?dpToSp=20=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../siksha2/compose/ui/menuDetail/MenuDetailScreen.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt index 243c1b4f..d771e925 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt @@ -33,7 +33,6 @@ import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.rotate import androidx.compose.ui.graphics.ColorFilter import androidx.compose.ui.platform.LocalContext -import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight @@ -130,7 +129,7 @@ fun MenuDetailScreen( TopBar( title = menu?.nameKr ?: stringResource(R.string.review_title), textStyle = MaterialTheme.typography.subtitle1.copy( - fontSize = with(LocalDensity.current) { 20.dp.toSp() }, + fontSize = dpToSp(20.dp), ), navigationButton = { Image( From 503d2d9bd64693ecafd63ecfd15a116ec11b85f5 Mon Sep 17 00:00:00 2001 From: eastshine2741 Date: Fri, 26 Jul 2024 23:26:11 +0900 Subject: [PATCH 64/68] =?UTF-8?q?Review=20Route=20Screen=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/menuDetail/review/ReviewScreen.kt | 26 +++++++++++++++---- .../ui/menuDetail/review/ReviewFragment.kt | 10 +++---- .../menuDetail/review/ReviewPhotoFragment.kt | 8 +++--- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt index 6232883e..d30ddcc4 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt @@ -20,20 +20,21 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel -import androidx.navigation.NavController +import androidx.paging.compose.LazyPagingItems import androidx.paging.compose.collectAsLazyPagingItems import com.wafflestudio.siksha2.R import com.wafflestudio.siksha2.components.compose.menuDetail.MenuReview +import com.wafflestudio.siksha2.models.Review import com.wafflestudio.siksha2.ui.SikshaColors import com.wafflestudio.siksha2.ui.menuDetail.MenuDetailViewModel import com.wafflestudio.siksha2.utils.dpToSp @Composable -fun ReviewScreen( - navController: NavController, +fun ReviewRoute( + showImages: Boolean, + onNavigateUp: () -> Unit, modifier: Modifier = Modifier, menuDetailViewModel: MenuDetailViewModel = hiltViewModel(), - showImages: Boolean = false ) { val reviews = if (!showImages) { menuDetailViewModel.reviews.collectAsLazyPagingItems() @@ -41,6 +42,21 @@ fun ReviewScreen( menuDetailViewModel.reviewsWithImage.collectAsLazyPagingItems() } + ReviewScreen( + showImages = showImages, + reviews = reviews, + onNavigateUp = onNavigateUp, + modifier = modifier, + ) +} + +@Composable +fun ReviewScreen( + showImages: Boolean, + reviews: LazyPagingItems, + onNavigateUp: () -> Unit, + modifier: Modifier = Modifier, +) { Column( modifier = modifier.fillMaxSize() ) { @@ -58,7 +74,7 @@ fun ReviewScreen( .padding(horizontal = 20.dp, vertical = 16.dp) .align(Alignment.CenterStart) .clickable { - navController.popBackStack() + onNavigateUp() } ) Text( diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt index b178765b..5bcfcb4a 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt @@ -7,7 +7,7 @@ import android.view.ViewGroup import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels import androidx.navigation.fragment.findNavController -import com.wafflestudio.siksha2.compose.ui.menuDetail.review.ReviewScreen +import com.wafflestudio.siksha2.compose.ui.menuDetail.review.ReviewRoute import com.wafflestudio.siksha2.databinding.FragmentReviewBinding import com.wafflestudio.siksha2.ui.SikshaTheme import com.wafflestudio.siksha2.ui.menuDetail.MenuDetailViewModel @@ -30,10 +30,10 @@ class ReviewFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { binding.reviewComposeView.setContent { SikshaTheme { - ReviewScreen( - navController = findNavController(), - showImages = false, - menuDetailViewModel = vm + ReviewRoute( + showImages = true, + onNavigateUp = { findNavController().popBackStack() }, + menuDetailViewModel = vm, ) } } diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewPhotoFragment.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewPhotoFragment.kt index 8a828378..2ce58551 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewPhotoFragment.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewPhotoFragment.kt @@ -7,7 +7,7 @@ import android.view.ViewGroup import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels import androidx.navigation.fragment.findNavController -import com.wafflestudio.siksha2.compose.ui.menuDetail.review.ReviewScreen +import com.wafflestudio.siksha2.compose.ui.menuDetail.review.ReviewRoute import com.wafflestudio.siksha2.databinding.FragmentReviewPhotoBinding import com.wafflestudio.siksha2.ui.SikshaTheme import com.wafflestudio.siksha2.ui.menuDetail.MenuDetailViewModel @@ -29,10 +29,10 @@ class ReviewPhotoFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { binding.reviewPhotoComposeView.setContent { SikshaTheme { - ReviewScreen( - navController = findNavController(), + ReviewRoute( showImages = true, - menuDetailViewModel = vm + onNavigateUp = { findNavController().popBackStack() }, + menuDetailViewModel = vm, ) } } From 170dfcfd052633824170717f83eebc6e26717739 Mon Sep 17 00:00:00 2001 From: eastshine2741 Date: Fri, 26 Jul 2024 23:30:55 +0900 Subject: [PATCH 65/68] =?UTF-8?q?ReviewScreen=20TopBar=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/menuDetail/review/ReviewScreen.kt | 43 ++++++++----------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt index d30ddcc4..84e1fbb4 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt @@ -11,6 +11,7 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.material.MaterialTheme import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment @@ -23,6 +24,7 @@ import androidx.hilt.navigation.compose.hiltViewModel import androidx.paging.compose.LazyPagingItems import androidx.paging.compose.collectAsLazyPagingItems import com.wafflestudio.siksha2.R +import com.wafflestudio.siksha2.components.compose.TopBar import com.wafflestudio.siksha2.components.compose.menuDetail.MenuReview import com.wafflestudio.siksha2.models.Review import com.wafflestudio.siksha2.ui.SikshaColors @@ -60,33 +62,22 @@ fun ReviewScreen( Column( modifier = modifier.fillMaxSize() ) { - // TODO: 커뮤니티탭 머지 후 TopBar로 수정 - Box( - modifier = Modifier - .fillMaxWidth() - .height(56.dp) - .background(color = SikshaColors.OrangeMain) - ) { - Image( - painter = painterResource(R.drawable.ic_back_arrow), - contentDescription = "뒤로가기", - modifier = Modifier - .padding(horizontal = 20.dp, vertical = 16.dp) - .align(Alignment.CenterStart) - .clickable { - onNavigateUp() - } - ) - Text( - text = stringResource(R.string.review_title), - modifier = Modifier - .padding(horizontal = 10.dp, vertical = 12.dp) - .align(Alignment.Center), + TopBar( + title = stringResource(R.string.review_title), + textStyle = MaterialTheme.typography.subtitle1.copy( fontSize = dpToSp(20.dp), - fontWeight = FontWeight.Bold, - color = SikshaColors.White900 - ) - } + ), + navigationButton = { + Image( + painter = painterResource(R.drawable.ic_back_arrow), + contentDescription = "뒤로가기", + modifier = Modifier + .clickable { + onNavigateUp() + } + ) + } + ) Box( modifier = Modifier From 4c8c21661fb9e500e7b2db9ad627a6e4630f9ca4 Mon Sep 17 00:00:00 2001 From: eastshine2741 Date: Fri, 26 Jul 2024 23:34:20 +0900 Subject: [PATCH 66/68] =?UTF-8?q?Preview=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 리뷰 존재하는 케이스 등 여러 케이스 preview 추가 필요 --- .../ui/menuDetail/review/ReviewScreen.kt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt index 84e1fbb4..86d32286 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt @@ -19,17 +19,22 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel +import androidx.paging.PagingData import androidx.paging.compose.LazyPagingItems import androidx.paging.compose.collectAsLazyPagingItems import com.wafflestudio.siksha2.R import com.wafflestudio.siksha2.components.compose.TopBar import com.wafflestudio.siksha2.components.compose.menuDetail.MenuReview +import com.wafflestudio.siksha2.models.Comment import com.wafflestudio.siksha2.models.Review import com.wafflestudio.siksha2.ui.SikshaColors +import com.wafflestudio.siksha2.ui.SikshaTheme import com.wafflestudio.siksha2.ui.menuDetail.MenuDetailViewModel import com.wafflestudio.siksha2.utils.dpToSp +import kotlinx.coroutines.flow.flowOf @Composable fun ReviewRoute( @@ -120,3 +125,15 @@ fun ReviewScreen( } } } + +@Preview(showBackground = true) +@Composable +fun ReviewScreenPreview() { + SikshaTheme { + ReviewScreen( + showImages = false, + reviews = flowOf(PagingData.empty()).collectAsLazyPagingItems(), + onNavigateUp = {} + ) + } +} From 8abbabefd4498170d1afc709fb5da32e2144b3a7 Mon Sep 17 00:00:00 2001 From: eastshine2741 Date: Fri, 26 Jul 2024 23:37:19 +0900 Subject: [PATCH 67/68] =?UTF-8?q?layout=20xml=20=EB=B6=88=ED=95=84?= =?UTF-8?q?=EC=9A=94=20=EC=A3=BC=EC=84=9D=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/res/layout/fragment_menu_detail.xml | 491 ------------------ app/src/main/res/layout/fragment_review.xml | 64 --- .../main/res/layout/fragment_review_photo.xml | 64 --- 3 files changed, 619 deletions(-) diff --git a/app/src/main/res/layout/fragment_menu_detail.xml b/app/src/main/res/layout/fragment_menu_detail.xml index 87352b0b..0bd421a8 100644 --- a/app/src/main/res/layout/fragment_menu_detail.xml +++ b/app/src/main/res/layout/fragment_menu_detail.xml @@ -8,497 +8,6 @@ android:orientation="vertical" tools:context=".ui.menuDetail.MenuDetailFragment"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Date: Fri, 26 Jul 2024 23:37:58 +0900 Subject: [PATCH 68/68] lint --- .../compose/ui/menuDetail/MenuDetailScreen.kt | 15 +++++++-------- .../compose/ui/menuDetail/review/ReviewScreen.kt | 9 ++++----- .../siksha2/ui/menuDetail/MenuDetailFragment.kt | 2 +- .../ui/menuDetail/review/ReviewFragment.kt | 2 +- .../ui/menuDetail/review/ReviewPhotoFragment.kt | 2 +- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt index d771e925..c29a7802 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/MenuDetailScreen.kt @@ -76,7 +76,7 @@ fun MenuDetailRoute( modifier: Modifier = Modifier, menuDetailViewModel: MenuDetailViewModel = hiltViewModel() ) { - val menu by menuDetailViewModel.menu.observeAsState() // todo: LiveData대신 StateFlow 써서 non-null로 만들기 + val menu by menuDetailViewModel.menu.observeAsState() // todo: LiveData대신 StateFlow 써서 non-null로 만들기 val reviewDistribution by menuDetailViewModel.reviewDistribution.observeAsState() val reviews = menuDetailViewModel.reviews.collectAsLazyPagingItems() val imageReviews = menuDetailViewModel.reviewsWithImage.collectAsLazyPagingItems() @@ -96,14 +96,14 @@ fun MenuDetailRoute( isTodayMenu = isTodayMenu, onClickLike = { menu?.let { - menuDetailViewModel.toggleLike(it.id, it.isLiked ?: false) // todo: model, dto 구분하고 isLiked not-null로 만들기 + menuDetailViewModel.toggleLike(it.id, it.isLiked ?: false) // todo: model, dto 구분하고 isLiked not-null로 만들기 } }, onNavigateUp = onNavigateUp, onNavigateToLeaveReview = onNavigateToLeaveReview, onNavigateToReviewPhoto = onNavigateToReviewPhoto, onNavigateToReview = onNavigateToReview, - modifier = modifier, + modifier = modifier ) } @@ -120,16 +120,15 @@ fun MenuDetailScreen( onNavigateToLeaveReview: () -> Unit, onNavigateToReviewPhoto: (Long) -> Unit, onNavigateToReview: (Long) -> Unit, - modifier: Modifier = Modifier, + modifier: Modifier = Modifier ) { - Column( modifier = modifier.fillMaxSize() ) { TopBar( title = menu?.nameKr ?: stringResource(R.string.review_title), textStyle = MaterialTheme.typography.subtitle1.copy( - fontSize = dpToSp(20.dp), + fontSize = dpToSp(20.dp) ), navigationButton = { Image( @@ -385,7 +384,7 @@ fun MenuStatistics( ) { Text( text = "${ - menu?.score?.times(10)?.let { round(it) / 10 } ?: "0.0" + menu?.score?.times(10)?.let { round(it) / 10 } ?: "0.0" }", fontSize = dpToSp(32.dp), fontWeight = FontWeight.ExtraBold @@ -524,7 +523,7 @@ private val testMenu = Menu( etc = listOf("https://picsum.photos/200", "https://picsum.photos/201"), reviewCount = 10L, isLiked = true, - likeCount = 100L, + likeCount = 100L ) @Preview diff --git a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt index 86d32286..97940ced 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/compose/ui/menuDetail/review/ReviewScreen.kt @@ -28,7 +28,6 @@ import androidx.paging.compose.collectAsLazyPagingItems import com.wafflestudio.siksha2.R import com.wafflestudio.siksha2.components.compose.TopBar import com.wafflestudio.siksha2.components.compose.menuDetail.MenuReview -import com.wafflestudio.siksha2.models.Comment import com.wafflestudio.siksha2.models.Review import com.wafflestudio.siksha2.ui.SikshaColors import com.wafflestudio.siksha2.ui.SikshaTheme @@ -41,7 +40,7 @@ fun ReviewRoute( showImages: Boolean, onNavigateUp: () -> Unit, modifier: Modifier = Modifier, - menuDetailViewModel: MenuDetailViewModel = hiltViewModel(), + menuDetailViewModel: MenuDetailViewModel = hiltViewModel() ) { val reviews = if (!showImages) { menuDetailViewModel.reviews.collectAsLazyPagingItems() @@ -53,7 +52,7 @@ fun ReviewRoute( showImages = showImages, reviews = reviews, onNavigateUp = onNavigateUp, - modifier = modifier, + modifier = modifier ) } @@ -62,7 +61,7 @@ fun ReviewScreen( showImages: Boolean, reviews: LazyPagingItems, onNavigateUp: () -> Unit, - modifier: Modifier = Modifier, + modifier: Modifier = Modifier ) { Column( modifier = modifier.fillMaxSize() @@ -70,7 +69,7 @@ fun ReviewScreen( TopBar( title = stringResource(R.string.review_title), textStyle = MaterialTheme.typography.subtitle1.copy( - fontSize = dpToSp(20.dp), + fontSize = dpToSp(20.dp) ), navigationButton = { Image( diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt index 4b415997..8562cdce 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/MenuDetailFragment.kt @@ -41,7 +41,7 @@ class MenuDetailFragment : Fragment() { }, onNavigateToLeaveReview = { findNavController().navigate( - MenuDetailFragmentDirections.actionMenuDetailFragmentToLeaveReviewFragment() // TODO: leaveReviewFragment로 이동 시 menuId arguement 전달하는 식으로 바꾸기 + MenuDetailFragmentDirections.actionMenuDetailFragmentToLeaveReviewFragment() // TODO: leaveReviewFragment로 이동 시 menuId arguement 전달하는 식으로 바꾸기 ) }, onNavigateToReviewPhoto = { menuId -> diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt index 5bcfcb4a..643eb8d0 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewFragment.kt @@ -33,7 +33,7 @@ class ReviewFragment : Fragment() { ReviewRoute( showImages = true, onNavigateUp = { findNavController().popBackStack() }, - menuDetailViewModel = vm, + menuDetailViewModel = vm ) } } diff --git a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewPhotoFragment.kt b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewPhotoFragment.kt index 2ce58551..885416b5 100644 --- a/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewPhotoFragment.kt +++ b/app/src/main/java/com/wafflestudio/siksha2/ui/menuDetail/review/ReviewPhotoFragment.kt @@ -32,7 +32,7 @@ class ReviewPhotoFragment : Fragment() { ReviewRoute( showImages = true, onNavigateUp = { findNavController().popBackStack() }, - menuDetailViewModel = vm, + menuDetailViewModel = vm ) } }