-
Notifications
You must be signed in to change notification settings - Fork 1
공통 발표 그래프 컴포넌트 구현 #133
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
Merged
The head ref may contain hidden characters: "feat/#120-\uACF5\uD1B5-\uBC1C\uD45C-\uADF8\uB798\uD504-\uCEF4\uD3EC\uB10C\uD2B8-\uAD6C\uD604"
Merged
공통 발표 그래프 컴포넌트 구현 #133
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
06d7462
feat: 리포트(Report) 기능 모듈 추가 및 기본 화면 구현
moondev03 fc438cc
feat: 속도 시각화를 위한 SpeedGraph 컴포넌트 추가
moondev03 8110ef0
refactor: SpeedGraph 컴포넌트 레이아웃 방식 개선 및 로직 단순화
moondev03 4e16122
docs: SpeedGraph 내 로직 설명 주석 추가 및 Preview 구조 분리
moondev03 7fb665f
refactor: SpeedGraph 컴포넌트 구조 개선 및 성능 최적화
moondev03 4e0e5c7
feat: 막대 그래프(StickGraph) 컴포넌트 추가 및 UI 구성 요소 구현
moondev03 e5e0b96
feat: 분석 데이터 시각화를 위한 `CardGraph` 컴포넌트 구현
moondev03 1f0c692
refactor: `CardGraph` 컴포넌트 구조 개선 및 커스터마이징 옵션 추가
moondev03 1b0cc28
refactor: CardGraph UI 컴포넌트 구조 개선 및 리소스화
moondev03 eb4ed62
chore: Detekt 설정 업데이트 및 커스텀 Preview 어노테이션 예외 추가
moondev03 3de90cc
refactor: CardGraph UI 구조 개선 및 로직 모듈화
moondev03 bd7a515
docs: CardGraphDrawers 내 그리기 로직 문서화 및 가독성 개선
moondev03 7b83b23
refactor: SpeedGraph 그리기 로직 리팩터링 및 가독성 개선
moondev03 f314efb
feat: PracticeCard 컴포넌트 추가 및 연습 현황 트래커 구현
moondev03 035082c
refactor: `CardGraph` UI 상태 구조 및 안정성 개선
moondev03 06aa8a7
refactor: StickGraph 안정성 개선 및 코드 스타일 정리
moondev03 0d82d0b
refactor: PracticeCard 내 하드코딩된 문자열을 리소스로 분리
moondev03 975cdf2
refactor: StickGraph 데이터 구조 개선 및 로직 단순화
moondev03 1fd2af9
Merge branch 'develop' into feat/#120-공통-발표-그래프-컴포넌트-구현
moondev03 434a407
refactor: StickGraph UI 스타일 적용 방식 및 텍스트 스타일 수정
moondev03 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 hidden or 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
359 changes: 359 additions & 0 deletions
359
Prezel/core/ui/src/main/java/com/team/prezel/core/ui/component/PracticeCard.kt
This file contains hidden or 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,359 @@ | ||
| package com.team.prezel.core.ui.component | ||
|
|
||
| import androidx.compose.foundation.background | ||
| import androidx.compose.foundation.layout.Arrangement | ||
| import androidx.compose.foundation.layout.Box | ||
| 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.size | ||
| import androidx.compose.material3.Icon | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.Immutable | ||
| import androidx.compose.runtime.getValue | ||
| import androidx.compose.runtime.mutableIntStateOf | ||
| import androidx.compose.runtime.saveable.rememberSaveable | ||
| import androidx.compose.runtime.setValue | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.draw.clip | ||
| import androidx.compose.ui.graphics.Color | ||
| import androidx.compose.ui.platform.LocalDensity | ||
| import androidx.compose.ui.res.painterResource | ||
| import androidx.compose.ui.res.stringResource | ||
| import androidx.compose.ui.text.SpanStyle | ||
| import androidx.compose.ui.text.buildAnnotatedString | ||
| import androidx.compose.ui.text.withStyle | ||
| import androidx.compose.ui.unit.dp | ||
| import com.team.prezel.core.designsystem.component.actions.button.PrezelTextButton | ||
| import com.team.prezel.core.designsystem.component.actions.button.config.ButtonHierarchy | ||
| import com.team.prezel.core.designsystem.component.actions.button.config.ButtonSize | ||
| import com.team.prezel.core.designsystem.component.actions.button.config.ButtonType | ||
| import com.team.prezel.core.designsystem.icon.PrezelIcons | ||
| import com.team.prezel.core.designsystem.preview.BasicPreview | ||
| import com.team.prezel.core.designsystem.theme.PrezelTheme | ||
| import com.team.prezel.core.designsystem.util.drawDashBorder | ||
| import com.team.prezel.core.ui.R | ||
| import com.team.prezel.core.ui.util.noRippleClickable | ||
| import kotlinx.collections.immutable.ImmutableList | ||
| import kotlinx.collections.immutable.toImmutableList | ||
| import kotlinx.collections.immutable.toPersistentList | ||
| import kotlinx.datetime.DatePeriod | ||
| import kotlinx.datetime.LocalDate | ||
| import kotlinx.datetime.daysUntil | ||
| import kotlinx.datetime.format | ||
| import kotlinx.datetime.format.DateTimeFormat | ||
| import kotlinx.datetime.plus | ||
|
|
||
| private const val TRACKER_SIZE = 7 | ||
| private val StampFormatter: DateTimeFormat<LocalDate> = LocalDate.Format { day() } | ||
|
|
||
| private enum class StampType { | ||
| AFTER, | ||
| BEFORE, | ||
| EMPTY, | ||
| } | ||
|
|
||
| @Immutable | ||
| private data class TrackerItem( | ||
| val date: LocalDate, | ||
| val isPracticed: Boolean, | ||
| val type: StampType, | ||
| ) | ||
|
|
||
| @Immutable | ||
| data class PracticeCardItem( | ||
| val date: LocalDate, | ||
| val isPracticed: Boolean, | ||
| ) | ||
|
|
||
| @Composable | ||
| fun PracticeCard( | ||
| dDay: LocalDate, | ||
| items: ImmutableList<PracticeCardItem>, | ||
| modifier: Modifier = Modifier, | ||
| showActionButton: Boolean = true, | ||
| onClickAction: () -> Unit = {}, | ||
| ) { | ||
| var startIndex by rememberSaveable(items) { mutableIntStateOf(0) } | ||
| val trackerItems = items.toTrackerItems(dDay = dDay) | ||
| val hasPreviousPage = startIndex > 0 | ||
| val hasNextPage = startIndex + TRACKER_SIZE < trackerItems.size | ||
|
|
||
| Column( | ||
| modifier = modifier | ||
| .fillMaxWidth() | ||
| .clip(PrezelTheme.shapes.V6) | ||
| .background(color = PrezelTheme.colors.bgMedium) | ||
| .padding( | ||
| vertical = PrezelTheme.spacing.V12, | ||
| horizontal = PrezelTheme.spacing.V16, | ||
| ), | ||
| ) { | ||
| PracticeCardHeader( | ||
| practicedCount = items.count { item -> item.isPracticed }, | ||
| totalCount = items.size, | ||
| hasNextPage = hasNextPage, | ||
| hasPreviousPage = hasPreviousPage, | ||
| onClickLeft = { if (hasPreviousPage) startIndex -= TRACKER_SIZE }, | ||
| onClickRight = { if (hasNextPage) startIndex += TRACKER_SIZE }, | ||
| ) | ||
|
|
||
| Spacer(modifier = Modifier.height(PrezelTheme.spacing.V12)) | ||
|
|
||
| PracticeTracker( | ||
| items = trackerItems, | ||
| startIndex = startIndex, | ||
| ) | ||
|
|
||
| if (showActionButton) { | ||
| Spacer(modifier = Modifier.height(PrezelTheme.spacing.V12)) | ||
|
|
||
| PrezelTextButton( | ||
| text = stringResource(R.string.core_ui_impl_practice_card_action), | ||
| type = ButtonType.FILLED, | ||
| size = ButtonSize.SMALL, | ||
| hierarchy = ButtonHierarchy.SECONDARY, | ||
| onClick = onClickAction, | ||
| modifier = Modifier.fillMaxWidth(), | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| private fun PracticeCardHeader( | ||
| practicedCount: Int, | ||
| totalCount: Int, | ||
| hasNextPage: Boolean, | ||
| hasPreviousPage: Boolean, | ||
| onClickLeft: () -> Unit, | ||
| onClickRight: () -> Unit, | ||
| modifier: Modifier = Modifier, | ||
| ) { | ||
| Row( | ||
| modifier = modifier.fillMaxWidth(), | ||
| horizontalArrangement = Arrangement.SpaceBetween, | ||
| verticalAlignment = Alignment.CenterVertically, | ||
| ) { | ||
| PaginationRow( | ||
| showChevron = totalCount > TRACKER_SIZE, | ||
| hasNextPage = hasNextPage, | ||
| hasPreviousPage = hasPreviousPage, | ||
| onClickLeft = onClickLeft, | ||
| onClickRight = onClickRight, | ||
| ) | ||
|
|
||
| CountRow( | ||
| practicedCount = practicedCount, | ||
| totalCount = totalCount, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| private fun PaginationRow( | ||
| showChevron: Boolean, | ||
| hasNextPage: Boolean, | ||
| hasPreviousPage: Boolean, | ||
| onClickLeft: () -> Unit, | ||
| onClickRight: () -> Unit, | ||
| modifier: Modifier = Modifier, | ||
| ) { | ||
| Row( | ||
| modifier = modifier, | ||
| horizontalArrangement = Arrangement.spacedBy(PrezelTheme.spacing.V8), | ||
| verticalAlignment = Alignment.CenterVertically, | ||
| ) { | ||
| if (showChevron) { | ||
| Icon( | ||
| painter = painterResource(PrezelIcons.ChevronLeft), | ||
| contentDescription = stringResource(R.string.core_ui_impl_practice_card_prev_page), | ||
| tint = chevronIconTintColor(enabled = hasPreviousPage), | ||
| modifier = Modifier.noRippleClickable(onClickLeft), | ||
| ) | ||
| } | ||
|
|
||
| Text( | ||
| text = stringResource(R.string.core_ui_impl_practice_card_count_label), | ||
| style = PrezelTheme.typography.body3Medium, | ||
| color = PrezelTheme.colors.textMedium, | ||
| ) | ||
|
|
||
| if (showChevron) { | ||
| Icon( | ||
| painter = painterResource(PrezelIcons.ChevronRight), | ||
| contentDescription = stringResource(R.string.core_ui_impl_practice_card_next_page), | ||
| tint = chevronIconTintColor(enabled = hasNextPage), | ||
| modifier = Modifier.noRippleClickable(onClickRight), | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| private fun chevronIconTintColor(enabled: Boolean): Color = if (enabled) PrezelTheme.colors.iconRegular else PrezelTheme.colors.iconDisabled | ||
|
|
||
| @Composable | ||
| private fun CountRow( | ||
| practicedCount: Int, | ||
| totalCount: Int, | ||
| modifier: Modifier = Modifier, | ||
| ) { | ||
| Text( | ||
| text = buildAnnotatedString { | ||
| withStyle(style = SpanStyle(color = PrezelTheme.colors.textMedium)) { | ||
| append(practicedCount.toString()) | ||
| } | ||
| withStyle(style = SpanStyle(color = PrezelTheme.colors.textSmall)) { | ||
| append("/") | ||
| append(totalCount.toString()) | ||
| } | ||
| }, | ||
| style = PrezelTheme.typography.body3Medium, | ||
| modifier = modifier, | ||
| ) | ||
| } | ||
|
|
||
| @Composable | ||
| private fun PracticeTracker( | ||
| items: ImmutableList<TrackerItem>, | ||
| startIndex: Int, | ||
| modifier: Modifier = Modifier, | ||
| ) { | ||
| Row( | ||
| modifier = modifier.fillMaxWidth(), | ||
| horizontalArrangement = Arrangement.SpaceBetween, | ||
| ) { | ||
| items | ||
| .drop(startIndex) | ||
| .take(TRACKER_SIZE) | ||
| .forEach { item -> | ||
| PracticeStamp(date = item.date, type = item.type) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private fun ImmutableList<PracticeCardItem>.toTrackerItems(dDay: LocalDate): ImmutableList<TrackerItem> { | ||
| val blankCount = (TRACKER_SIZE - (size % TRACKER_SIZE)) | ||
| .takeIf { count -> count != TRACKER_SIZE } ?: 0 | ||
|
|
||
| val lastDate = lastOrNull()?.date ?: dDay | ||
|
|
||
| val blankItems = List(blankCount) { index -> | ||
| PracticeCardItem( | ||
| date = lastDate.plus(DatePeriod(days = index + 1)), | ||
| isPracticed = false, | ||
| ) | ||
| } | ||
|
|
||
| return (this + blankItems) | ||
| .map { item -> | ||
| TrackerItem( | ||
| date = item.date, | ||
| isPracticed = item.isPracticed, | ||
| type = when { | ||
| item.date >= dDay -> StampType.EMPTY | ||
| item.isPracticed -> StampType.AFTER | ||
| else -> StampType.BEFORE | ||
| }, | ||
| ) | ||
| }.toImmutableList() | ||
| } | ||
|
|
||
| @Composable | ||
| private fun PracticeStamp( | ||
| date: LocalDate, | ||
| type: StampType, | ||
| modifier: Modifier = Modifier, | ||
| ) { | ||
| Column( | ||
| modifier = modifier, | ||
| horizontalAlignment = Alignment.CenterHorizontally, | ||
| ) { | ||
| Text( | ||
| text = date.format(StampFormatter), | ||
| style = PrezelTheme.typography.caption2Regular, | ||
| color = type.textColor(), | ||
| ) | ||
| Spacer(modifier = Modifier.height(PrezelTheme.spacing.V2)) | ||
|
|
||
| Box( | ||
| modifier = Modifier | ||
| .size(32.dp) | ||
| .clip(PrezelTheme.shapes.V1000) | ||
| .background(color = type.bgColor()) | ||
| .applyDashBorder(type = type), | ||
| contentAlignment = Alignment.Center, | ||
| ) { | ||
| Icon( | ||
| painter = painterResource(PrezelIcons.Check), | ||
| contentDescription = null, | ||
| tint = type.tintColor(), | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| private fun StampType.textColor(): Color = | ||
| when (this) { | ||
| StampType.EMPTY -> PrezelTheme.colors.textDisabled | ||
| StampType.AFTER, | ||
| StampType.BEFORE, | ||
| -> PrezelTheme.colors.textRegular | ||
| } | ||
|
|
||
| @Composable | ||
| private fun StampType.bgColor(): Color = | ||
| when (this) { | ||
| StampType.AFTER -> PrezelTheme.colors.interactiveRegular | ||
| StampType.BEFORE -> PrezelTheme.colors.bgLarge | ||
| StampType.EMPTY -> PrezelTheme.colors.bgDisabled | ||
| } | ||
|
|
||
| @Composable | ||
| private fun StampType.tintColor(): Color = | ||
| when (this) { | ||
| StampType.AFTER -> PrezelTheme.colors.solidWhite | ||
| StampType.BEFORE -> PrezelTheme.colors.iconDisabled | ||
| StampType.EMPTY -> Color.Transparent | ||
| } | ||
|
|
||
| @Composable | ||
| private fun Modifier.applyDashBorder(type: StampType): Modifier { | ||
| if (type != StampType.BEFORE) return this | ||
| val density = LocalDensity.current | ||
|
|
||
| return drawDashBorder( | ||
| shape = PrezelTheme.shapes.V1000, | ||
| color = PrezelTheme.colors.borderMedium, | ||
| width = with(density) { 1.dp.toPx() }, | ||
| interval = with(density) { 2.dp.toPx() }, | ||
| ) | ||
| } | ||
|
|
||
| @BasicPreview | ||
| @Composable | ||
| private fun PracticeCardPreview() { | ||
| val baseDate = LocalDate(year = 2026, month = 3, day = 20) | ||
| val dDay = LocalDate(year = 2026, month = 3, day = 30) | ||
|
|
||
| PrezelTheme { | ||
| Box(modifier = Modifier.padding(16.dp)) { | ||
| PracticeCard( | ||
| dDay = dDay, | ||
| items = List(baseDate.daysUntil(dDay)) { index -> | ||
| PracticeCardItem( | ||
| date = baseDate.plus(DatePeriod(days = index)), | ||
| isPracticed = index % 2 == 0, | ||
| ) | ||
| }.toPersistentList(), | ||
| ) | ||
| } | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.