diff --git a/presentation/src/main/java/com/everymeal/presentation/ui/restaurant/DetailRestaurantScreen.kt b/presentation/src/main/java/com/everymeal/presentation/ui/restaurant/DetailRestaurantScreen.kt index a93b79a..b99fdb6 100644 --- a/presentation/src/main/java/com/everymeal/presentation/ui/restaurant/DetailRestaurantScreen.kt +++ b/presentation/src/main/java/com/everymeal/presentation/ui/restaurant/DetailRestaurantScreen.kt @@ -53,8 +53,11 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.hilt.navigation.compose.hiltViewModel -import com.everymeal.domain.model.restaurant.RestaurantDataEntity +import androidx.paging.compose.LazyPagingItems +import androidx.paging.compose.collectAsLazyPagingItems import coil.compose.AsyncImage +import com.everymeal.domain.model.restaurant.RestaurantDataEntity +import com.everymeal.domain.model.review.StoreReviewEntity import com.everymeal.presentation.R import com.everymeal.presentation.base.LoadState import com.everymeal.presentation.components.EveryMealDialog @@ -83,6 +86,9 @@ fun DetailRestaurantScreen( val restaurantInfo = viewState.restaurantInfo + val pagingReviewList: LazyPagingItems = + detailRestaurantViewModel.restaurantReviews.collectAsLazyPagingItems() + LaunchedEffect(Unit) { detailRestaurantViewModel.setEvent( DetailRestaurantEvent.InitDetailRestaurantScreen( @@ -466,17 +472,24 @@ fun DetailRestaurantTabLayout( } } - HorizontalPager(state = pagerState) { page -> + HorizontalPager( + modifier = Modifier.fillMaxSize(), + state = pagerState + ) { page -> when (page) { 0 -> DetailRestaurantTabInfo( restaurantInfo = restaurantInfo, modifier = Modifier.padding(horizontal = 20.dp) ) - 1 -> DetailRestaurantTabImage( - restaurantInfo = restaurantInfo - ) + 1 -> { + DetailRestaurantTabImage( + restaurantInfo = restaurantInfo + ) + } - 2 -> DetailRestaurantReview() + 2 -> DetailRestaurantReview( + viewModel = viewModel, + ) } } } @@ -547,33 +560,37 @@ fun DetailRestaurantTabInfo( fun DetailRestaurantTabImage( restaurantInfo : RestaurantDataEntity ) { - Column { - restaurantInfo.images?.let { images -> - for (rowItems in images.chunked(3)) { - Row( - modifier = Modifier - .fillMaxWidth() - .padding(bottom = 3.dp), - horizontalArrangement = Arrangement.spacedBy(3.dp) - ) { - rowItems.forEach { item -> - AsyncImage( - model = item, - contentDescription = null, - modifier = Modifier - .weight(1f) - .aspectRatio(1f), - contentScale = ContentScale.Crop - ) - } - if (rowItems.size < 3) { - repeat(3 - rowItems.size) { - Box( + if(restaurantInfo.images.isNullOrEmpty()) { + + } else { + Column { + restaurantInfo.images?.let { images -> + for (rowItems in images.chunked(3)) { + Row( + modifier = Modifier + .fillMaxWidth() + .padding(bottom = 3.dp), + horizontalArrangement = Arrangement.spacedBy(3.dp) + ) { + rowItems.forEach { item -> + AsyncImage( + model = item, + contentDescription = null, modifier = Modifier .weight(1f) - .aspectRatio(1f) + .aspectRatio(1f), + contentScale = ContentScale.Crop ) } + if (rowItems.size < 3) { + repeat(3 - rowItems.size) { + Box( + modifier = Modifier + .weight(1f) + .aspectRatio(1f) + ) + } + } } } } @@ -582,7 +599,9 @@ fun DetailRestaurantTabImage( } @Composable -fun DetailRestaurantReview() { +fun DetailRestaurantReview( + viewModel: DetailRestaurantViewModel +) { } diff --git a/presentation/src/main/java/com/everymeal/presentation/ui/restaurant/DetailRestaurantViewModel.kt b/presentation/src/main/java/com/everymeal/presentation/ui/restaurant/DetailRestaurantViewModel.kt index ff3443f..b2a50cc 100644 --- a/presentation/src/main/java/com/everymeal/presentation/ui/restaurant/DetailRestaurantViewModel.kt +++ b/presentation/src/main/java/com/everymeal/presentation/ui/restaurant/DetailRestaurantViewModel.kt @@ -1,24 +1,36 @@ package com.everymeal.presentation.ui.restaurant import androidx.lifecycle.viewModelScope +import androidx.paging.PagingData +import androidx.paging.cachedIn import com.everymeal.domain.model.restaurant.RestaurantDataEntity +import com.everymeal.domain.model.review.StoreReviewEntity import com.everymeal.domain.usecase.restaurant.GetDetailRestaurantUseCase +import com.everymeal.domain.usecase.review.GetStoreReviewUseCase import com.everymeal.presentation.base.BaseViewModel import com.everymeal.presentation.base.LoadState import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch import javax.inject.Inject @HiltViewModel class DetailRestaurantViewModel @Inject constructor( - private val getDetailRestaurantUseCase: GetDetailRestaurantUseCase + private val getDetailRestaurantUseCase: GetDetailRestaurantUseCase, + private val getStoreReviewUseCase: GetStoreReviewUseCase ): BaseViewModel( DetailRestaurantState() ) { + private val _restaurantReviews : MutableStateFlow> = MutableStateFlow(value = PagingData.empty()) + val restaurantReviews : StateFlow> = _restaurantReviews.asStateFlow() + override fun handleEvents(event: DetailRestaurantEvent) { when(event) { is DetailRestaurantEvent.InitDetailRestaurantScreen -> { getDetailRestaurant(event.restaurantId) + getReviewList() } is DetailRestaurantEvent.OnTabSelectedChanged -> { reflectUpdateState( @@ -38,6 +50,20 @@ class DetailRestaurantViewModel @Inject constructor( } } + private fun getReviewList() { + viewModelScope.launch { + getStoreReviewUseCase( + order = "name", + group = null, + grade = null, + campusIdx = 2 + ).cachedIn(viewModelScope) + .collect { + _restaurantReviews.emit(it) + } + } + } + private fun getDetailRestaurant(restaurantIdx: Int) { viewModelScope.launch { getDetailRestaurantUseCase(restaurantIdx).onSuccess {