diff --git a/core/src/main/java/com/terning/core/designsystem/component/item/InternItemWithShadow.kt b/core/src/main/java/com/terning/core/designsystem/component/item/InternItemWithShadow.kt index 287e4076d..cc0f59122 100644 --- a/core/src/main/java/com/terning/core/designsystem/component/item/InternItemWithShadow.kt +++ b/core/src/main/java/com/terning/core/designsystem/component/item/InternItemWithShadow.kt @@ -22,6 +22,7 @@ fun InternItemWithShadow( dateDeadline: String, workingPeriod: String, isScrapped: Boolean, + onScrapButtonClicked: (Long) -> Unit = {} ) { Box( modifier = modifier @@ -40,7 +41,8 @@ fun InternItemWithShadow( title = title, dateDeadline = dateDeadline, workingPeriod = workingPeriod, - isScraped = isScrapped + isScraped = isScrapped, + onScrapButtonClicked = onScrapButtonClicked ) } } \ No newline at end of file diff --git a/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt b/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt index 0f19b313f..bc437e7a4 100644 --- a/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt +++ b/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt @@ -35,6 +35,8 @@ import androidx.navigation.NavHostController import com.google.accompanist.systemuicontroller.rememberSystemUiController import com.terning.core.designsystem.component.bottomsheet.SortingBottomSheet import com.terning.core.designsystem.component.button.SortingButton +import com.terning.core.designsystem.component.dialog.ScrapCancelDialogContent +import com.terning.core.designsystem.component.dialog.TerningBasicDialog import com.terning.core.designsystem.component.item.InternItemWithShadow import com.terning.core.designsystem.component.topappbar.LogoTopAppBar import com.terning.core.designsystem.theme.Black @@ -52,6 +54,7 @@ import com.terning.feature.home.changefilter.navigation.navigateChangeFilter import com.terning.feature.home.home.component.HomeFilteringEmptyIntern import com.terning.feature.home.home.component.HomeFilteringScreen import com.terning.feature.home.home.component.HomeRecommendEmptyIntern +import com.terning.feature.home.home.component.HomeRecommendInternDialog import com.terning.feature.home.home.component.HomeTodayEmptyWithImg import com.terning.feature.home.home.component.HomeTodayIntern import com.terning.feature.home.home.model.HomeDialogState @@ -168,6 +171,7 @@ fun HomeScreen( navController: NavHostController, ) { var sheetState by remember { mutableStateOf(false) } + var scrapId by remember { mutableStateOf(-1) } if (sheetState) { SortingBottomSheet( @@ -247,7 +251,12 @@ fun HomeScreen( items(recommendInternList.size) { index -> RecommendInternItem( navController = navController, - intern = recommendInternList[index] + intern = recommendInternList[index], + onScrapButtonClicked = { + viewModel.updateScrapDialogVisible(true) + viewModel.updateIsToday(false) + scrapId = index + } ) } } @@ -264,6 +273,54 @@ fun HomeScreen( } } } + + if (homeDialogState.isScrapDialogVisible && !homeDialogState.isToday) { + TerningBasicDialog( + onDismissRequest = { viewModel.updateScrapDialogVisible(false) }, + content = { + if (recommendInternList[scrapId].scrapId != null) { + ScrapCancelDialogContent( + onClickScrapCancel = { + viewModel.updateScrapDialogVisible(false) + viewModel.deleteScrap( + recommendInternList[scrapId].scrapId ?: -1, + ) + if(homeDialogState.isScrappedState) { + viewModel.getRecommendInternsData( + currentSortBy.value, + homeFilteringInfo.startYear ?: viewModel.currentYear, + homeFilteringInfo.startMonth ?: viewModel.currentMonth, + ) + viewModel.updateScrapped(false) + } + } + ) + } else { + with(recommendInternList[scrapId]) { + HomeRecommendInternDialog( + internInfoList = listOf( + stringResource(id = R.string.intern_info_d_day) to deadline, + stringResource(id = R.string.intern_info_working) to workingPeriod, + stringResource(id = R.string.intern_info_start_date) to startYearMonth, + ), + clickAction = { + viewModel.updateScrapDialogVisible(false) + if(homeDialogState.isScrappedState) { + viewModel.getRecommendInternsData( + currentSortBy.value, + homeFilteringInfo.startYear ?: viewModel.currentYear, + homeFilteringInfo.startMonth ?: viewModel.currentMonth, + ) + viewModel.updateScrapped(false) + } + }, + homeRecommendInternModel = this, + ) + } + } + } + ) + } } @@ -271,6 +328,7 @@ fun HomeScreen( private fun RecommendInternItem( navController: NavHostController, intern: HomeRecommendInternModel, + onScrapButtonClicked: (Long) -> Unit, ) { InternItemWithShadow( modifier = Modifier @@ -286,7 +344,8 @@ private fun RecommendInternItem( workingPeriod = intern.workingPeriod, isScrapped = intern.isScrapped, shadowRadius = 5.dp, - shadowWidth = 1.dp + shadowWidth = 1.dp, + onScrapButtonClicked = onScrapButtonClicked, ) } diff --git a/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt b/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt index eb7815327..f0764e7f0 100644 --- a/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt +++ b/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt @@ -136,6 +136,7 @@ class HomeViewModel @Inject constructor( ).onSuccess { updateScrapDialogVisible(visible = false) updateScrapped(scrapped = true) + getHomeTodayInternList() }.onFailure { _homeSideEffect.emit(HomeSideEffect.ShowToast(R.string.server_failure)) } @@ -148,7 +149,8 @@ class HomeViewModel @Inject constructor( ScrapRequestModel(id = scrapId) ).onSuccess { updateScrapDialogVisible(visible = false) - updateScrapped(scrapped = false) + updateScrapped(scrapped = true) + getHomeTodayInternList() }.onFailure { _homeSideEffect.emit(HomeSideEffect.ShowToast(R.string.server_failure)) } diff --git a/feature/src/main/java/com/terning/feature/home/home/component/HomeRecommendInternDialog.kt b/feature/src/main/java/com/terning/feature/home/home/component/HomeRecommendInternDialog.kt new file mode 100644 index 000000000..45e08b4ba --- /dev/null +++ b/feature/src/main/java/com/terning/feature/home/home/component/HomeRecommendInternDialog.kt @@ -0,0 +1,258 @@ +package com.terning.feature.home.home.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.fillMaxSize +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.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.domain.entity.response.HomeRecommendInternModel +import com.terning.feature.home.home.HomeViewModel +import com.terning.feature.intern.component.InternInfoRow + + +@Composable +fun HomeRecommendInternDialog( + internInfoList: List>, + clickAction: () -> Unit, + homeRecommendInternModel: HomeRecommendInternModel, + viewModel: HomeViewModel = hiltViewModel(), +) { + val state by viewModel.homeDialogState.collectAsStateWithLifecycle() + + val colorList = listOf( + CalRed, + CalOrange1, + CalOrange2, + CalYellow, + CalGreen1, + CalGreen2, + CalBlue1, + CalBlue2, + CalPurple, + CalPink, + ) + + Box( + modifier = Modifier + .fillMaxSize() + .padding(top = 32.dp), + contentAlignment = Alignment.TopCenter + ) { + Column( + modifier = Modifier + .fillMaxSize() + .padding(horizontal = 11.dp), + horizontalAlignment = Alignment.CenterHorizontally + ) { + AsyncImage( + model = ImageRequest.Builder(LocalContext.current) + .data(homeRecommendInternModel.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 = homeRecommendInternModel.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 = CalRed, + onColorSelected = { newColor -> + viewModel.updateSelectColor(newColor) + } + ) + } + } else { + Text( + text = homeRecommendInternModel.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 + ) + } + } + } + } + Spacer(modifier = Modifier.weight(1f)) + 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.updateColorChange(false) + viewModel.updateScrapDialogVisible(false) + } else { + if (state.isColorChange) { + viewModel.updateColorChange(false) + } + viewModel.updateScrapDialogVisible(false) + } + viewModel.postScrap( + homeRecommendInternModel.internshipAnnouncementId, + selectedColorIndex, + ) + clickAction() + }, + modifier = Modifier.padding(bottom = 8.dp) + ) + } + } + } +} \ No newline at end of file diff --git a/feature/src/main/java/com/terning/feature/home/home/component/HomeTodayIntern.kt b/feature/src/main/java/com/terning/feature/home/home/component/HomeTodayIntern.kt index e5672924a..fac68b5ed 100644 --- a/feature/src/main/java/com/terning/feature/home/home/component/HomeTodayIntern.kt +++ b/feature/src/main/java/com/terning/feature/home/home/component/HomeTodayIntern.kt @@ -1,6 +1,5 @@ package com.terning.feature.home.home.component -import android.util.Log import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.fillMaxWidth @@ -45,20 +44,20 @@ fun HomeTodayIntern( modifier = Modifier .noRippleClickable { homeViewModel.updateScrapDialogVisible(true) + homeViewModel.updateIsToday(true) selectedIndex = index } ) } } - if (homeDialogState.isScrapDialogVisible) { + if (homeDialogState.isScrapDialogVisible && homeDialogState.isToday) { TerningBasicDialog( onDismissRequest = { homeViewModel.updateScrapDialogVisible(false) }, content = { with(internList[selectedIndex]) { - Log.d("homeDialog", selectedIndex.toString()) HomeTodayInternDialog( internInfoList = listOf( stringResource(id = R.string.intern_info_d_day) to deadline, @@ -72,7 +71,6 @@ fun HomeTodayIntern( homeTodayInternModel = internList[selectedIndex], ) } - }, ) }