Skip to content

Commit

Permalink
feat : 티켓 판매 전 카운트 다운
Browse files Browse the repository at this point in the history
  • Loading branch information
HamBP committed Nov 11, 2024
1 parent 02b3e2e commit c604706
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 10 deletions.
3 changes: 1 addition & 2 deletions domain/src/main/java/com/nexters/boolti/domain/model/Show.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ data class Show(
val state: ShowState
get() {
val now = LocalDate.now()
val dDay = salesStartDate.toEpochDay() - now.toEpochDay()

return when {
now > date.toLocalDate() -> ShowState.FinishedShow
now < salesStartDate -> ShowState.WaitingTicketing(dDay.toInt())
now < salesStartDate -> ShowState.WaitingTicketing(salesStartDate.atStartOfDay())
now <= salesEndDate -> ShowState.TicketingInProgress
now > salesEndDate -> ShowState.ClosedTicketing
else -> ShowState.FinishedShow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ data class ShowDetail(
val state: ShowState
get() {
val now = LocalDate.now()
val dDay = salesStartDate.toEpochDay() - now.toEpochDay()

return when {
now > date.toLocalDate() -> ShowState.FinishedShow
now < salesStartDate -> ShowState.WaitingTicketing(dDay.toInt())
now < salesStartDate -> ShowState.WaitingTicketing(salesStartDate.atStartOfDay())
now <= salesEndDate -> ShowState.TicketingInProgress
now > salesEndDate -> ShowState.ClosedTicketing
else -> ShowState.FinishedShow
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.nexters.boolti.domain.model

import java.time.LocalDateTime

sealed interface ShowState {
data class WaitingTicketing(val dDay: Int) : ShowState
data class WaitingTicketing(val startDateTime: LocalDateTime) : ShowState
data object TicketingInProgress : ShowState
data object ClosedTicketing : ShowState
data object FinishedShow : ShowState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,25 @@ import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import com.nexters.boolti.domain.model.Show
import com.nexters.boolti.domain.model.ShowState
import com.nexters.boolti.presentation.R
import com.nexters.boolti.presentation.constants.posterRatio
import com.nexters.boolti.presentation.extension.dDay
import com.nexters.boolti.presentation.extension.showDateTimeString
import com.nexters.boolti.presentation.extension.toPx
import com.nexters.boolti.presentation.theme.BooltiTheme
import com.nexters.boolti.presentation.theme.Grey05
import com.nexters.boolti.presentation.theme.Grey20
import com.nexters.boolti.presentation.theme.Grey30
import com.nexters.boolti.presentation.theme.Grey40
import com.nexters.boolti.presentation.theme.Grey80
import com.nexters.boolti.presentation.theme.Grey95
import com.nexters.boolti.presentation.theme.point1
import java.time.LocalDateTime

@Composable
fun ShowFeed(
Expand Down Expand Up @@ -120,7 +124,7 @@ private fun ShowBadge(
var dDay: Int? = null
val (color, containerColor, labelId) = when (showState) {
is ShowState.WaitingTicketing -> {
dDay = showState.dDay
dDay = showState.startDateTime.dDay.toInt()
Triple(
MaterialTheme.colorScheme.primary,
Grey80,
Expand Down Expand Up @@ -148,4 +152,12 @@ private fun ShowBadge(
.padding(horizontal = 12.dp, vertical = 3.dp),
style = MaterialTheme.typography.labelMedium.copy(color = color),
)
}

@Preview
@Composable
private fun ShowBadgePreview() {
BooltiTheme {
ShowBadge(ShowState.WaitingTicketing(LocalDateTime.now().plusDays(3).plusHours(1)))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ package com.nexters.boolti.presentation.extension

import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringArrayResource
import androidx.compose.ui.res.stringResource
import com.nexters.boolti.presentation.R
import java.time.Duration
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.time.temporal.ChronoUnit

/**
* ## 요일
Expand All @@ -29,3 +33,24 @@ val LocalDateTime.showDateTimeString: String
}

fun LocalDateTime.format(pattern: String): String = format(DateTimeFormatter.ofPattern(pattern))

val LocalDateTime.dDay: Long
get() = run {
val today = LocalDate.now()
ChronoUnit.DAYS.between(today, toLocalDate())
}

val LocalDateTime.countDownString: String
@Composable
get() = run {
val now = LocalDateTime.now()

val duration = Duration.between(now, this)

val days = duration.toDays()
val hours = duration.toHours() % 24
val minutes = duration.toMinutes() % 60

stringResource(id = R.string.ticketing_button_ticket_countdown, days) +
" ${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ import com.nexters.boolti.domain.model.ShowState
import com.nexters.boolti.presentation.R
import com.nexters.boolti.presentation.component.MainButton
import com.nexters.boolti.presentation.component.MainButtonDefaults
import com.nexters.boolti.presentation.extension.countDownString
import com.nexters.boolti.presentation.theme.BooltiTheme
import com.nexters.boolti.presentation.theme.Grey50
import com.nexters.boolti.presentation.theme.Grey80
import com.nexters.boolti.presentation.theme.marginHorizontal
import java.time.LocalDateTime

@Composable
fun ShowDetailButtons(
Expand Down Expand Up @@ -93,10 +95,7 @@ private fun TicketingButton(
) {
val enabled = showState is ShowState.TicketingInProgress
val text = when (showState) {
is ShowState.WaitingTicketing -> stringResource(
id = R.string.ticketing_button_upcoming_ticket, showState.dDay
)

is ShowState.WaitingTicketing -> showState.startDateTime.countDownString
ShowState.TicketingInProgress -> stringResource(id = R.string.ticketing_button_label)
ShowState.ClosedTicketing -> stringResource(id = R.string.ticketing_button_closed_ticket)
ShowState.FinishedShow -> stringResource(id = R.string.ticketing_button_finished_show)
Expand Down Expand Up @@ -125,3 +124,17 @@ fun ShowDetailButtonsPreview() {
)
}
}

@Preview(heightDp = 100)
@Composable
fun ShowDetailButtonsBeforeTicketingPreview() {
BooltiTheme {
ShowDetailButtons(
showState = ShowState.WaitingTicketing(
LocalDateTime.now().plusDays(3).plusHours(2).plusMinutes(17)
),
onTicketingClicked = {},
onGiftClicked = {}
)
}
}
1 change: 1 addition & 0 deletions presentation/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
<string name="ticketing_button_purchased_ticket">이미 예매한 공연</string>
<string name="ticketing_button_purchased_ticket_message">1인 1매만 예매할 수 있어요</string>
<string name="ticketing_button_upcoming_ticket">예매 시작 D-%d</string>
<string name="ticketing_button_ticket_countdown">판매 시작까지 %d일</string>
<string name="ticketing_button_closed_ticket">예매 종료</string>
<string name="ticketing_button_finished_show">공연 종료</string>
<string name="ticketing_limit_per_person">1인 %d매</string>
Expand Down

0 comments on commit c604706

Please sign in to comment.