-
Notifications
You must be signed in to change notification settings - Fork 1
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
챌린지 상세 페이지에서 도전 내용 인디케이터 변경 사항 반영 #95
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
230 changes: 230 additions & 0 deletions
230
...on/src/main/java/com/whyranoid/presentation/component/challenge/ChallengeGoalIndicator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,230 @@ | ||
package com.whyranoid.presentation.component.challenge | ||
|
||
import androidx.compose.foundation.Canvas | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.foundation.progressSemantics | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material.Divider | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.clip | ||
import androidx.compose.ui.geometry.Offset | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.StrokeCap | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.text.drawText | ||
import androidx.compose.ui.text.rememberTextMeasurer | ||
import androidx.compose.ui.text.style.TextOverflow | ||
import androidx.compose.ui.unit.LayoutDirection | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import com.whyranoid.domain.model.challenge.Challenge | ||
import com.whyranoid.domain.model.challenge.ChallengeType | ||
import com.whyranoid.domain.util.EMPTY | ||
import com.whyranoid.domain.util.getDurationDifference | ||
import com.whyranoid.domain.util.getToday | ||
import com.whyranoid.presentation.theme.ChallengeColor.getColor | ||
import com.whyranoid.presentation.theme.WalkieColor | ||
import com.whyranoid.presentation.theme.WalkieTypography | ||
import java.time.LocalDateTime | ||
import java.time.format.DateTimeFormatter | ||
|
||
@Composable | ||
fun ChallengeGoalIndicator(challenge: Challenge) { | ||
|
||
val challengeColor = challenge.challengeType.getColor() | ||
|
||
Column( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.clip(shape = RoundedCornerShape(15.dp)) | ||
.background(challengeColor.backgroundColor), | ||
horizontalAlignment = Alignment.CenterHorizontally | ||
) { | ||
|
||
val progressBarColor = challengeColor.progressBarColor | ||
|
||
val progress = | ||
if (challenge.progress == null) 0f else requireNotNull(challenge.progress) / 100f | ||
|
||
val textMeasure = rememberTextMeasurer() | ||
|
||
Spacer(modifier = Modifier.height(20.dp)) | ||
|
||
Row( | ||
modifier = Modifier | ||
.fillMaxWidth(), | ||
horizontalArrangement = Arrangement.SpaceEvenly, | ||
verticalAlignment = Alignment.CenterVertically | ||
) { | ||
|
||
ChallengeGoalItem( | ||
modifier = Modifier.weight(1f), | ||
goal = "목표", | ||
limit = when (challenge.challengeType) { | ||
ChallengeType.LIFE -> { | ||
"연속 " + challenge.period.toString() + "일" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit) "연속 ${challenge.period}일"로 하면 더 간결하게 할 수 있을 것 같아요! |
||
} | ||
|
||
ChallengeType.CALORIE -> { | ||
challenge.calorie.toString() + "kcal" | ||
} | ||
|
||
ChallengeType.DISTANCE -> { | ||
"${challenge.distance}km" | ||
} | ||
}, | ||
) | ||
|
||
Divider( | ||
color = challengeColor.progressBarColor, | ||
modifier = Modifier | ||
.height(55.dp) | ||
.width(1.dp) | ||
) | ||
|
||
when (challenge.challengeType) { | ||
ChallengeType.LIFE -> { | ||
if (challenge.startTime != String.EMPTY) { | ||
ChallengeGoalItem( | ||
modifier = Modifier.weight(1f), | ||
goal = "운동 시작 시간", | ||
limit = "${challenge.startTime?.take(2)}-${challenge.endTime?.take(2)}시" | ||
) | ||
} else { | ||
ChallengeGoalItem( | ||
modifier = Modifier.weight(1f), | ||
goal = "일일 운동 시간", | ||
limit = "${(challenge.time ?: 0) / 60} 시간" | ||
) | ||
} | ||
|
||
} | ||
|
||
ChallengeType.CALORIE, ChallengeType.DISTANCE -> { | ||
ChallengeGoalItem( | ||
modifier = Modifier.weight(1f), | ||
goal = "기간", | ||
limit = challenge.timeLimit.toString() + "일 동안" | ||
) | ||
} | ||
} | ||
|
||
} | ||
|
||
Spacer(modifier = Modifier.height(20.dp)) | ||
|
||
if (challenge.status == "P") { | ||
|
||
Row( | ||
Modifier | ||
.fillMaxWidth() | ||
.padding(horizontal = 20.dp), | ||
horizontalArrangement = Arrangement.SpaceBetween, | ||
) { | ||
|
||
when (challenge.challengeType) { | ||
ChallengeType.LIFE -> { | ||
Text( | ||
"${challenge.accCount}일째 성공했어요!", | ||
style = WalkieTypography.Body1_ExtraBold.copy( | ||
color = challengeColor.progressBarColor | ||
) | ||
) | ||
} | ||
|
||
ChallengeType.CALORIE -> { | ||
Text( | ||
"${challenge.calorie?.minus(challenge.accCalories?.toInt() ?: 0)}kcal 만큼 남았어요", | ||
style = WalkieTypography.Body1_ExtraBold.copy( | ||
color = challengeColor.progressBarColor | ||
) | ||
) | ||
} | ||
|
||
ChallengeType.DISTANCE -> { | ||
Text( | ||
"${challenge.distance?.minus(challenge.accDistance?.toInt() ?: 0)}m 만큼 남았어요", | ||
style = WalkieTypography.Body1_ExtraBold.copy( | ||
color = challengeColor.progressBarColor | ||
) | ||
) | ||
} | ||
} | ||
|
||
|
||
Text( | ||
"${challenge.progress}%", | ||
style = WalkieTypography.Body1.copy( | ||
color = challengeColor.progressBarColor | ||
) | ||
) | ||
} | ||
|
||
Spacer(modifier = Modifier.height(8.dp)) | ||
|
||
Canvas( | ||
modifier = Modifier | ||
.progressSemantics(progress) | ||
.fillMaxWidth() | ||
.padding(horizontal = 20.dp) | ||
.height(4.dp) | ||
) { | ||
|
||
val width = size.width | ||
val height = size.height | ||
|
||
val yOffset = height / 2 | ||
|
||
val isLtr = layoutDirection == LayoutDirection.Ltr | ||
val barStart = (if (isLtr) 0f else 1f - progress) * width | ||
val barEnd = (if (isLtr) progress else 1f) * width | ||
|
||
// draw Background | ||
drawLine( | ||
Color.White, | ||
Offset(0f, yOffset), | ||
Offset(1f * width, yOffset), | ||
2.dp.toPx(), | ||
cap = StrokeCap.Round, | ||
) | ||
|
||
// Progress line | ||
drawLine( | ||
progressBarColor, | ||
Offset(barStart, yOffset), | ||
Offset(barEnd, yOffset), | ||
4.dp.toPx(), | ||
cap = StrokeCap.Round, | ||
) | ||
|
||
} | ||
|
||
Spacer(modifier = Modifier.height(10.dp)) | ||
|
||
val deadLineInfo = getDurationDifference( | ||
getToday(), challenge.challengeEdate ?: getToday() | ||
) | ||
|
||
Text( | ||
text = "${deadLineInfo[0]}일 ${deadLineInfo[1]}시간 ${deadLineInfo[2]}분" + "남음", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. index exception이 날 수도 있을 것 같아서 default 값이 있으면 좋을 것 같긴하네요! |
||
style = WalkieTypography.Body2.copy( | ||
color = Color(0xFF666666) | ||
) | ||
) | ||
|
||
Spacer(modifier = Modifier.height(10.dp)) | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...d/presentation/component/ChallengeItem.kt → ...tion/component/challenge/ChallengeItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...presentation/component/ChallengingItem.kt → ...on/component/challenge/ChallengingItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
requireNotNull을 쓰면 challenge.progress가 null이면 exception 나지 않나요? 아마 challenge.progress는 nullable한 상황이라 사용하셨을 것 같은데 다음과 같은 방식은 어떨까요?