Skip to content

Commit 859ca73

Browse files
authored
Merge pull request #129 from THT-Team/feature/TOP-107_timer
[TOP-107] 메인화면 타이머 개선
2 parents c4e064f + 402ecb4 commit 859ca73

9 files changed

Lines changed: 282 additions & 224 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.example.compose_ui.common
2+
3+
import android.util.Log
4+
import androidx.compose.runtime.Composable
5+
import androidx.compose.runtime.DisposableEffect
6+
import androidx.compose.runtime.SideEffect
7+
import androidx.compose.runtime.remember
8+
9+
class RecompositionCounter(var value: Int)
10+
11+
@Composable
12+
inline fun LogComposition(
13+
tag: String,
14+
msg: String = "",
15+
) {
16+
DisposableEffect(Unit) {
17+
onDispose {
18+
Log.d(tag, "Dispose: $msg")
19+
}
20+
}
21+
val recompositionCounter = remember { RecompositionCounter(0) }
22+
SideEffect { recompositionCounter.value++ }
23+
Log.d(tag, "Composition: $msg ${recompositionCounter.value}")
24+
}
25+

feature/tohot/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,5 @@ dependencies {
7676
implementation(libs.lottie.compose)
7777

7878
implementation(libs.renderscript.intrinsics.replacement.toolkit)
79+
implementation(libs.kotlin.collections.immutable)
7980
}

feature/tohot/src/main/java/tht/feature/tohot/component/card/ToHotCard.kt

Lines changed: 56 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package tht.feature.tohot.component.card
22

33
import androidx.compose.animation.core.Animatable
44
import androidx.compose.animation.core.tween
5-
import androidx.compose.foundation.ExperimentalFoundationApi
65
import androidx.compose.foundation.layout.fillMaxSize
76
import androidx.compose.foundation.layout.fillMaxWidth
87
import androidx.compose.foundation.layout.padding
@@ -29,28 +28,27 @@ import tht.feature.tohot.component.progress.ToHotHeartTimeProgressContainer
2928
import tht.feature.tohot.component.userinfo.ToHotUserInfoCard
3029
import tht.feature.tohot.model.CardTimerUiModel
3130
import tht.feature.tohot.model.ImmutableListWrapper
31+
import kotlin.time.DurationUnit
32+
import kotlin.time.toDuration
3233

33-
@OptIn(ExperimentalFoundationApi::class)
3434
@Composable
3535
fun 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

Comments
 (0)