-
Notifications
You must be signed in to change notification settings - Fork 0
[Feature/#5] : 소요시간 이하 입력 방지 #6
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
Changes from all commits
a77c022
c3edbf2
5d2b34d
9a8f312
321ea6a
8f3dc48
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package com.sopt.core.designsystem.component.checkbox | ||
|
|
||
| import androidx.compose.foundation.background | ||
| import androidx.compose.foundation.border | ||
| import androidx.compose.foundation.layout.PaddingValues | ||
| import androidx.compose.foundation.layout.Row | ||
| import androidx.compose.foundation.layout.fillMaxWidth | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.foundation.layout.wrapContentHeight | ||
| import androidx.compose.foundation.shape.RoundedCornerShape | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.graphics.Color | ||
| import androidx.compose.ui.text.TextStyle | ||
| import androidx.compose.ui.tooling.preview.Preview | ||
| import androidx.compose.ui.unit.dp | ||
| import com.sopt.core.designsystem.theme.NoostakAndroidTheme | ||
| import com.sopt.core.designsystem.theme.NoostakTheme | ||
| import com.sopt.core.extension.noRippleClickable | ||
|
|
||
| @Composable | ||
| fun NoostakCheckbox( | ||
| modifier: Modifier = Modifier, | ||
| text: String = "", | ||
| isChecked: Boolean = false, | ||
| onCheckedChange: (Boolean) -> Unit = {}, | ||
| textStyle: TextStyle = NoostakTheme.typography.b4SemiBold, | ||
| borderColor: Color = NoostakTheme.colors.gray500, | ||
| backgroundColorChecked: Color = NoostakTheme.colors.gray50, | ||
| backgroundColorUnchecked: Color = NoostakTheme.colors.white, | ||
| paddingValues: PaddingValues = PaddingValues(horizontal = 12.dp, vertical = 15.dp) | ||
| ) { | ||
| Row( | ||
| modifier = modifier | ||
| .fillMaxWidth() | ||
| .wrapContentHeight() | ||
| .border( | ||
| width = 0.5.dp, | ||
| color = borderColor, | ||
| shape = RoundedCornerShape(10.dp) | ||
| ) | ||
| .background( | ||
| color = if (isChecked) backgroundColorChecked else backgroundColorUnchecked, | ||
| shape = RoundedCornerShape(10.dp) | ||
| ) | ||
| .noRippleClickable { onCheckedChange(!isChecked) } | ||
| .padding(paddingValues), | ||
| verticalAlignment = Alignment.CenterVertically | ||
| ) { | ||
| Text( | ||
| text = text, | ||
| modifier = Modifier.weight(1f), | ||
| style = textStyle, | ||
| color = NoostakTheme.colors.gray900 | ||
| ) | ||
| CircularCheckbox( | ||
| isChecked = isChecked, | ||
| onCheckedChange = { onCheckedChange(it) } | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| @Preview(showBackground = true) | ||
| @Composable | ||
| fun NoostakCheckboxPreview() { | ||
| NoostakAndroidTheme { | ||
| NoostakCheckbox( | ||
| isChecked = true, | ||
| text = "체크박스블라블라" | ||
|
Contributor
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. P3: 이거 뭔디 ㅋㅋㅋㅋㅋ |
||
| ) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,8 +5,11 @@ import androidx.compose.animation.slideInVertically | |
| import androidx.compose.animation.slideOutVertically | ||
| import androidx.compose.foundation.layout.Box | ||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.PaddingValues | ||
| import androidx.compose.foundation.layout.Spacer | ||
| import androidx.compose.foundation.layout.fillMaxSize | ||
| import androidx.compose.foundation.layout.fillMaxWidth | ||
| import androidx.compose.foundation.layout.height | ||
| import androidx.compose.foundation.layout.navigationBarsPadding | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.foundation.layout.statusBarsPadding | ||
|
|
@@ -34,6 +37,7 @@ import androidx.compose.ui.zIndex | |
| import androidx.hilt.navigation.compose.hiltViewModel | ||
| import androidx.lifecycle.compose.collectAsStateWithLifecycle | ||
| import com.sopt.core.designsystem.component.button.NoostakBottomButton | ||
| import com.sopt.core.designsystem.component.checkbox.NoostakCheckbox | ||
| import com.sopt.core.designsystem.component.dialog.NoostakDialog | ||
| import com.sopt.core.designsystem.component.snackbar.NoostakSnackBar | ||
| import com.sopt.core.designsystem.component.snackbar.SNACK_BAR_DURATION | ||
|
|
@@ -62,6 +66,7 @@ fun AppointmentCheckRoute( | |
| val context = LocalContext.current | ||
| val showErrorDialog by appointmentCheckViewModel.showErrorDialog.collectAsStateWithLifecycle() | ||
| var selectedData by remember { mutableStateOf(emptyList<TimeEntity>()) } | ||
| var isChecked by remember { mutableStateOf(false) } | ||
| val rememberedAvailablePeriods = remember { availablePeriods } | ||
| val snackBarHostState = remember { SnackbarHostState() } | ||
| val coroutineScope = rememberCoroutineScope() | ||
|
|
@@ -99,7 +104,7 @@ fun AppointmentCheckRoute( | |
| ) | ||
|
|
||
| is AppointmentCheckSideEffect.ShowSnackBar -> onShowFailureSnackBar( | ||
| context.getString(sideEffect.message) | ||
| context.getString(sideEffect.message, duration / 60) | ||
| ) | ||
| } | ||
| } | ||
|
|
@@ -109,16 +114,31 @@ fun AppointmentCheckRoute( | |
| groupId = groupId, | ||
| appointmentName = appointmentName, | ||
| availablePeriods = rememberedAvailablePeriods, | ||
| onSelectedDataChange = { selectedData = it }, | ||
| onSelectedDataChange = { | ||
| selectedData = it | ||
| if (it.isNotEmpty()) isChecked = false | ||
| }, | ||
| duration = duration, | ||
| isChecked = isChecked, | ||
| onCheckedChange = { | ||
| isChecked = it | ||
| if (isChecked) selectedData = emptyList() | ||
|
Contributor
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. P3: 오호 체크 박스 선택 시 이렇게 초기화했구나! 베리굿! |
||
| }, | ||
| onBackButtonClick = appointmentCheckViewModel::navigateToGroupDetail, | ||
| onConfirmButtonClick = { | ||
| // TODO: selectedData가 duration 이하인지 체크하는 로직 추가 | ||
| appointmentCheckViewModel.postTimeTable( | ||
| groupId, | ||
| appointmentId, | ||
| appointmentName, | ||
| selectedData | ||
| ) | ||
| if (appointmentCheckViewModel.isSelectedDataValid( | ||
| duration / 60, | ||
| selectedData, | ||
| isChecked | ||
| ) | ||
| ) { | ||
| appointmentCheckViewModel.postTimeTable( | ||
| groupId, | ||
| appointmentId, | ||
| appointmentName, | ||
| selectedData | ||
| ) | ||
| } | ||
| }, | ||
| snackBarHostState = snackBarHostState, | ||
| snackBarVisible = snackBarVisible | ||
|
|
@@ -149,6 +169,9 @@ fun AppointmentCheckScreen( | |
| appointmentName: String, | ||
| availablePeriods: List<TimeEntity>, | ||
| onSelectedDataChange: (List<TimeEntity>) -> Unit = {}, | ||
| duration: Long, | ||
| isChecked: Boolean = false, | ||
| onCheckedChange: (Boolean) -> Unit = {}, | ||
| onBackButtonClick: (Long) -> Unit, | ||
| onConfirmButtonClick: () -> Unit, | ||
| snackBarHostState: SnackbarHostState, | ||
|
|
@@ -199,15 +222,27 @@ fun AppointmentCheckScreen( | |
| ) { | ||
| Text( | ||
| modifier = Modifier | ||
| .padding(top = 11.dp, start = 6.dp, bottom = 16.dp), | ||
| text = stringResource(R.string.title_appointment_check), | ||
| .padding(vertical = 12.dp), | ||
| text = stringResource(R.string.title_appointment_check, duration / 60), | ||
| color = NoostakTheme.colors.black, | ||
| style = NoostakTheme.typography.h4Bold, | ||
| textAlign = TextAlign.Start | ||
| ) | ||
| NoostakCheckbox( | ||
| text = stringResource(R.string.cb_appointment_check_impossible), | ||
| isChecked = isChecked, | ||
| onCheckedChange = { | ||
| onCheckedChange(it) | ||
| }, | ||
| textStyle = NoostakTheme.typography.b5Regular, | ||
| borderColor = NoostakTheme.colors.gray200, | ||
| paddingValues = PaddingValues(horizontal = 12.dp, vertical = 14.dp) | ||
| ) | ||
| Spacer(modifier = Modifier.height(16.dp)) | ||
| NoostakEditableTimeTable( | ||
| availablePeriods = availablePeriods, | ||
| modifier = Modifier.fillMaxWidth() | ||
| modifier = Modifier.fillMaxWidth(), | ||
| isChecked = isChecked | ||
| ) { | ||
| onSelectedDataChange(it) | ||
| Timber.d("selectedData: $it") | ||
|
|
@@ -251,6 +286,7 @@ fun PreviewAppointmentConfirmScreen() { | |
| endTime = "2024-09-07T18:00:00" | ||
| ) | ||
| ), | ||
| duration = 360, | ||
| onBackButtonClick = {}, | ||
| onConfirmButtonClick = {}, | ||
| snackBarHostState = SnackbarHostState(), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,13 +6,16 @@ import com.sopt.core.type.DialogType | |
| import com.sopt.core.util.BaseViewModel | ||
| import com.sopt.domain.entity.TimeEntity | ||
| import com.sopt.domain.repository.AppointmentConfirmRepository | ||
| import com.sopt.presentation.R | ||
| import dagger.hilt.android.lifecycle.HiltViewModel | ||
| import kotlinx.coroutines.flow.MutableStateFlow | ||
| import kotlinx.coroutines.flow.StateFlow | ||
| import kotlinx.coroutines.flow.asStateFlow | ||
| import kotlinx.coroutines.flow.update | ||
| import kotlinx.coroutines.launch | ||
| import java.io.IOException | ||
| import java.time.Duration | ||
| import java.time.LocalDateTime | ||
| import javax.inject.Inject | ||
|
|
||
| @HiltViewModel | ||
|
|
@@ -71,6 +74,46 @@ class AppointmentCheckViewModel @Inject constructor( | |
| } | ||
| } | ||
|
|
||
| fun isSelectedDataValid(duration: Long, selectedDate: List<TimeEntity>, isChecked: Boolean): Boolean { | ||
| if (isChecked) { | ||
| return true | ||
| } | ||
|
|
||
| if (selectedDate.isEmpty()) { | ||
| emitSideEffect(AppointmentCheckSideEffect.ShowSnackBar(R.string.sb_appointment_check_invalid)) | ||
| return false | ||
| } | ||
|
|
||
| val sorted = selectedDate.sortedBy { LocalDateTime.parse(it.startTime) } | ||
|
Contributor
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. P3: 시간 정렬하는 방법 너무 좋은디! |
||
| var currentStart = LocalDateTime.parse(sorted.first().startTime) | ||
| var currentEnd = LocalDateTime.parse(sorted.first().endTime) | ||
|
|
||
| for (i in 1 until sorted.size) { | ||
| val nextStart = LocalDateTime.parse(sorted[i].startTime) | ||
| val nextEnd = LocalDateTime.parse(sorted[i].endTime) | ||
|
|
||
| if (nextStart == currentEnd) { | ||
| currentEnd = nextEnd | ||
| } else { | ||
| // 블록이 끊기면 검사 | ||
| val blockDuration = Duration.between(currentStart, currentEnd).toHours() | ||
| if (blockDuration < duration) { | ||
| emitSideEffect(AppointmentCheckSideEffect.ShowSnackBar(R.string.sb_appointment_check_invalid)) | ||
| return false | ||
| } | ||
| currentStart = nextStart | ||
| currentEnd = nextEnd | ||
| } | ||
| } | ||
|
Comment on lines
+91
to
+107
Contributor
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. P3: 오 이렇게 연속 여부 판단했구나 대단한디?
Contributor
Author
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. 지피티는 정말 대단한 친구야 흙흙 |
||
| val finalBlockDuration = Duration.between(currentStart, currentEnd).toHours() | ||
| if (finalBlockDuration < duration) { | ||
| emitSideEffect(AppointmentCheckSideEffect.ShowSnackBar(R.string.sb_appointment_check_invalid)) | ||
| return false | ||
| } | ||
|
Comment on lines
+108
to
+112
Contributor
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. P3: 마지막 블록까지 꼼꼼히 체크한 거 너무 좋습니다! |
||
|
|
||
| return true | ||
| } | ||
|
|
||
| fun showErrorDialog(show: Boolean, dialogType: DialogType) { | ||
| _showErrorDialog.update { it.copy(first = show, second = dialogType) } | ||
| } | ||
|
|
@@ -79,16 +122,6 @@ class AppointmentCheckViewModel @Inject constructor( | |
| emitSideEffect(AppointmentCheckSideEffect.NavigateUp) | ||
| } | ||
|
|
||
| fun navigateToAppointment(groupId: Long, appointmentId: Long, appointmentName: String) { | ||
| emitSideEffect( | ||
| AppointmentCheckSideEffect.NavigateToAppointment( | ||
| groupId, | ||
| appointmentId, | ||
| appointmentName | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| fun navigateToGroupDetail(groupId: Long) { | ||
| emitSideEffect(AppointmentCheckSideEffect.NavigateToGroupDetail(groupId)) | ||
| } | ||
|
|
||
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.
P3: 체크박스 컴포넌트로 따로 빼놓은거 너무 좋습니다!
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.
P3 : 히히 체크박스도 생겻다 감사함니두