From 45d79fbd6d85a12855bc835a07b5ef00ae080e31 Mon Sep 17 00:00:00 2001 From: arinming Date: Fri, 30 Aug 2024 18:36:06 +0900 Subject: [PATCH] =?UTF-8?q?[FEAT/#191]=20=EA=B3=B5=EA=B3=A0=20=EC=83=81?= =?UTF-8?q?=EC=84=B8=20=EA=B8=B0=EC=97=85=20=EC=A0=95=EB=B3=B4=20=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=20=EB=A1=9C=EB=93=9C=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/terning/feature/intern/InternRoute.kt | 76 +++++++++---------- .../terning/feature/intern/InternViewModel.kt | 18 ++--- .../intern/component/InternCompanyInfo.kt | 1 - .../intern/component/ScrapDialogContent.kt | 2 +- .../feature/intern/model/InternState.kt | 28 ------- .../feature/intern/model/InternUiState.kt | 16 ++++ 6 files changed, 59 insertions(+), 82 deletions(-) delete mode 100644 feature/src/main/java/com/terning/feature/intern/model/InternState.kt create mode 100644 feature/src/main/java/com/terning/feature/intern/model/InternUiState.kt 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 adc3a3a18..4719398db 100644 --- a/feature/src/main/java/com/terning/feature/intern/InternRoute.kt +++ b/feature/src/main/java/com/terning/feature/intern/InternRoute.kt @@ -8,9 +8,7 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.size import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.Icon import androidx.compose.material3.Scaffold @@ -20,37 +18,32 @@ import androidx.compose.runtime.LaunchedEffect 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.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.viewinterop.AndroidView import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.LocalLifecycleOwner import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.flowWithLifecycle -import coil.compose.AsyncImage -import coil.request.ImageRequest import com.terning.core.designsystem.component.dialog.TerningBasicDialog import com.terning.core.designsystem.component.topappbar.BackButtonTopAppBar import com.terning.core.designsystem.theme.Black -import com.terning.core.designsystem.theme.Grey150 import com.terning.core.designsystem.theme.Grey200 import com.terning.core.designsystem.theme.Grey400 import com.terning.core.designsystem.theme.TerningMain -import com.terning.core.designsystem.theme.TerningPointTheme import com.terning.core.designsystem.theme.TerningTheme import com.terning.core.extension.customShadow import com.terning.core.extension.toast +import com.terning.core.state.UiState +import com.terning.domain.entity.response.InternInfoModel import com.terning.feature.R import com.terning.feature.intern.component.InternBottomBar import com.terning.feature.intern.component.InternCompanyInfo import com.terning.feature.intern.component.InternInfoRow import com.terning.feature.intern.component.InternPageTitle -import com.terning.feature.intern.model.InternState +import com.terning.feature.intern.model.InternUiState import java.text.DecimalFormat @Composable @@ -58,7 +51,7 @@ fun InternRoute( announcementId: Long = 0, viewModel: InternViewModel = hiltViewModel(), ) { - val internState by viewModel.state.collectAsStateWithLifecycle() + val internState by viewModel.internUiState.collectAsStateWithLifecycle() val context = LocalContext.current val lifecycleOwner = LocalLifecycleOwner.current @@ -76,29 +69,38 @@ fun InternRoute( } } - InternScreen( - internState = internState - ) + when (internState.loadState) { + UiState.Loading -> {} + UiState.Empty -> {} + is UiState.Failure -> {} + is UiState.Success -> { + InternScreen( + internUiState = internState, + internInfoModel = (internState.loadState as UiState.Success).data + ) + } + } } @Composable fun InternScreen( modifier: Modifier = Modifier, viewModel: InternViewModel = hiltViewModel(), - internState: InternState, + internUiState: InternUiState, + internInfoModel: InternInfoModel, ) { val decimal = DecimalFormat("#,###") val internInfoList = listOf( - stringResource(id = R.string.intern_info_d_day) to internState.deadline, - stringResource(id = R.string.intern_info_working) to internState.workingPeriod, - stringResource(id = R.string.intern_info_start_date) to internState.startDate, + stringResource(id = R.string.intern_info_d_day) to internInfoModel.deadline, + stringResource(id = R.string.intern_info_working) to internInfoModel.workingPeriod, + stringResource(id = R.string.intern_info_start_date) to internInfoModel.startDate, ) - val qualificationList = internState.qualification.split(",").map { it.trim() } - val jobTypeList = internState.jobType.split(",").map { it.trim() } + val qualificationList = internInfoModel.qualification.split(",").map { it.trim() } + val jobTypeList = internInfoModel.jobType.split(",").map { it.trim() } - if (internState.showWeb) { + if (internUiState.showWeb) { AndroidView( factory = { WebView(it).apply { @@ -106,7 +108,7 @@ fun InternScreen( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, ) - loadUrl(internState.url) + loadUrl(internInfoModel.url) } }, ) @@ -128,8 +130,8 @@ fun InternScreen( bottomBar = { InternBottomBar( modifier = modifier, - scrapCount = decimal.format(internState.scrapCount), - scrapId = internState.scrapId, + scrapCount = decimal.format(internInfoModel.scrapCount), + scrapId = internInfoModel.scrapId, onScrapClick = { viewModel.updateScrapDialogVisible(true) } @@ -150,13 +152,13 @@ fun InternScreen( ) { InternCompanyInfo( modifier = modifier, - companyImage = internState.companyImage, - company = internState.company, - companyCategory = internState.companyCategory + companyImage = internInfoModel.companyImage, + company = internInfoModel.company, + companyCategory = internInfoModel.companyCategory ) Text( - text = internState.title, - style = TerningTheme.typography.title2, + text = internInfoModel.title, + style = TerningTheme.typography.heading2, color = Black, modifier = modifier.padding( top = 4.dp, @@ -198,7 +200,7 @@ fun InternScreen( color = Grey400 ) Text( - text = "${decimal.format(internState.viewCount)}회", + text = "${decimal.format(internInfoModel.viewCount)}회", style = TerningTheme.typography.button4, color = Grey400, ) @@ -328,7 +330,7 @@ fun InternScreen( ) ) { Text( - text = internState.detail.trimIndent(), + text = internInfoModel.detail.trimIndent(), style = TerningTheme.typography.detail1, color = Grey400 ) @@ -336,7 +338,7 @@ fun InternScreen( } } } - if (internState.isScrapDialogVisible) { + if (internUiState.isScrapDialogVisible) { TerningBasicDialog( onDismissRequest = { viewModel.updateScrapDialogVisible(false) @@ -345,14 +347,4 @@ fun InternScreen( ) } } -} - -@Preview(showBackground = true) -@Composable -fun InternScreenPreview() { - TerningPointTheme { - InternScreen( - internState = InternState(), - ) - } } \ No newline at end of file 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 3a63ea8f8..737c134db 100644 --- a/feature/src/main/java/com/terning/feature/intern/InternViewModel.kt +++ b/feature/src/main/java/com/terning/feature/intern/InternViewModel.kt @@ -9,11 +9,10 @@ import com.terning.domain.repository.InternRepository import com.terning.domain.repository.ScrapRepository import com.terning.feature.R import com.terning.feature.intern.model.InternScrapState -import com.terning.feature.intern.model.InternState +import com.terning.feature.intern.model.InternUiState import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.update @@ -25,9 +24,8 @@ class InternViewModel @Inject constructor( private val internRepository: InternRepository, private val scrapRepository: ScrapRepository, ) : ViewModel() { - private val _internState: MutableStateFlow = - MutableStateFlow(InternState()) - val state: StateFlow = _internState.asStateFlow() + private val _internUiState = MutableStateFlow(InternUiState()) + val internUiState get() = _internUiState.asStateFlow() private val _scrapState: MutableStateFlow = MutableStateFlow(InternScrapState()) @@ -97,31 +95,31 @@ class InternViewModel @Inject constructor( } fun updateSelectColor(newColor: Color) { - _internState.update { + _internUiState.update { it.copy(selectedColor = newColor) } } fun updateScrapDialogVisible(visible: Boolean) { - _internState.update { + _internUiState.update { it.copy(isScrapDialogVisible = visible) } } fun updatePaletteOpen(open: Boolean) { - _internState.update { + _internUiState.update { it.copy(isPaletteOpen = open) } } fun updateColorChange(change: Boolean) { - _internState.update { + _internUiState.update { it.copy(isColorChange = change) } } fun updateShowWeb(show: Boolean) { - _internState.update { + _internUiState.update { it.copy(showWeb = show) } } diff --git a/feature/src/main/java/com/terning/feature/intern/component/InternCompanyInfo.kt b/feature/src/main/java/com/terning/feature/intern/component/InternCompanyInfo.kt index 0ab151077..093d1e3e1 100644 --- a/feature/src/main/java/com/terning/feature/intern/component/InternCompanyInfo.kt +++ b/feature/src/main/java/com/terning/feature/intern/component/InternCompanyInfo.kt @@ -73,7 +73,6 @@ fun InternCompanyInfo( horizontalAlignment = Alignment.CenterHorizontally, modifier = modifier .padding( - vertical = 20.dp ) ) { Text( 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 index 17335a3a8..3746f5f13 100644 --- a/feature/src/main/java/com/terning/feature/intern/component/ScrapDialogContent.kt +++ b/feature/src/main/java/com/terning/feature/intern/component/ScrapDialogContent.kt @@ -65,7 +65,7 @@ fun ScrapDialogContent( announcementId: Long, type: Int, ) { - val state by viewModel.state.collectAsStateWithLifecycle() + val state by viewModel.internUiState.collectAsStateWithLifecycle() val colorList = listOf( CalRed, diff --git a/feature/src/main/java/com/terning/feature/intern/model/InternState.kt b/feature/src/main/java/com/terning/feature/intern/model/InternState.kt deleted file mode 100644 index 55d2b80c7..000000000 --- a/feature/src/main/java/com/terning/feature/intern/model/InternState.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.terning.feature.intern.model - -import androidx.compose.ui.graphics.Color -import com.terning.core.designsystem.theme.CalRed - -data class InternState( - val dDay: String = "", - val title: String = "", - val deadline: String = "", - val workingPeriod: String = "", - val startDate: String = "", - val scrapCount: Int = 0, - val viewCount: Int = 0, - val company: String = "", - val companyCategory: String = "", - val companyImage: String = "", - val qualification: String = "", - val jobType: String = "", - val detail: String = "", - val url: String = "", - val scrapId: Long? = null, - val isColorChange: Boolean = false, - val isPaletteOpen: Boolean = false, - val selectedColor: Color = CalRed, - val isScrapDialogVisible: Boolean = false, - val isScrappedState: Boolean = false, - val showWeb: Boolean = false, -) \ 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 new file mode 100644 index 000000000..16f8afcc3 --- /dev/null +++ b/feature/src/main/java/com/terning/feature/intern/model/InternUiState.kt @@ -0,0 +1,16 @@ +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.response.InternInfoModel + +data class InternUiState( + val loadState: UiState = UiState.Loading, + val isColorChange: Boolean = false, + val isPaletteOpen: Boolean = false, + val selectedColor: Color = CalRed, + val isScrapDialogVisible: Boolean = false, + val isScrappedState: Boolean = false, + val showWeb: Boolean = false, +) \ No newline at end of file