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 @@ -42,15 +42,16 @@ internal fun AppjamtampButton(
text: String,
onClicked: () -> Unit,
modifier: Modifier = Modifier,
isEnabled: Boolean = true,
) {
Box(
modifier = modifier
.fillMaxWidth()
.background(
color = SoptTheme.colors.primary,
color = if (isEnabled) SoptTheme.colors.primary else SoptTheme.colors.onSurface300,
shape = RoundedCornerShape(9.dp),
)
.clickable(onClick = onClicked),
.clickable(onClick = { if (isEnabled) onClicked() }),
contentAlignment = Alignment.Center,
) {
Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import org.sopt.official.common.util.throttledNoRippleClickable
import org.sopt.official.designsystem.SoptTheme
import org.sopt.official.feature.appjamtamp.R

Expand All @@ -57,7 +58,7 @@ internal fun BackButtonHeader(
imageVector = ImageVector.vectorResource(R.drawable.ic_back_32),
contentDescription = null,
tint = SoptTheme.colors.onSurface10,
modifier = Modifier.clickable(onClick = onBackButtonClick)
modifier = Modifier.throttledNoRippleClickable(onClick = onBackButtonClick),
)

Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
Expand All @@ -59,6 +60,7 @@ import com.airbnb.lottie.compose.LottieCompositionSpec
import com.airbnb.lottie.compose.animateLottieCompositionAsState
import com.airbnb.lottie.compose.rememberLottieComposition
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.first
import org.sopt.official.designsystem.SoptTheme
import org.sopt.official.designsystem.component.dialog.TwoButtonDialog
import org.sopt.official.feature.appjamtamp.R
Expand Down Expand Up @@ -130,10 +132,12 @@ internal fun MissionDetailRoute(
}
}

LaunchedEffect(!uiState.isLoading, progress) {
if (progress >= 0.99f && !uiState.isLoading) {
LaunchedEffect(showPostSubmissionBadge) {
if (showPostSubmissionBadge) {
snapshotFlow { progress >= 0.99f && !uiState.isLoading }.first { it }
delay(500L)
viewModel.updateShowPostSubmissionBadge()
navigateUp()
Comment thread
seungjunGong marked this conversation as resolved.
}
}

Expand All @@ -148,7 +152,8 @@ internal fun MissionDetailRoute(
},
onDatePickerClick = { isDatePickerVisible = true },
onMemoChange = viewModel::updateContent,
onCompleteButtonClick = viewModel::handleSubmit
onCompleteButtonClick = viewModel::handleSubmit,
isSubmitEnabled = uiState.isSubmitEnabled,
)
} else {
MissionDetailScreen(
Expand Down Expand Up @@ -185,7 +190,8 @@ internal fun MissionDetailRoute(

DetailViewType.EDIT -> viewModel.handleSubmit()
}
}
},
isSubmitEnabled = uiState.isSubmitEnabled,
)
}

Expand Down Expand Up @@ -249,7 +255,8 @@ private fun MyEmptyMissionDetailScreen(
onClickZoomIn: (String) -> Unit,
onDatePickerClick: () -> Unit,
onMemoChange: (String) -> Unit,
onCompleteButtonClick: () -> Unit
onCompleteButtonClick: () -> Unit,
isSubmitEnabled: Boolean,
) {
val scrollState = rememberScrollState()

Expand Down Expand Up @@ -306,6 +313,7 @@ private fun MyEmptyMissionDetailScreen(
AppjamtampButton(
text = "미션 완료",
onClicked = onCompleteButtonClick,
isEnabled = isSubmitEnabled,
modifier = Modifier
.fillMaxWidth()
.padding(bottom = 20.dp)
Expand All @@ -322,7 +330,8 @@ private fun MissionDetailScreen(
onClickZoomIn: (String) -> Unit,
onDatePickerClick: () -> Unit,
onMemoChange: (String) -> Unit,
onActionButtonClick: () -> Unit
onActionButtonClick: () -> Unit,
isSubmitEnabled: Boolean,
) {
val scrollState = rememberScrollState()
var isEditable by remember(uiState.viewType) { mutableStateOf(uiState.viewType == DetailViewType.EDIT) }
Expand Down Expand Up @@ -436,6 +445,7 @@ private fun MissionDetailScreen(
AppjamtampButton(
text = "미션 완료",
onClicked = onActionButtonClick,
isEnabled = isSubmitEnabled,
modifier = Modifier
.fillMaxWidth()
.padding(bottom = 20.dp)
Expand All @@ -456,7 +466,8 @@ private fun MyEmptyMissionDetailScreenPreview() {
onClickZoomIn = {},
onDatePickerClick = {},
onMemoChange = {},
onCompleteButtonClick = {}
onCompleteButtonClick = {},
isSubmitEnabled = true,
)
}
}
Expand All @@ -473,7 +484,8 @@ private fun MyMissionDetailScreenPreview() {
onDatePickerClick = {},
onMemoChange = {},
onActionButtonClick = {},
onToolbarIconClick = {}
onToolbarIconClick = {},
isSubmitEnabled = true,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,22 @@ internal data class MissionDetailState(
val viewCount: Int = 0,

val clappers: ImmutableList<StampClapUserModel> = persistentListOf(),
val showPostSubmissionBadge: Boolean = false
)
val showPostSubmissionBadge: Boolean = false,

val initSnapshotImageModel: ImageModel = ImageModel.Empty,
val initSnapshotDate: String = "",
val initSnapshotContent: String = "",
) {
val isSubmitEnabled: Boolean
get() {
val commonGuard = !isLoading && content.isNotBlank() && date.isNotBlank() && !imageModel.isEmpty()

if (!commonGuard) return false

return when (viewType) {
DetailViewType.WRITE -> true
DetailViewType.EDIT -> content != initSnapshotContent || date != initSnapshotDate || imageModel != initSnapshotImageModel
DetailViewType.READ_ONLY, DetailViewType.COMPLETE -> false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ internal class MissionDetailViewModel @Inject constructor(
imageModel = ImageModel.Remote(stamp.images),
date = stamp.activityDate,
content = stamp.contents,
initSnapshotImageModel = ImageModel.Remote(stamp.images),
initSnapshotDate = stamp.activityDate,
initSnapshotContent = stamp.contents,
teamName = stamp.teamName,
stampId = stamp.stampId,
writer = User(
Expand Down Expand Up @@ -260,7 +263,10 @@ internal class MissionDetailViewModel @Inject constructor(
_missionDetailState.update {
it.copy(
isLoading = false,
viewType = DetailViewType.COMPLETE
viewType = DetailViewType.COMPLETE,
initSnapshotImageModel = ImageModel.Remote(imageModel.url),
initSnapshotDate = date,
initSnapshotContent = content,
Comment thread
seungjunGong marked this conversation as resolved.
)
}
}.onFailure { e ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,13 @@ 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 java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
import java.util.TimeZone
import java.util.concurrent.TimeUnit
import org.sopt.official.designsystem.GrayAlpha100
import org.sopt.official.designsystem.SoptTheme
import org.sopt.official.designsystem.White
import org.sopt.official.designsystem.component.UrlImage
import org.sopt.official.feature.appjamtamp.R
import org.sopt.official.feature.appjamtamp.ranking.model.Top3RecentRankingUiModel
import org.sopt.official.feature.appjamtamp.util.toRelativeTime

@Composable
internal fun Top3RecentRankingMission(
Expand Down Expand Up @@ -152,32 +148,6 @@ internal fun Top3RecentRankingMission(
}
}

private fun String?.toRelativeTime(): String {
if (this.isNullOrBlank()) return ""

val dateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.KOREA)
dateFormat.timeZone = TimeZone.getTimeZone("Asia/Seoul")

val date = dateFormat.parse(this) ?: return ""
val currentDate = Date()

val diffMillis = currentDate.time - date.time
if (diffMillis < 0) return "1분 전"

val minutes = TimeUnit.MILLISECONDS.toMinutes(diffMillis)
val hours = TimeUnit.MILLISECONDS.toHours(diffMillis)

return when {
minutes == 0L -> "1분 전"
minutes in 1..59 -> "${minutes}분 전"
hours in 1..24 -> "${hours}시간 전"
else -> {
val days = TimeUnit.MILLISECONDS.toDays(diffMillis)
"${days}일 전"
}
}
}

@Preview
@Composable
private fun Top3RecentRankingMissionPreview() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* MIT License
* Copyright 2025-2026 SOPT - Shout Our Passion Together
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.sopt.official.feature.appjamtamp.util

import java.time.LocalDateTime
import java.time.ZoneId
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
import java.util.Locale
import java.util.concurrent.TimeUnit

private val seoulZoneId: ZoneId = ZoneId.of("Asia/Seoul")
private val monthDayFormatter: DateTimeFormatter =
DateTimeFormatter.ofPattern("M월 d일", Locale.KOREA)

fun String?.toRelativeTime(
currentDateTime: ZonedDateTime = ZonedDateTime.now(seoulZoneId)
): String {
if (this.isNullOrBlank()) return ""

val dateTime = runCatching {
LocalDateTime.parse(this).atZone(seoulZoneId)
}.getOrNull() ?: return ""

val diffMillis = currentDateTime.toInstant().toEpochMilli() - dateTime.toInstant().toEpochMilli()

if (diffMillis < 0) return "방금 전"

val minutes = TimeUnit.MILLISECONDS.toMinutes(diffMillis)
val hours = TimeUnit.MILLISECONDS.toHours(diffMillis)
val days = TimeUnit.MILLISECONDS.toDays(diffMillis)

return when {
diffMillis < TimeUnit.MINUTES.toMillis(10) -> "방금 전"
diffMillis < TimeUnit.HOURS.toMillis(1) -> "${minutes}분 전"
diffMillis < TimeUnit.DAYS.toMillis(1) -> "${hours}시간 전"
diffMillis < TimeUnit.DAYS.toMillis(7) -> "${days}일 전"
diffMillis < TimeUnit.DAYS.toMillis(28) -> "${days / 7}주 전"
else -> dateTime.format(monthDayFormatter)
Comment thread
seungjunGong marked this conversation as resolved.
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* MIT License
* Copyright 2026 SOPT - Shout Our Passion Together
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.sopt.official.feature.appjamtamp.util

import com.google.common.truth.Truth.assertThat
import java.time.ZoneId
import java.time.ZonedDateTime
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.MethodSource

class RelativeTimeExtTest {

@ParameterizedTest
@MethodSource("relativeTimeCases")
@DisplayName("createdAt 문자열을 상대 시간 문구로 변환한다")
fun toRelativeTime(description: String, createdAt: String?, expected: String) {
// when
val actual = createdAt.toRelativeTime(currentDateTime = fixedNow)

// then
assertThat(actual).isEqualTo(expected)
}

companion object {
private val fixedNow: ZonedDateTime =
ZonedDateTime.of(2026, 6, 3, 12, 0, 0, 0, ZoneId.of("Asia/Seoul"))

@JvmStatic
fun relativeTimeCases() = listOf(
Arguments.of("null 입력은 빈 문자열을 반환한다", null, ""),
Arguments.of("blank 입력은 빈 문자열을 반환한다", "", ""),
Arguments.of("파싱 불가능한 입력은 빈 문자열을 반환한다", "invalid", ""),
Arguments.of("미래 시각은 방금 전으로 표시한다", "2026-06-03T12:01:00", "방금 전"),
Arguments.of("10분 미만은 방금 전으로 표시한다", "2026-06-03T11:50:01", "방금 전"),
Arguments.of("10분 경계는 분 전으로 표시한다", "2026-06-03T11:50:00", "10분 전"),
Arguments.of("1시간 미만은 분 전으로 표시한다", "2026-06-03T11:01:00", "59분 전"),
Arguments.of("1시간 경계는 시간 전으로 표시한다", "2026-06-03T11:00:00", "1시간 전"),
Arguments.of("24시간 미만은 시간 전으로 표시한다", "2026-06-02T12:01:00", "23시간 전"),
Arguments.of("24시간 경계는 일 전으로 표시한다", "2026-06-02T12:00:00", "1일 전"),
Arguments.of("7일 미만은 일 전으로 표시한다", "2026-05-27T12:00:01", "6일 전"),
Arguments.of("7일 경계는 주 전으로 표시한다", "2026-05-27T12:00:00", "1주 전"),
Arguments.of("28일 미만은 주 전으로 표시한다", "2026-05-06T12:00:01", "3주 전"),
Arguments.of("28일 경계는 월일 포맷으로 표시한다", "2026-05-06T12:00:00", "5월 6일"),
)
}
}
Loading