@@ -2,7 +2,6 @@ package tht.feature.tohot.component.card
22
33import androidx.compose.animation.core.Animatable
44import androidx.compose.animation.core.tween
5- import androidx.compose.foundation.ExperimentalFoundationApi
65import androidx.compose.foundation.layout.fillMaxSize
76import androidx.compose.foundation.layout.fillMaxWidth
87import androidx.compose.foundation.layout.padding
@@ -29,28 +28,27 @@ import tht.feature.tohot.component.progress.ToHotHeartTimeProgressContainer
2928import tht.feature.tohot.component.userinfo.ToHotUserInfoCard
3029import tht.feature.tohot.model.CardTimerUiModel
3130import tht.feature.tohot.model.ImmutableListWrapper
31+ import kotlin.time.DurationUnit
32+ import kotlin.time.toDuration
3233
33- @OptIn(ExperimentalFoundationApi ::class )
3434@Composable
3535fun ToHotCard (
3636 modifier : Modifier = Modifier ,
37+ timer : CardTimerUiModel ? ,
3738 imageUrls : ImmutableListWrapper <String >,
3839 name : String ,
3940 age : Int ,
4041 address : String ,
4142 interests : ImmutableListWrapper <InterestModel >,
4243 idealTypes : ImmutableListWrapper <IdealTypeModel >,
4344 introduce : String ,
44- timer : CardTimerUiModel .ToHotTimer ,
45- maxTimeSec : Int ,
46- currentSec : Float ,
47- destinationSec : Float ,
4845 enable : Boolean ,
4946 fallingAnimationEnable : Boolean = false,
5047 isHoldCard : Boolean ,
5148 isShakingCard : Boolean ,
5249 onFallingAnimationFinish : () -> Unit = { },
53- ticChanged : (Float ) -> Unit = { },
50+ onTicChanged : (Float ) -> Unit = { },
51+ onTimerEnd : () -> Unit = { },
5452 userCardClick : () -> Unit = { },
5553 onLikeClick : () -> Unit = { },
5654 onUnLikeClick : () -> Unit = { },
@@ -92,15 +90,25 @@ fun ToHotCard(
9290 val timerModifier = Modifier
9391 .align(Alignment .TopCenter )
9492 .padding(horizontal = 13 .dp, vertical = 12 .dp)
95- when (timer) {
93+ when (timer?.timerType ) {
9694 CardTimerUiModel .ToHotTimer .Timer -> {
9795 ToHotAnimateTimeProgressContainer (
9896 modifier = timerModifier,
97+ maxTimer = remember(timer) {
98+ timer.maxTimer.toLong(DurationUnit .SECONDS ).toInt()
99+ },
100+ initialDelay = remember(timer) {
101+ timer.initialDelay.toLong(DurationUnit .MILLISECONDS )
102+ },
103+ completionDelay = remember(timer) {
104+ timer.completionDelay.toLong(DurationUnit .MILLISECONDS )
105+ },
99106 enable = enable && ! isHoldCard,
100- maxTimeSec = maxTimeSec,
101- currentSec = currentSec,
102- ticChanged = ticChanged,
103- destinationSec = destinationSec
107+ duration = remember(timer) {
108+ timer.duration.toLong(DurationUnit .MILLISECONDS )
109+ },
110+ onTicChanged = onTicChanged,
111+ onEnd = onTimerEnd
104112 )
105113 }
106114
@@ -115,6 +123,12 @@ fun ToHotCard(
115123 modifier = timerModifier
116124 )
117125 }
126+
127+ null -> {
128+ ToHotEmptyTimeProgressContainer (
129+ modifier = timerModifier
130+ )
131+ }
118132 }
119133
120134 if (isHoldCard) return @FallingCard
@@ -170,10 +184,13 @@ private fun ToHotCardPreview() {
170184 interests = ImmutableListWrapper (emptyList()),
171185 idealTypes = ImmutableListWrapper (emptyList()),
172186 introduce = " introduce" ,
173- timer = CardTimerUiModel .ToHotTimer .Timer ,
174- maxTimeSec = 5 ,
175- currentSec = 5f ,
176- destinationSec = 4f ,
187+ timer = CardTimerUiModel (
188+ maxTimer = 5 .toDuration(DurationUnit .NANOSECONDS ),
189+ initialDelay = 1 .toDuration(DurationUnit .NANOSECONDS ),
190+ completionDelay = 1 .toDuration(DurationUnit .NANOSECONDS ),
191+ duration = 6 .toDuration(DurationUnit .NANOSECONDS ),
192+ startAble = true
193+ ),
177194 enable = true ,
178195 isHoldCard = false ,
179196 isShakingCard = false
@@ -198,10 +215,13 @@ private fun ToHotCardHoldCardPreview() {
198215 interests = ImmutableListWrapper (emptyList()),
199216 idealTypes = ImmutableListWrapper (emptyList()),
200217 introduce = " introduce" ,
201- timer = CardTimerUiModel .ToHotTimer .Timer ,
202- maxTimeSec = 5 ,
203- currentSec = 5f ,
204- destinationSec = 4f ,
218+ timer = CardTimerUiModel (
219+ maxTimer = 5 .toDuration(DurationUnit .NANOSECONDS ),
220+ initialDelay = 1 .toDuration(DurationUnit .NANOSECONDS ),
221+ completionDelay = 1 .toDuration(DurationUnit .NANOSECONDS ),
222+ duration = 6 .toDuration(DurationUnit .NANOSECONDS ),
223+ startAble = true
224+ ),
205225 enable = true ,
206226 isHoldCard = true ,
207227 isShakingCard = false
@@ -226,10 +246,14 @@ private fun ToHotHeartCardPreview() {
226246 interests = ImmutableListWrapper (emptyList()),
227247 idealTypes = ImmutableListWrapper (emptyList()),
228248 introduce = " introduce" ,
229- timer = CardTimerUiModel .ToHotTimer .Heart ,
230- maxTimeSec = 5 ,
231- currentSec = 5f ,
232- destinationSec = 4f ,
249+ timer = CardTimerUiModel (
250+ maxTimer = 5 .toDuration(DurationUnit .NANOSECONDS ),
251+ initialDelay = 1 .toDuration(DurationUnit .NANOSECONDS ),
252+ completionDelay = 1 .toDuration(DurationUnit .NANOSECONDS ),
253+ duration = 6 .toDuration(DurationUnit .NANOSECONDS ),
254+ startAble = true ,
255+ timerType = CardTimerUiModel .ToHotTimer .Heart
256+ ),
233257 enable = true ,
234258 isHoldCard = false ,
235259 isShakingCard = false
@@ -254,10 +278,14 @@ private fun ToHotDislikeCardPreview() {
254278 interests = ImmutableListWrapper (emptyList()),
255279 idealTypes = ImmutableListWrapper (emptyList()),
256280 introduce = " introduce" ,
257- timer = CardTimerUiModel .ToHotTimer .Dislike ,
258- maxTimeSec = 5 ,
259- currentSec = 5f ,
260- destinationSec = 4f ,
281+ timer = CardTimerUiModel (
282+ maxTimer = 5 .toDuration(DurationUnit .NANOSECONDS ),
283+ initialDelay = 1 .toDuration(DurationUnit .NANOSECONDS ),
284+ completionDelay = 1 .toDuration(DurationUnit .NANOSECONDS ),
285+ duration = 6 .toDuration(DurationUnit .NANOSECONDS ),
286+ startAble = true ,
287+ timerType = CardTimerUiModel .ToHotTimer .Dislike
288+ ),
261289 enable = true ,
262290 isHoldCard = false ,
263291 isShakingCard = false
0 commit comments