Skip to content

Commit

Permalink
[feature/remain_feat] 리뷰 페이징 (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
SsongSik committed Feb 12, 2024
1 parent fb8ee59 commit 6c1ef8b
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -83,6 +86,9 @@ fun DetailRestaurantScreen(

val restaurantInfo = viewState.restaurantInfo

val pagingReviewList: LazyPagingItems<StoreReviewEntity> =
detailRestaurantViewModel.restaurantReviews.collectAsLazyPagingItems()

LaunchedEffect(Unit) {
detailRestaurantViewModel.setEvent(
DetailRestaurantEvent.InitDetailRestaurantScreen(
Expand Down Expand Up @@ -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,
)
}
}
}
Expand Down Expand Up @@ -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)
)
}
}
}
}
}
Expand All @@ -582,7 +599,9 @@ fun DetailRestaurantTabImage(
}

@Composable
fun DetailRestaurantReview() {
fun DetailRestaurantReview(
viewModel: DetailRestaurantViewModel
) {

}

Expand Down
Original file line number Diff line number Diff line change
@@ -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, DetailRestaurantEffect, DetailRestaurantEvent>(
DetailRestaurantState()
) {
private val _restaurantReviews : MutableStateFlow<PagingData<StoreReviewEntity>> = MutableStateFlow(value = PagingData.empty())
val restaurantReviews : StateFlow<PagingData<StoreReviewEntity>> = _restaurantReviews.asStateFlow()

override fun handleEvents(event: DetailRestaurantEvent) {
when(event) {
is DetailRestaurantEvent.InitDetailRestaurantScreen -> {
getDetailRestaurant(event.restaurantId)
getReviewList()
}
is DetailRestaurantEvent.OnTabSelectedChanged -> {
reflectUpdateState(
Expand All @@ -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 {
Expand Down

0 comments on commit 6c1ef8b

Please sign in to comment.