Skip to content

Commit

Permalink
[feat/login]: 식당 리뷰 화면 최적화
Browse files Browse the repository at this point in the history
  • Loading branch information
kez-lab committed Feb 16, 2024
1 parent 51851f9 commit 64d4fcd
Show file tree
Hide file tree
Showing 13 changed files with 370 additions and 206 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import javax.inject.Inject
class PostReviewUseCase @Inject constructor(
private val reviewRepository: ReviewRepository
) {
suspend operator fun invoke(userReview: UserReview) {
reviewRepository.postReview(userReview)
}
suspend operator fun invoke(userReview: UserReview) = reviewRepository.postReview(userReview)

}
1 change: 1 addition & 0 deletions presentation/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
id("dagger.hilt.android.plugin")
id("kotlin-android")
id("kotlin-kapt")
id("kotlin-parcelize")
}

android {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.everymeal.presentation.model

import android.os.Parcelable
import kotlinx.parcelize.Parcelize

@Parcelize
data class Restaurant(
val idx: Int,
val name: String,
val address: String,
val phoneNumber: String,
val categoryDetail: String,
val distance: Int,
val grade: Float,
val reviewCount: Int,
val recommendedCount: Int,
val images: List<String>?,
val isLiked: Boolean
) : Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ enum class EveryMealRoute(val route: String) {
DETAIL_RESTAURANT("detail-restaurant"),
SCHOOL_AUTH("school-auth"),
PROFILE_GENERATE("profile_generate?emailAuthValue={emailAuthValue}&emailAuthToken={emailAuthToken}"),
SIGN_UP_SUCCESS("sign-up-success"),
WITH_DRAW("with-draw"),
REVIEW_SEARCH("review-search"),
REVIEW("review"),
REVIEW_WRITE("review-write"),
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavBackStackEntry
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
Expand All @@ -23,12 +26,16 @@ import com.everymeal.presentation.ui.home.HomeScreen
import com.everymeal.presentation.ui.mypage.MyPageScreen
import com.everymeal.presentation.ui.profile.ProfileGenerateScreen
import com.everymeal.presentation.ui.restaurant.DetailRestaurantScreen
import com.everymeal.presentation.ui.review.ReviewScreen
import com.everymeal.presentation.ui.review.ReviewViewModel
import com.everymeal.presentation.ui.review.search.ReviewSearchScreen
import com.everymeal.presentation.ui.review.write.ReviewWriteScreen
import com.everymeal.presentation.ui.search.SearchScreen
import com.everymeal.presentation.ui.signup.school.SchoolAuthScreen
import com.everymeal.presentation.ui.univfood.UnivFoodScreen
import com.everymeal.presentation.ui.whatfood.WhatFoodScreen
import com.everymeal.presentation.ui.withdraw.WithDrawScreen
import com.everymeal.presentation.util.sharedViewModel

const val DETAIL_SCREEN_TYPE = "detailScreenType"
const val DETAIL_RESTAURANT_IDX = "detailRestaurantIdx"
Expand Down Expand Up @@ -133,6 +140,21 @@ fun MainScreen(
composable(route = EveryMealRoute.REVIEW_SEARCH.route) {
ReviewSearchScreen(navController = navController)
}
composable(route = EveryMealRoute.REVIEW.route.plus("/{$DETAIL_RESTAURANT_IDX}")) { navBackStackEntry ->
val argument = navBackStackEntry.arguments
val restaurantIdx = argument?.getString(DETAIL_RESTAURANT_IDX).orEmpty()
val viewModel = navBackStackEntry.sharedViewModel<ReviewViewModel>(
navController = navController,
navGraphRoute = EveryMealRoute.HOME.route
)
ReviewScreen(
viewModel = viewModel,
restaurantIdx = restaurantIdx,
moveReviewWriteScreen = {
navController.navigate(EveryMealRoute.REVIEW_WRITE.route)
}
)
}
composable(route = EveryMealRoute.WITH_DRAW.route) {
WithDrawScreen(
onBackClick = {
Expand All @@ -141,7 +163,17 @@ fun MainScreen(
)
}
composable(route = EveryMealRoute.SEARCH.route) {
SearchScreen(navController = navController)
SearchScreen(
moveReviewScreen = { restaurantIdx ->
navController.navigate(EveryMealRoute.REVIEW.route.plus("/$restaurantIdx"))
})
}
composable(route = EveryMealRoute.REVIEW_WRITE.route) { navBackStackEntry ->
val viewModel = navBackStackEntry.sharedViewModel<ReviewViewModel>(
navController = navController,
navGraphRoute = EveryMealRoute.HOME.route
)
ReviewWriteScreen(viewModel = viewModel)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.everymeal.presentation.ui.review

import android.util.Log
import android.widget.Toast
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.PickVisualMediaRequest
import androidx.activity.result.contract.ActivityResultContracts
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.ColumnScope
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.LazyRow
Expand All @@ -30,7 +29,6 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
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
Expand All @@ -42,24 +40,22 @@ import androidx.compose.ui.unit.sp
import androidx.hilt.navigation.compose.hiltViewModel
import com.everymeal.presentation.R
import com.everymeal.presentation.components.EveryMealDialog
import com.everymeal.presentation.ui.review.write.ReviewWriteScreen
import com.everymeal.presentation.ui.review.search.ReviewGuideHeader
import com.everymeal.presentation.ui.theme.Gray600
import com.everymeal.presentation.ui.theme.Grey2
import com.everymeal.presentation.ui.theme.Grey9
import com.everymeal.presentation.ui.theme.Typography
import com.everymeal.presentation.util.noRippleClickable

@Composable
fun ReviewScreen(
viewModel: ReviewScreenViewModel = hiltViewModel(),
viewModel: ReviewViewModel,
restaurantIdx: String,
moveReviewWriteScreen: () -> Unit = {},
) {
val pickMultipleMedia = rememberLauncherForActivityResult(
ActivityResultContracts.PickMultipleVisualMedia(10),
) {
viewModel.setEvent(ReviewEvent.OnImageSelected(it))
Log.d("ReviewScreen", "ReviewScreen: $it")
}
viewModel.setEvent(ReviewEvent.SetRestaurantIdx(restaurantIdx.toIntOrNull() ?: 0))

val viewState by viewModel.viewState.collectAsState()
val context = LocalContext.current
Scaffold(
topBar = {
ReviewTopBar(
Expand All @@ -69,81 +65,64 @@ fun ReviewScreen(
},
containerColor = Color.White,
) { innerPadding ->
ReviewStarRateContract(
modifier = Modifier.padding(innerPadding),
viewState = viewState,
onStarClicked = { index ->
viewModel.setEvent(ReviewEvent.OnStarClicked(index))
},
moveReviewWriteScreen = moveReviewWriteScreen,
)
Box(modifier = Modifier.padding(innerPadding)) {
Column {
// ReviewGuideHeader()
// ReviewSearchBar(
// modifier = Modifier
// .padding(top = 28.dp)
// .padding(horizontal = 20.dp),
// searchBarClicked = {
// //TODO 화면 이동
// }
// )
// StarDetail(
// viewState = viewState,
// startRatingClicked = { index ->
// viewModel.setEvent(ReviewEvent.OnStarClicked(index))
// },
// )
ReviewWriteScreen(
viewState = viewState,
starRatingClicked = { index ->
viewModel.setEvent(ReviewEvent.OnStarClicked(index))
},
reviewTextChanged = {
viewModel.setEvent(ReviewEvent.OnReviewTextChanged(it))
},
onReviewRegisterClicked = {
viewModel.setEvent(
ReviewEvent.PostReview(
mealIdx = viewState.idx,
reviewValue = viewState.reviewValue,
imageUri = viewState.imageUri,
restaurantType = viewState.restaurantType,
restaurantName = viewState.restaurantName,
starRatingCount = viewState.starRatingStateList.count { it.value },
),
)
Toast.makeText(
context,
context.getString(R.string.register_review),
Toast.LENGTH_SHORT,
).show()
},
onAddPhotoClicked = {
pickMultipleMedia.launch(
PickVisualMediaRequest(
ActivityResultContracts.PickVisualMedia.ImageOnly,
),
)
},
)
Column(
horizontalAlignment = Alignment.CenterHorizontally,
) {

}
}
}
}

@Composable
fun ColumnScope.StarDetail(
private fun ReviewStarRateContract(
modifier: Modifier = Modifier,
viewState: ReviewState,
startRatingClicked: (Int) -> Unit,
onStarClicked: (Int) -> Unit = {},
moveReviewWriteScreen: () -> Unit = {},
) {
Column(
modifier = modifier
.align(Alignment.CenterHorizontally)
.padding(top = 133.dp),
modifier = modifier.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally
) {
RestaurantType(
viewState = viewState,
)
RestaurantName(
ReviewGuideHeader(modifier = Modifier.fillMaxWidth())
Spacer(modifier = Modifier.height(133.dp))
StarDetail(
modifier = Modifier,
viewState = viewState,
startRatingClicked = { index ->
onStarClicked(index)
moveReviewWriteScreen()
},
)
}

}

@Composable
fun StarDetail(
modifier: Modifier,
viewState: ReviewState,
startRatingClicked: (Int) -> Unit,
) {
Column(
modifier = modifier,
horizontalAlignment = Alignment.CenterHorizontally,
) {
RestaurantType(viewState = viewState)
RestaurantName(viewState = viewState)
Spacer(modifier = Modifier.height(50.dp))
StarRating(
modifier = Modifier
.padding(top = 50.dp),
modifier = Modifier,
ratingStateList = viewState.starRatingStateList,
starRatingClicked = startRatingClicked,
)
Expand Down Expand Up @@ -194,7 +173,7 @@ fun RestaurantName(
fun StarRating(
modifier: Modifier = Modifier,
ratingStateList: List<State<Boolean>>,
starRatingClicked: ((Int) -> Unit)? = null,
starRatingClicked: (Int) -> Unit = {},
starSize: Dp = 40.dp,
) {
LazyRow(
Expand All @@ -206,8 +185,8 @@ fun StarRating(
modifier = Modifier
.size(starSize)
.padding(horizontal = 1.dp)
.clickable {
starRatingClicked?.invoke(index)
.noRippleClickable {
starRatingClicked(index)
},
painter = if (active.value) {
painterResource(
Expand Down Expand Up @@ -279,5 +258,14 @@ fun ReviewSaveDialog(
@Composable
@Preview
fun ReviewScreenPreview() {
ReviewScreen(
viewModel = hiltViewModel(),
restaurantIdx = "1"
)
}

@Composable
@Preview
fun ReviewSaveDialogPreview() {
ReviewSaveDialog()
}

This file was deleted.

Loading

0 comments on commit 64d4fcd

Please sign in to comment.