Skip to content

Commit

Permalink
[FEAT/#191] 공고 상세 기업 정보 데이터 로드 로직 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
arinming committed Aug 30, 2024
1 parent e37e92f commit 45d79fb
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 82 deletions.
76 changes: 34 additions & 42 deletions feature/src/main/java/com/terning/feature/intern/InternRoute.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,45 +18,40 @@ 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
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
Expand All @@ -76,37 +69,46 @@ 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 {
layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT,
)
loadUrl(internState.url)
loadUrl(internInfoModel.url)
}
},
)
Expand All @@ -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)
}
Expand All @@ -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,
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -328,15 +330,15 @@ fun InternScreen(
)
) {
Text(
text = internState.detail.trimIndent(),
text = internInfoModel.detail.trimIndent(),
style = TerningTheme.typography.detail1,
color = Grey400
)
}
}
}
}
if (internState.isScrapDialogVisible) {
if (internUiState.isScrapDialogVisible) {
TerningBasicDialog(
onDismissRequest = {
viewModel.updateScrapDialogVisible(false)
Expand All @@ -345,14 +347,4 @@ fun InternScreen(
)
}
}
}

@Preview(showBackground = true)
@Composable
fun InternScreenPreview() {
TerningPointTheme {
InternScreen(
internState = InternState(),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,9 +24,8 @@ class InternViewModel @Inject constructor(
private val internRepository: InternRepository,
private val scrapRepository: ScrapRepository,
) : ViewModel() {
private val _internState: MutableStateFlow<InternState> =
MutableStateFlow(InternState())
val state: StateFlow<InternState> = _internState.asStateFlow()
private val _internUiState = MutableStateFlow(InternUiState())
val internUiState get() = _internUiState.asStateFlow()

private val _scrapState: MutableStateFlow<InternScrapState> =
MutableStateFlow(InternScrapState())
Expand Down Expand Up @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ fun InternCompanyInfo(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = modifier
.padding(
vertical = 20.dp
)
) {
Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<InternInfoModel> = 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,
)

0 comments on commit 45d79fb

Please sign in to comment.