Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TOP-107] 메인화면 타이머 개선 #129

Merged
merged 17 commits into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
@@ -0,0 +1,25 @@
package com.example.compose_ui.common

import android.util.Log
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.remember

class RecompositionCounter(var value: Int)

@Composable
inline fun LogComposition(
tag: String,
msg: String = "",
) {
DisposableEffect(Unit) {
onDispose {
Log.d(tag, "Dispose: $msg")
}
}
val recompositionCounter = remember { RecompositionCounter(0) }
SideEffect { recompositionCounter.value++ }
Log.d(tag, "Composition: $msg ${recompositionCounter.value}")
}

1 change: 1 addition & 0 deletions feature/tohot/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,5 @@ dependencies {
implementation(libs.lottie.compose)

implementation(libs.renderscript.intrinsics.replacement.toolkit)
implementation(libs.kotlin.collections.immutable)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package tht.feature.tohot.component.card

import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.tween
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
Expand All @@ -29,28 +28,27 @@ import tht.feature.tohot.component.progress.ToHotHeartTimeProgressContainer
import tht.feature.tohot.component.userinfo.ToHotUserInfoCard
import tht.feature.tohot.model.CardTimerUiModel
import tht.feature.tohot.model.ImmutableListWrapper
import kotlin.time.DurationUnit
import kotlin.time.toDuration

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun ToHotCard(
modifier: Modifier = Modifier,
timer: CardTimerUiModel?,
imageUrls: ImmutableListWrapper<String>,
name: String,
age: Int,
address: String,
interests: ImmutableListWrapper<InterestModel>,
idealTypes: ImmutableListWrapper<IdealTypeModel>,
introduce: String,
timer: CardTimerUiModel.ToHotTimer,
maxTimeSec: Int,
currentSec: Float,
destinationSec: Float,
enable: Boolean,
fallingAnimationEnable: Boolean = false,
isHoldCard: Boolean,
isShakingCard: Boolean,
onFallingAnimationFinish: () -> Unit = { },
ticChanged: (Float) -> Unit = { },
onTicChanged: (Float) -> Unit = { },
onTimerEnd: () -> Unit = { },
userCardClick: () -> Unit = { },
onLikeClick: () -> Unit = { },
onUnLikeClick: () -> Unit = { },
Expand Down Expand Up @@ -92,15 +90,25 @@ fun ToHotCard(
val timerModifier = Modifier
.align(Alignment.TopCenter)
.padding(horizontal = 13.dp, vertical = 12.dp)
when (timer) {
when (timer?.timerType) {
CardTimerUiModel.ToHotTimer.Timer -> {
ToHotAnimateTimeProgressContainer(
modifier = timerModifier,
maxTimer = remember(timer) {
timer.maxTimer.toLong(DurationUnit.SECONDS).toInt()
},
initialDelay = remember(timer) {
timer.initialDelay.toLong(DurationUnit.MILLISECONDS)
},
completionDelay = remember(timer) {
timer.completionDelay.toLong(DurationUnit.MILLISECONDS)
},
enable = enable && !isHoldCard,
maxTimeSec = maxTimeSec,
currentSec = currentSec,
ticChanged = ticChanged,
destinationSec = destinationSec
duration = remember(timer) {
timer.duration.toLong(DurationUnit.MILLISECONDS)
},
onTicChanged = onTicChanged,
onEnd = onTimerEnd
)
}

Expand All @@ -115,6 +123,12 @@ fun ToHotCard(
modifier = timerModifier
)
}

null -> {
ToHotEmptyTimeProgressContainer(
modifier = timerModifier
)
}
}

if (isHoldCard) return@FallingCard
Expand Down Expand Up @@ -170,10 +184,13 @@ private fun ToHotCardPreview() {
interests = ImmutableListWrapper(emptyList()),
idealTypes = ImmutableListWrapper(emptyList()),
introduce = "introduce",
timer = CardTimerUiModel.ToHotTimer.Timer,
maxTimeSec = 5,
currentSec = 5f,
destinationSec = 4f,
timer = CardTimerUiModel(
maxTimer = 5.toDuration(DurationUnit.NANOSECONDS),
initialDelay = 1.toDuration(DurationUnit.NANOSECONDS),
completionDelay = 1.toDuration(DurationUnit.NANOSECONDS),
duration = 6.toDuration(DurationUnit.NANOSECONDS),
startAble = true
),
enable = true,
isHoldCard = false,
isShakingCard = false
Expand All @@ -198,10 +215,13 @@ private fun ToHotCardHoldCardPreview() {
interests = ImmutableListWrapper(emptyList()),
idealTypes = ImmutableListWrapper(emptyList()),
introduce = "introduce",
timer = CardTimerUiModel.ToHotTimer.Timer,
maxTimeSec = 5,
currentSec = 5f,
destinationSec = 4f,
timer = CardTimerUiModel(
maxTimer = 5.toDuration(DurationUnit.NANOSECONDS),
initialDelay = 1.toDuration(DurationUnit.NANOSECONDS),
completionDelay = 1.toDuration(DurationUnit.NANOSECONDS),
duration = 6.toDuration(DurationUnit.NANOSECONDS),
startAble = true
),
enable = true,
isHoldCard = true,
isShakingCard = false
Expand All @@ -226,10 +246,14 @@ private fun ToHotHeartCardPreview() {
interests = ImmutableListWrapper(emptyList()),
idealTypes = ImmutableListWrapper(emptyList()),
introduce = "introduce",
timer = CardTimerUiModel.ToHotTimer.Heart,
maxTimeSec = 5,
currentSec = 5f,
destinationSec = 4f,
timer = CardTimerUiModel(
maxTimer = 5.toDuration(DurationUnit.NANOSECONDS),
initialDelay = 1.toDuration(DurationUnit.NANOSECONDS),
completionDelay = 1.toDuration(DurationUnit.NANOSECONDS),
duration = 6.toDuration(DurationUnit.NANOSECONDS),
startAble = true,
timerType = CardTimerUiModel.ToHotTimer.Heart
),
enable = true,
isHoldCard = false,
isShakingCard = false
Expand All @@ -254,10 +278,14 @@ private fun ToHotDislikeCardPreview() {
interests = ImmutableListWrapper(emptyList()),
idealTypes = ImmutableListWrapper(emptyList()),
introduce = "introduce",
timer = CardTimerUiModel.ToHotTimer.Dislike,
maxTimeSec = 5,
currentSec = 5f,
destinationSec = 4f,
timer = CardTimerUiModel(
maxTimer = 5.toDuration(DurationUnit.NANOSECONDS),
initialDelay = 1.toDuration(DurationUnit.NANOSECONDS),
completionDelay = 1.toDuration(DurationUnit.NANOSECONDS),
duration = 6.toDuration(DurationUnit.NANOSECONDS),
startAble = true,
timerType = CardTimerUiModel.ToHotTimer.Dislike
),
enable = true,
isHoldCard = false,
isShakingCard = false
Expand Down
Loading
Loading