diff --git a/feature/src/main/java/com/terning/feature/dialog/detail/ScrapDialog.kt b/feature/src/main/java/com/terning/feature/dialog/detail/ScrapDialog.kt index e160aea7a..6432d0d5a 100644 --- a/feature/src/main/java/com/terning/feature/dialog/detail/ScrapDialog.kt +++ b/feature/src/main/java/com/terning/feature/dialog/detail/ScrapDialog.kt @@ -59,17 +59,18 @@ fun ScrapDialog( title: String, scrapColor: Color, deadline: String, - startYear: Int, - startMonth: Int, + startYear: Int = 0, + startMonth: Int = 0, + startDate: String = "", workingPeriod: String, - scrapId: Long, - internshipAnnouncementId: Long, + scrapId: Long = -1, + internshipAnnouncementId: Long = -1, companyImage: String, isScrapped: Boolean, onDismissRequest: () -> Unit, - onClickChangeColor: () -> Unit, - onClickNavigateButton: (Long) -> Unit, - viewModel: ScrapDialogViewModel = hiltViewModel() + onClickChangeColor: () -> Unit = {}, + onClickNavigateButton: (Long) -> Unit = {}, + viewModel: ScrapDialogViewModel = hiltViewModel(), ) { val context = LocalContext.current val lifecycleOwner = LocalLifecycleOwner.current @@ -81,6 +82,7 @@ fun ScrapDialog( is ScrapDialogSideEffect.ShowToast -> { context.toast(sideEffect.message) } + is ScrapDialogSideEffect.DismissDialog -> { viewModel.initUiState() onDismissRequest() @@ -110,6 +112,7 @@ fun ScrapDialog( deadline = deadline, startYear = startYear, startMonth = startMonth, + startDate = startDate, workingPeriod = workingPeriod, isScrapped = isScrapped, companyImage = companyImage, @@ -118,8 +121,8 @@ fun ScrapDialog( isColorChangedOnce = uiState.isColorChangedOnce, onClickColorButton = viewModel::changeSelectedColor, onClickColorChangeButton = { - if(uiState.isColorChanged) - viewModel.patchScrap(scrapId = scrapId, color = uiState.selectedColorType) + if (uiState.isColorChanged) + viewModel.patchScrap(scrapId = scrapId, color = uiState.selectedColorType) }, onClickNavigateButton = viewModel::navigateToDetail, onClickScrapButton = { @@ -136,6 +139,7 @@ private fun ScrapDialogScreen( deadline: String, startYear: Int, startMonth: Int, + startDate: String, workingPeriod: String, isScrapped: Boolean, companyImage: String, @@ -145,7 +149,7 @@ private fun ScrapDialogScreen( onClickColorButton: (ColorType) -> Unit, onClickNavigateButton: () -> Unit, onClickColorChangeButton: () -> Unit, - onClickScrapButton: () -> Unit + onClickScrapButton: () -> Unit, ) { Box( modifier = Modifier @@ -176,6 +180,7 @@ private fun ScrapDialogScreen( ) Spacer(modifier = Modifier.height(15.dp)) + Box( modifier = Modifier .height(TerningTheme.typography.title4.getFixHeightByMaxLine(3)) @@ -250,10 +255,17 @@ private fun ScrapDialogScreen( title = stringResource(id = R.string.intern_info_working), value = workingPeriod ) - InternInfoRow( - title = stringResource(id = R.string.intern_info_start_date), - value = "${startYear}년 ${startMonth}월" - ) + if (startDate == "") { + InternInfoRow( + title = stringResource(id = R.string.intern_info_start_date), + value = "${startYear}년 ${startMonth}월" + ) + } else { + InternInfoRow( + title = stringResource(id = R.string.intern_info_start_date), + value = startDate + ) + } } } @@ -277,7 +289,7 @@ private fun ScrapDialogScreen( @Composable private fun NewScrapButton( onClickScrapButton: () -> Unit, - modifier: Modifier = Modifier + modifier: Modifier = Modifier, ) { RoundButton( style = TerningTheme.typography.button3, @@ -295,7 +307,7 @@ private fun DetailScrapButton( isColorChangedOnce: Boolean, onClickNavigateButton: () -> Unit, onClickColorChangeButton: () -> Unit, - modifier: Modifier = Modifier + modifier: Modifier = Modifier, ) { Row( modifier = modifier @@ -329,6 +341,7 @@ private fun ScrapDialogPreview() { deadline = "2024/09/07", startYear = 2024, startMonth = 11, + startDate = "", workingPeriod = "2개월", companyImage = "", isScrapped = false, diff --git a/feature/src/main/java/com/terning/feature/intern/InternRoute.kt b/feature/src/main/java/com/terning/feature/intern/InternRoute.kt index b5b1effc5..669b5c0e6 100644 --- a/feature/src/main/java/com/terning/feature/intern/InternRoute.kt +++ b/feature/src/main/java/com/terning/feature/intern/InternRoute.kt @@ -22,8 +22,8 @@ import androidx.lifecycle.compose.LocalLifecycleOwner import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.flowWithLifecycle import androidx.navigation.NavHostController -import com.terning.core.designsystem.component.dialog.TerningBasicDialog import com.terning.core.designsystem.component.topappbar.BackButtonTopAppBar +import com.terning.core.designsystem.theme.CalRed import com.terning.core.designsystem.theme.Grey200 import com.terning.core.designsystem.theme.Grey400 import com.terning.core.designsystem.theme.TerningTheme @@ -32,6 +32,8 @@ import com.terning.core.extension.toast import com.terning.core.state.UiState import com.terning.domain.entity.intern.InternInfo import com.terning.feature.R +import com.terning.feature.dialog.cancel.ScrapCancelDialog +import com.terning.feature.dialog.detail.ScrapDialog import com.terning.feature.intern.component.InternBottomBar import com.terning.feature.intern.component.InternCompanyInfo import com.terning.feature.intern.component.InternInfoRow @@ -43,7 +45,7 @@ import java.text.DecimalFormat @Composable fun InternRoute( announcementId: Long = 0, - modifier: Modifier = Modifier, + modifier: Modifier, viewModel: InternViewModel = hiltViewModel(), navController: NavHostController, ) { @@ -74,7 +76,19 @@ fun InternRoute( internUiState = internState, modifier = modifier, internInfo = (internState.loadState as UiState.Success).data, - navController = navController + navController = navController, + onDismissCancelDialog = { + viewModel.updateScrapDialogVisibility(false) + }, + onDismissInternDialog = { + viewModel.updateScrapDialogVisibility(false) + }, + onClickScrapButton = { detail -> + with(viewModel) { + updateInternshipModel(detail) + updateScrapDialogVisibility(true) + } + } ) } } @@ -87,6 +101,9 @@ fun InternScreen( viewModel: InternViewModel = hiltViewModel(), internUiState: InternUiState, internInfo: InternInfo, + onDismissCancelDialog: (Boolean) -> Unit, + onDismissInternDialog: () -> Unit, + onClickScrapButton: (InternInfo) -> Unit, ) { val decimal = DecimalFormat("#,###") @@ -231,16 +248,29 @@ fun InternScreen( scrapCount = decimal.format(internInfo.scrapCount), scrapId = internInfo.scrapId, onScrapClick = { - viewModel.updateScrapDialogVisible(true) + viewModel.updateScrapDialogVisibility(true) } ) - if (internUiState.isScrapDialogVisible) { - TerningBasicDialog( - onDismissRequest = { - viewModel.updateScrapDialogVisible(false) - }, - content = {}, + if (internUiState.isCancelDialogVisibility) { + internUiState.scrapId?.run { + ScrapCancelDialog( + scrapId = this, + onDismissRequest = onDismissCancelDialog + ) + } + } + + if (internUiState.isScrapDialogVisibility) { + ScrapDialog( + title = internInfo.title, + scrapColor = CalRed, + deadline = internInfo.deadline, + startDate = internInfo.startDate, + workingPeriod = internInfo.workingPeriod, + companyImage = internInfo.companyImage, + isScrapped = internUiState.isScrappedState, + onDismissRequest = onDismissInternDialog, ) } } diff --git a/feature/src/main/java/com/terning/feature/intern/InternViewModel.kt b/feature/src/main/java/com/terning/feature/intern/InternViewModel.kt index 7322223a9..ab7636caf 100644 --- a/feature/src/main/java/com/terning/feature/intern/InternViewModel.kt +++ b/feature/src/main/java/com/terning/feature/intern/InternViewModel.kt @@ -1,10 +1,10 @@ package com.terning.feature.intern -import androidx.compose.ui.graphics.Color import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.terning.core.state.UiState import com.terning.domain.entity.CalendarScrapRequest +import com.terning.domain.entity.intern.InternInfo import com.terning.domain.repository.InternRepository import com.terning.domain.repository.ScrapRepository import com.terning.feature.R @@ -60,7 +60,7 @@ class InternViewModel @Inject constructor( it.copy(isScrap = UiState.Success(true)) } getInternInfo(id) - updateScrapDialogVisible(false) + updateScrapDialogVisibility(false) _sideEffect.emit( InternViewSideEffect.Toast(R.string.intern_scrap_add_toast_message) ) @@ -85,7 +85,7 @@ class InternViewModel @Inject constructor( it.copy(isScrap = UiState.Success(false)) } getInternInfo(announcementId) - updateScrapDialogVisible(false) + updateScrapDialogVisibility(false) _sideEffect.emit(InternViewSideEffect.Toast(R.string.intern_scrap_delete_toast_message)) }.onFailure { _sideEffect.emit( @@ -96,27 +96,23 @@ class InternViewModel @Inject constructor( } } - fun updateSelectColor(newColor: Color) { + fun updateCancelDialogVisibility(visible: Boolean) { _internUiState.update { - it.copy(selectedColor = newColor) + it.copy(isCancelDialogVisibility = visible) } } - fun updateScrapDialogVisible(visible: Boolean) { + fun updateScrapDialogVisibility(visible: Boolean) { _internUiState.update { - it.copy(isScrapDialogVisible = visible) + it.copy(isScrapDialogVisibility = visible) } } - fun updatePaletteOpen(open: Boolean) { - _internUiState.update { - it.copy(isPaletteOpen = open) - } - } - - fun updateColorChange(change: Boolean) { - _internUiState.update { - it.copy(isColorChange = change) + fun updateInternshipModel(scrapDetailModel: InternInfo?) { + _internUiState.update { currentState -> + currentState.copy( + internshipModel = scrapDetailModel + ) } } diff --git a/feature/src/main/java/com/terning/feature/intern/component/ScrapDialogContent.kt b/feature/src/main/java/com/terning/feature/intern/component/ScrapDialogContent.kt deleted file mode 100644 index 3746f5f13..000000000 --- a/feature/src/main/java/com/terning/feature/intern/component/ScrapDialogContent.kt +++ /dev/null @@ -1,250 +0,0 @@ -package com.terning.feature.intern.component - -import androidx.compose.foundation.background -import androidx.compose.foundation.border -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.foundation.layout.wrapContentSize -import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material3.HorizontalDivider -import androidx.compose.material3.Icon -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.draw.clip -import androidx.compose.ui.layout.ContentScale -import androidx.compose.ui.platform.LocalContext -import androidx.compose.ui.res.painterResource -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.style.TextAlign -import androidx.compose.ui.text.style.TextOverflow -import androidx.compose.ui.unit.dp -import androidx.hilt.navigation.compose.hiltViewModel -import androidx.lifecycle.compose.collectAsStateWithLifecycle -import coil.compose.AsyncImage -import coil.request.ImageRequest -import com.terning.core.R -import com.terning.core.designsystem.component.button.RoundButton -import com.terning.core.designsystem.component.item.ColorPalette -import com.terning.core.designsystem.theme.CalBlue1 -import com.terning.core.designsystem.theme.CalBlue2 -import com.terning.core.designsystem.theme.CalGreen1 -import com.terning.core.designsystem.theme.CalGreen2 -import com.terning.core.designsystem.theme.CalOrange1 -import com.terning.core.designsystem.theme.CalOrange2 -import com.terning.core.designsystem.theme.CalPink -import com.terning.core.designsystem.theme.CalPurple -import com.terning.core.designsystem.theme.CalRed -import com.terning.core.designsystem.theme.CalYellow -import com.terning.core.designsystem.theme.Grey200 -import com.terning.core.designsystem.theme.Grey350 -import com.terning.core.designsystem.theme.Grey500 -import com.terning.core.designsystem.theme.TerningMain -import com.terning.core.designsystem.theme.TerningTheme -import com.terning.core.designsystem.theme.White -import com.terning.core.extension.noRippleClickable -import com.terning.feature.intern.InternViewModel - - -@Composable -fun ScrapDialogContent( - internInfoList: List>, - viewModel: InternViewModel = hiltViewModel(), - dDay: String, - companyImage: String, - title: String, - announcementId: Long, - type: Int, -) { - val state by viewModel.internUiState.collectAsStateWithLifecycle() - - val colorList = listOf( - CalRed, - CalOrange1, - CalOrange2, - CalYellow, - CalGreen1, - CalGreen2, - CalBlue1, - CalBlue2, - CalPurple, - CalPink - ) - - Column( - modifier = Modifier - .wrapContentSize() - .padding(horizontal = 11.dp) - .padding(top = 32.dp), - horizontalAlignment = Alignment.CenterHorizontally - ) { - AsyncImage( - model = ImageRequest.Builder(LocalContext.current) - .data(companyImage) - .build(), - contentDescription = stringResource(R.string.image_content_descriptin), - modifier = Modifier - .size(80.dp) - .border( - width = 1.dp, - color = TerningMain, - shape = RoundedCornerShape(size = 15.dp) - ) - .clip(RoundedCornerShape(size = 15.dp)), - contentScale = ContentScale.Fit, - alignment = Alignment.Center - ) - - Text( - text = title, - textAlign = TextAlign.Center, - style = TerningTheme.typography.title4, - color = Grey500, - modifier = Modifier.padding(top = 20.dp), - maxLines = 3, - overflow = TextOverflow.Ellipsis - ) - Text( - text = stringResource(id = R.string.dialog_content_scrap_sub_title), - style = TerningTheme.typography.body5, - color = Grey350, - modifier = Modifier.padding( - top = 4.dp - ) - ) - Spacer(modifier = Modifier.height(26.dp)) - Column( - horizontalAlignment = Alignment.Start, - verticalArrangement = Arrangement.Top, - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 13.dp) - ) { - Row( - modifier = Modifier - .background( - color = state.selectedColor, - shape = RoundedCornerShape(14.dp) - ) - .noRippleClickable { - viewModel.updatePaletteOpen(!state.isPaletteOpen) - }, - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.Start - ) { - Text( - text = stringResource(id = R.string.dialog_content_color_button), - style = TerningTheme.typography.body5, - color = White, - modifier = Modifier.padding( - start = 13.dp, - top = 5.dp, - bottom = 5.dp - ) - ) - Icon( - painter = painterResource( - id = if (state.isPaletteOpen) R.drawable.ic_up_22 - else R.drawable.ic_down_22 - ), - contentDescription = stringResource( - id = R.string.dialog_content_color_button - ), - tint = White, - modifier = Modifier.padding( - end = 7.dp - ) - ) - } - HorizontalDivider( - thickness = 1.dp, - color = Grey200, - modifier = Modifier.padding( - top = 11.dp, - bottom = 8.dp - ) - ) - if (state.isPaletteOpen) { - Box( - modifier = Modifier - .fillMaxWidth() - .padding( - top = 12.dp, - bottom = 23.dp, - ), - contentAlignment = Alignment.Center - ) { - ColorPalette( - initialColor = state.selectedColor, - onColorSelected = { newColor -> - viewModel.updateSelectColor(newColor) - } - ) - } - } else { - Text( - text = dDay, - style = TerningTheme.typography.body5, - color = TerningMain, - modifier = Modifier.padding(bottom = 9.dp) - ) - Column( - modifier = Modifier.padding(bottom = 29.dp), - verticalArrangement = Arrangement.spacedBy( - 5.dp, - Alignment.CenterVertically - ), - horizontalAlignment = Alignment.Start, - ) { - internInfoList.forEach { - InternInfoRow( - title = it.first, - value = it.second - ) - } - } - } - } - Box( - modifier = Modifier.fillMaxWidth(), - contentAlignment = Alignment.BottomCenter - ) { - val selectedColorIndex = - colorList.indexOf(state.selectedColor).takeIf { it >= 0 } ?: 0 - - RoundButton( - style = TerningTheme.typography.button3, - paddingVertical = 12.dp, - cornerRadius = 8.dp, - text = R.string.dialog_scrap_button, - onButtonClick = { - if (state.isPaletteOpen) { - viewModel.updatePaletteOpen(false) - viewModel.postScrap(announcementId, selectedColorIndex) - viewModel.updateColorChange(false) - viewModel.updateScrapDialogVisible(false) - } else { - if (state.isColorChange) { - viewModel.postScrap(announcementId, selectedColorIndex) - viewModel.updateColorChange(false) - } else { - viewModel.postScrap(announcementId, selectedColorIndex) - } - viewModel.updateScrapDialogVisible(false) - } - }, - modifier = Modifier.padding(bottom = 8.dp) - ) - } - } - -} \ No newline at end of file diff --git a/feature/src/main/java/com/terning/feature/intern/model/InternUiState.kt b/feature/src/main/java/com/terning/feature/intern/model/InternUiState.kt index a9b094007..cee2e5373 100644 --- a/feature/src/main/java/com/terning/feature/intern/model/InternUiState.kt +++ b/feature/src/main/java/com/terning/feature/intern/model/InternUiState.kt @@ -3,6 +3,7 @@ package com.terning.feature.intern.model import androidx.compose.ui.graphics.Color import com.terning.core.designsystem.theme.CalRed import com.terning.core.state.UiState +import com.terning.domain.entity.CalendarScrapDetail import com.terning.domain.entity.intern.InternInfo data class InternUiState( @@ -10,7 +11,10 @@ data class InternUiState( val isColorChange: Boolean = false, val isPaletteOpen: Boolean = false, val selectedColor: Color = CalRed, - val isScrapDialogVisible: Boolean = false, + val isCancelDialogVisibility: Boolean = false, + val isScrapDialogVisibility: Boolean = false, val isScrappedState: Boolean = false, val showWeb: Boolean = false, + val scrapId: Long? = null, + val internshipModel: InternInfo? = null ) \ No newline at end of file