Skip to content

Commit

Permalink
SessionDetail 화면 개선
Browse files Browse the repository at this point in the history
- AttendanceType을 UI가 아닌 SessionDetailViewModel 에서 연산하도록 함
  • Loading branch information
toastmeister1 committed May 4, 2024
1 parent cbc0967 commit e7b7161
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.tween
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
Expand Down Expand Up @@ -54,14 +55,13 @@ import com.yapp.common.theme.AttendanceTheme
import com.yapp.common.theme.AttendanceTypography
import com.yapp.common.yds.YDSAppBar
import com.yapp.common.yds.YDSAttendanceList
import com.yapp.common.yds.YDSAttendanceType
import com.yapp.common.yds.YDSEmptyScreen
import com.yapp.common.yds.YDSProgressBar
import com.yapp.domain.model.Attendance
import com.yapp.domain.model.Session
import com.yapp.domain.model.types.NeedToAttendType
import com.yapp.domain.util.DateUtil
import com.yapp.presentation.R
import com.yapp.presentation.util.attendance.checkSessionAttendance

@Composable
fun MemberScore(
Expand Down Expand Up @@ -92,7 +92,6 @@ fun MemberScore(
navigateToSessionDetail = navigateToSessionDetail
)
}

}
}

Expand Down Expand Up @@ -130,8 +129,13 @@ fun MemberScoreScreen(
.background(AttendanceTheme.colors.backgroundColors.background)
)
}
items(uiState.attendanceList) { attendanceInfo ->
AttendUserSession(attendanceInfo, navigateToSessionDetail)

items(uiState.attendanceList) { (session, attendanceType) ->
AttendUserSession(
session = session,
attendanceType = attendanceType,
navigateToSessionDetail = navigateToSessionDetail,
)
}
}
}
Expand All @@ -155,9 +159,7 @@ private fun HelpIcon(navigateToHelpScreen: () -> Unit) {
.align(Alignment.TopEnd)
.padding(top = 18.dp, end = 14.dp)
.clip(CircleShape)
.clickable {
navigateToHelpScreen()
}
.clickable { navigateToHelpScreen() }
.padding(10.dp),
)
}
Expand Down Expand Up @@ -193,23 +195,15 @@ fun SemiCircleProgressBar(score: Int) {
Column(
verticalArrangement = Arrangement.Center,
) {
BoxWithConstraints(
modifier = Modifier
.padding(start = 64.dp, end = 64.dp),
) {

BoxWithConstraints(modifier = Modifier.padding(start = 64.dp, end = 64.dp)) {
val gray200 = AttendanceTheme.colors.grayScale.Gray200
val etcGreen = AttendanceTheme.colors.etcColors.EtcGreen
val etcYellow = AttendanceTheme.colors.etcColors.EtcYellow
val etcRed = AttendanceTheme.colors.etcColors.EtcRed

androidx.compose.foundation.Canvas(
modifier = Modifier
.size(maxWidth, (maxWidth.value / 2).dp)
) {

Canvas(modifier = Modifier.size(maxWidth, (maxWidth.value / 2).dp)) {
val arcColor = fillColorByUserScore(score).let { score ->
when(score) {
when (score) {
Score.GOOD -> etcGreen
Score.NORMAL -> etcYellow
Score.DANGEROUS -> etcRed
Expand All @@ -225,7 +219,6 @@ fun SemiCircleProgressBar(score: Int) {
style = Stroke(width = 25f, cap = StrokeCap.Round)
)


drawArc(
color = arcColor,
startAngle = 180f,
Expand Down Expand Up @@ -334,19 +327,12 @@ fun RowScope.AttendanceCell(

@Composable
private fun AttendUserSession(
attendanceInfo: Pair<Session, Attendance>,
session: Session,
attendanceType: YDSAttendanceType,
navigateToSessionDetail: (Int) -> Unit
) {
val dateUtil = remember { DateUtil() }
val session = attendanceInfo.first
val attendance = attendanceInfo.second

YDSAttendanceList(
attendanceType = checkSessionAttendance(
session = session,
attendance = attendance,
isPastSession = with(dateUtil) { currentTime isAfterFrom session.startTime }
),
attendanceType = attendanceType,
date = session.monthAndDay,
title = session.title,
description = session.description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package com.yapp.presentation.ui.member.score
import com.yapp.common.base.UiEvent
import com.yapp.common.base.UiSideEffect
import com.yapp.common.base.UiState
import com.yapp.common.yds.YDSAttendanceType
import com.yapp.domain.model.Attendance
import com.yapp.domain.model.Session

class MemberScoreContract {
data class MemberScoreUiState(
val loadState: LoadState = LoadState.Loading,
val attendanceList: List<Pair<Session, Attendance>> = emptyList(),
val lastAttendanceList: List<Pair<Session, Attendance>> = emptyList(),
val attendanceList: List<Pair<Session, YDSAttendanceType>> = emptyList(),
val lastAttendanceList: List<Pair<Session, Attendance>> = emptyList()
) : UiState {
enum class LoadState {
Loading, Idle, Error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package com.yapp.presentation.ui.member.score

import androidx.lifecycle.viewModelScope
import com.yapp.common.base.BaseViewModel
import com.yapp.domain.usecases.GetCurrentTimeUseCase
import com.yapp.domain.usecases.GetMemberAttendanceListUseCase
import com.yapp.domain.util.DateUtil
import com.yapp.presentation.common.AttendanceTypeMapper
import com.yapp.presentation.ui.member.score.MemberScoreContract.MemberScoreUiEvent
import com.yapp.presentation.ui.member.score.MemberScoreContract.MemberScoreUiSideEffect
import com.yapp.presentation.ui.member.score.MemberScoreContract.MemberScoreUiState
Expand All @@ -15,7 +16,8 @@ import javax.inject.Inject
@HiltViewModel
class MemberScoreViewModel @Inject constructor(
private val getMemberAttendanceListUseCase: GetMemberAttendanceListUseCase,
private val dateUtil: DateUtil
private val getCurrentTimeUseCase: GetCurrentTimeUseCase,
private val attendanceTypeMapper: AttendanceTypeMapper
) : BaseViewModel<MemberScoreUiState, MemberScoreUiSideEffect, MemberScoreUiEvent>(initialState = MemberScoreUiState()) {

init {
Expand All @@ -31,13 +33,23 @@ class MemberScoreViewModel @Inject constructor(
return@onSuccess
}

val attendanceList = sessions zip attendances
val currentTime = getCurrentTimeUseCase()
val attendanceList = (sessions zip attendances).map { (session, attendance) ->
val attendanceType = attendanceTypeMapper.map(
sessionType = session.type,
attendanceStatus = attendance.status,
isPastSession = currentTime.isAfter(session.startTime)
)

session to attendanceType
}

setState {
copy(
loadState = MemberScoreUiState.LoadState.Idle,
attendanceList = attendanceList,
lastAttendanceList = attendanceList.filter { (session, _) ->
with(dateUtil) { currentTime isAfterFrom session.startTime }
lastAttendanceList = (sessions zip attendances).filter { (session, _) ->
currentTime.isAfter(session.startTime)
}
)
}
Expand Down

0 comments on commit e7b7161

Please sign in to comment.