Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ fun ConditionResponse.toModel(): ConditionModel =
fun AvailableScheduleModel.toRequest(): AvailableScheduleRequest =
AvailableScheduleRequest(date = date, time = time)

enum class TravelTime(val label: String, val maxMinutes: Int?) {
WITHIN_30("30분 이내", 30),
WITHIN_60("1시간 이내", 60),
WITHIN_90("1시간 30분 이내", 90),
NO_PREFERENCE("상관 없어요", null),
}

@Serializable
enum class ActivityType(val label: String) {
BOARD_GAME("보드게임"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import kotlinx.collections.immutable.toPersistentList

fun HomeResponse.toModel(): HomeModel =
HomeModel(
nickname = nickname,
confirmedMeetings = confirmedMeetings.map { it.toModel() }.toImmutableList(),
myMeetings = myMeetings.map { it.toModel() }.toImmutableList(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import kotlinx.collections.immutable.ImmutableList

@Immutable
data class HomeModel(
val nickname: String,
val confirmedMeetings: ImmutableList<ConfirmedMeetingItemModel>,
val myMeetings: ImmutableList<MyMeetingCardItemModel>,
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import kotlinx.serialization.Serializable

@Serializable
data class HomeResponse(
@SerialName("nickname")
val nickname: String,
Comment thread
vahkjsdf marked this conversation as resolved.
@SerialName("confirmedMeetings")
val confirmedMeetings: List<ConfirmedMeetingResponse>,
@SerialName("myMeetings")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ fun RecommendedPlaceDetailResponse.applyTo(place: PlaceDetailModel): PlaceDetail
category = category,
address = address,
areaName = areaName,
totalMemberCount = participantCnt,
matchMemberCount = preferenceMatchCnt,
avgTravelMinutes = averageTravelTime,
imageList = imageUrls,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ data class RecommendedPlaceDetailResponse(
val address: String,
@SerialName("areaName")
val areaName: String,
@SerialName("participantCnt")
val participantCnt: Int,
@SerialName("preferenceMatchCnt")
val preferenceMatchCnt: Int,
@SerialName("averageTravelTime")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package com.moive.app.presentation.condition

import androidx.compose.runtime.Immutable
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toPersistentList
import java.util.Calendar

@Immutable
data class CalendarDay(
val day: Int,
val isCurrentMonth: Boolean,
val isSelectable: Boolean,
)

private const val SELECTABLE_RANGE_DAYS = 42

fun buildCalendarDays(year: Int, month: Int): ImmutableList<CalendarDay> {
val calendar = Calendar.getInstance()
calendar.clear()
Expand All @@ -21,6 +26,16 @@ fun buildCalendarDays(year: Int, month: Int): ImmutableList<CalendarDay> {
previousMonthCalendar.add(Calendar.MONTH, -1)
val daysInPreviousMonth = previousMonthCalendar.getActualMaximum(Calendar.DAY_OF_MONTH)

val today = Calendar.getInstance().apply {
set(Calendar.HOUR_OF_DAY, 0)
set(Calendar.MINUTE, 0)
set(Calendar.SECOND, 0)
set(Calendar.MILLISECOND, 0)
}
val maxSelectableDate = (today.clone() as Calendar).apply {
add(Calendar.DAY_OF_MONTH, SELECTABLE_RANGE_DAYS - 1)
}

val leadingCount = firstDayOfWeek - 1
val days = mutableListOf<CalendarDay>()

Expand All @@ -29,22 +44,28 @@ fun buildCalendarDays(year: Int, month: Int): ImmutableList<CalendarDay> {
CalendarDay(
day = daysInPreviousMonth - leadingCount + 1 + i,
isCurrentMonth = false,
isSelectable = false,
),
)
}

for (day in 1..daysInMonth) {
days.add(CalendarDay(day = day, isCurrentMonth = true))
val date = (calendar.clone() as Calendar).apply { set(Calendar.DAY_OF_MONTH, day) }
val isSelectable = !date.before(today) && !date.after(maxSelectableDate)
days.add(CalendarDay(day = day, isCurrentMonth = true, isSelectable = isSelectable))
}

val trailingCount = (7 - days.size % 7) % 7
for (day in 1..trailingCount) {
days.add(CalendarDay(day = day, isCurrentMonth = false))
days.add(CalendarDay(day = day, isCurrentMonth = false, isSelectable = false))
}

return days.toPersistentList()
}

fun monthHasSelectableDay(year: Int, month: Int): Boolean =
buildCalendarDays(year, month).any { it.isCurrentMonth && it.isSelectable }

fun previousMonth(year: Int, month: Int): Pair<Int, Int> {
val calendar = Calendar.getInstance()
calendar.clear()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.foundation.text.input.TextFieldState
import androidx.compose.runtime.Immutable
import com.moive.app.core.designsystem.component.toast.ToastType
import com.moive.app.data.condition.mapper.ActivityType
import com.moive.app.data.condition.mapper.TravelTime
import com.moive.app.data.condition.model.PlaceSearchItemModel
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.PersistentList
Expand Down Expand Up @@ -40,6 +41,12 @@ interface ConditionContract {
val calendarDays: ImmutableList<CalendarDay>
get() = buildCalendarDays(calendarYear, calendarMonth)

val hasPreviousMonth: Boolean
get() = previousMonth(calendarYear, calendarMonth).let { (year, month) -> monthHasSelectableDay(year, month) }

val hasNextMonth: Boolean
get() = nextMonth(calendarYear, calendarMonth).let { (year, month) -> monthHasSelectableDay(year, month) }

val timeOptions: ImmutableList<String>
get() = TIME_OPTIONS

Expand Down Expand Up @@ -144,13 +151,6 @@ sealed interface ConditionUiState {
) : ConditionUiState
}

enum class TravelTime(val label: String, val maxMinutes: Int?) {
WITHIN_30("30분 이내", 30),
WITHIN_60("1시간 이내", 60),
WITHIN_90("1시간 30분 이내", 90),
NO_PREFERENCE("상관 없어요", null),
}

fun String.toMaxTravelMinutes(): Int? =
TravelTime.entries.find { it.label == this }?.maxMinutes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,15 @@ class ConditionViewModel @Inject constructor(
fun onCalendarPrevMonthClick() {
_uiState.update {
val (year, month) = previousMonth(it.calendarYear, it.calendarMonth)
if (!monthHasSelectableDay(year, month)) return@update it
it.copy(calendarYear = year, calendarMonth = month, pendingDay = null)
}
}

fun onCalendarNextMonthClick() {
_uiState.update {
val (year, month) = nextMonth(it.calendarYear, it.calendarMonth)
if (!monthHasSelectableDay(year, month)) return@update it
it.copy(calendarYear = year, calendarMonth = month, pendingDay = null)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ import androidx.compose.foundation.layout.aspectRatio
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.wrapContentSize
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.SheetState
import androidx.compose.material3.SheetValue
import androidx.compose.material3.Text
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
Expand Down Expand Up @@ -132,8 +130,12 @@ private fun DateBottomSheetContent(
Icon(
imageVector = ImageVector.vectorResource(R.drawable.ic_arrow_chevron_left_20),
contentDescription = null,
tint = colors.icon.default,
modifier = Modifier.noRippleClickable(onClick = onPrevMonthClick),
tint = if (uiState.hasPreviousMonth) colors.icon.default else colors.icon.disabled,
modifier = if (uiState.hasPreviousMonth) {
Modifier.noRippleClickable(onClick = onPrevMonthClick)
} else {
Modifier
},
)

Text(
Expand All @@ -146,8 +148,12 @@ private fun DateBottomSheetContent(
Icon(
imageVector = ImageVector.vectorResource(R.drawable.ic_arrow_chevron_right_20),
contentDescription = null,
tint = colors.icon.default,
modifier = Modifier.noRippleClickable(onClick = onNextMonthClick),
tint = if (uiState.hasNextMonth) colors.icon.default else colors.icon.disabled,
modifier = if (uiState.hasNextMonth) {
Modifier.noRippleClickable(onClick = onNextMonthClick)
} else {
Modifier
},
)
}

Expand Down Expand Up @@ -187,7 +193,7 @@ private fun DateBottomSheetContent(
week.forEach { calendarDay ->
CalendarDayCell(
calendarDay = calendarDay,
isSelected = calendarDay.isCurrentMonth && calendarDay.day == uiState.pendingDay,
isSelected = calendarDay.isSelectable && calendarDay.day == uiState.pendingDay,
onClick = { onDayClick(calendarDay.day) },
modifier = Modifier.weight(1f),
)
Expand Down Expand Up @@ -276,7 +282,7 @@ private fun CalendarDayCell(
modifier = modifier
.aspectRatio(1f)
.then(
if (calendarDay.isCurrentMonth) {
if (calendarDay.isSelectable) {
Modifier.noRippleClickable(onClick = onClick)
} else {
Modifier
Expand All @@ -288,7 +294,7 @@ private fun CalendarDayCell(
text = calendarDay.day.toString(),
color = when {
isSelected -> colors.text.onBg
calendarDay.isCurrentMonth -> colors.text.default
calendarDay.isSelectable -> colors.text.default
else -> colors.text.tertiary
},
style = typography.label.mdM,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import kotlinx.collections.immutable.toImmutableList
interface HomeContract {
@Immutable
data class State(
val userName: String = "수현",
val userName: String = "",
val isAlarmUnRead: Boolean = false,
val selectedTab: String = MeetingTab.ALL.label,
val homeUiState: HomeUiState = HomeUiState.Idle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class HomeViewModel @Inject constructor(
_uiState.update {
it.copy(
homeUiState = HomeUiState.Success,
userName = home.nickname,
upcomingMeetings = home.confirmedMeetings,
myMeetingList = home.myMeetings,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,63 +84,59 @@ class MeetingConfirmedViewModel @Inject constructor(
}
}

private fun fetchPlaceDetail(areaId: Long, placeId: Long) {
private suspend fun fetchPlaceDetail(areaId: Long, placeId: Long) {
_uiState.update { it.copy(placeDetailUiState = PlaceDetailUiState.Loading) }
viewModelScope.launch {
votingRepository.getRecommendedPlaceDetail(
meetingId = meetingId,
recommendedAreaId = areaId,
recommendedPlaceId = placeId,
current = _uiState.value.currentPlaceDetail,
)
.onSuccess { updated ->
_uiState.update {
it.copy(
placeDetailUiState = PlaceDetailUiState.Success,
currentPlaceDetail = updated,
)
}
votingRepository.getRecommendedPlaceDetail(
meetingId = meetingId,
recommendedAreaId = areaId,
recommendedPlaceId = placeId,
current = _uiState.value.currentPlaceDetail,
)
.onSuccess { updated ->
_uiState.update {
it.copy(
placeDetailUiState = PlaceDetailUiState.Success,
currentPlaceDetail = updated,
)
}
.onFailure { error ->
Timber.tag(TAG).e(error, PLACE_DETAIL_FAILURE_MESSAGE)
_uiState.update {
it.copy(
placeDetailUiState = PlaceDetailUiState.Failure(
error.message ?: UNKNOWN_ERROR_MESSAGE,
),
)
}
}
.onFailure { error ->
Timber.tag(TAG).e(error, PLACE_DETAIL_FAILURE_MESSAGE)
_uiState.update {
it.copy(
placeDetailUiState = PlaceDetailUiState.Failure(
error.message ?: UNKNOWN_ERROR_MESSAGE,
),
)
}
}
}
}

private fun fetchPlaceRoute(placeId: Long) {
private suspend fun fetchPlaceRoute(placeId: Long) {
_uiState.update { it.copy(placeRouteUiState = PlaceRouteUiState.Loading) }
viewModelScope.launch {
votingRepository.getRecommendedPlaceRoute(
meetingId = meetingId,
recommendedPlaceId = placeId,
current = _uiState.value.currentPlaceDetail,
)
.onSuccess { updated ->
_uiState.update {
it.copy(
placeRouteUiState = PlaceRouteUiState.Success,
currentPlaceDetail = updated,
)
}
votingRepository.getRecommendedPlaceRoute(
meetingId = meetingId,
recommendedPlaceId = placeId,
current = _uiState.value.currentPlaceDetail,
)
.onSuccess { updated ->
_uiState.update {
it.copy(
placeRouteUiState = PlaceRouteUiState.Success,
currentPlaceDetail = updated,
)
}
.onFailure { error ->
Timber.tag(TAG).e(error, PLACE_ROUTE_FAILURE_MESSAGE)
_uiState.update {
it.copy(
placeRouteUiState = PlaceRouteUiState.Failure(
error.message ?: UNKNOWN_ERROR_MESSAGE,
),
)
}
}
.onFailure { error ->
Timber.tag(TAG).e(error, PLACE_ROUTE_FAILURE_MESSAGE)
_uiState.update {
it.copy(
placeRouteUiState = PlaceRouteUiState.Failure(
error.message ?: UNKNOWN_ERROR_MESSAGE,
),
)
}
}
}
}

fun backToMain() {
Expand Down
Loading
Loading