Skip to content

Commit

Permalink
feat : 카운트 다운 로직 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
HamBP committed Nov 14, 2024
1 parent 81602a1 commit 037938d
Showing 1 changed file with 24 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ import com.nexters.boolti.presentation.theme.marginHorizontal
import com.nexters.boolti.presentation.theme.point2
import com.nexters.boolti.presentation.theme.point3
import com.nexters.boolti.presentation.util.UrlParser
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.launch
import timber.log.Timber
import java.time.Duration
Expand Down Expand Up @@ -169,18 +171,19 @@ fun ShowDetailScreen(
.fillMaxSize()
.padding(innerPadding),
) {

val host = stringResource(
id = R.string.ticketing_host_format,
uiState.showDetail.hostName,
uiState.showDetail.hostPhoneNumber,
)

LazyColumn(
modifier = Modifier,
) {

item {
CountDownBanner(
uiState.showDetail.salesEndDate.plusDays(1).atStartOfDay().minusMinutes(1)
CountDownBanner( // todo : 날짜 변경
LocalDateTime.now().plusSeconds(15)
)
}

Expand Down Expand Up @@ -786,6 +789,14 @@ private fun Divider(modifier: Modifier = Modifier) {

@Composable
private fun CountDownBanner(deadlineDateTime: LocalDateTime) {
val remainingTime by flow {
while (true) {
val duration = Duration.between(LocalDateTime.now(), deadlineDateTime)
emit(maxOf(duration, Duration.ZERO))
delay(1000L)
}
}.collectAsStateWithLifecycle(Duration.ZERO)

Box(
modifier = Modifier
.height(40.dp)
Expand All @@ -794,27 +805,22 @@ private fun CountDownBanner(deadlineDateTime: LocalDateTime) {
contentAlignment = Alignment.Center
) {
Text(
text = deadlineDateTime.countDownString,
text = stringResource(id = R.string.show_ticketing_deadline_countdown) + " " +
getRemainingTimeString(duration = remainingTime),
style = MaterialTheme.typography.titleLarge.copy(color = Grey90)
)
}
}

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

val duration = Duration.between(now, this)
val hours = duration.toHours() % 24
val minutes = duration.toMinutes() % 60
val seconds = duration.seconds % 60
fun getRemainingTimeString(duration: Duration): String {
val hours = duration.toHours() % 24
val minutes = duration.toMinutes() % 60
val seconds = duration.seconds % 60

stringResource(id = R.string.show_ticketing_deadline_countdown) + " " +
"${hours.toString().padStart(2, '0')}:" +
"${minutes.toString().padStart(2, '0')}:" +
seconds.toString().padStart(2, '0')
}
return "${hours.toString().padStart(2, '0')}:" +
"${minutes.toString().padStart(2, '0')}:" +
seconds.toString().padStart(2, '0')
}

@Preview
@Composable
Expand Down

0 comments on commit 037938d

Please sign in to comment.