Skip to content

Commit

Permalink
[feat] 데이터에 맞게 모델 전달
Browse files Browse the repository at this point in the history
  • Loading branch information
ddyeon committed Oct 11, 2023
1 parent a899ae6 commit 3e318c6
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalConfiguration
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
Expand All @@ -30,13 +31,17 @@ import androidx.compose.ui.window.DialogProperties
import com.mashup.twotoo.presenter.R
import com.mashup.twotoo.presenter.designsystem.component.TwoTooImageView
import com.mashup.twotoo.presenter.designsystem.theme.TwoTooTheme
import com.mashup.twotoo.presenter.home.model.FlowerLanguageUiModel

@Composable
fun FlowerLanguageDialog(
flowerLanguageUiModel: FlowerLanguageUiModel,
onClickDismiss: () -> Unit,
onDismissRequest: () -> Unit = {},
properties: DialogProperties = DialogProperties(),
) {
val screenWidth = LocalConfiguration.current.screenWidthDp.dp
val context = LocalContext.current
Dialog(
onDismissRequest = onDismissRequest,
properties = properties,
Expand All @@ -58,52 +63,52 @@ fun FlowerLanguageDialog(
previewPlaceholder = R.drawable.img_flower_card_bottom,

)
Column() {
Column {
Icon(
painter = painterResource(id = R.drawable.ic_cancel),
modifier = Modifier
.align(Alignment.End)
.padding(top = 14.dp, end = 14.dp)
.clickable { },
.clickable { onClickDismiss() },
contentDescription = null,
)
FlowerLanguageContent(
modifier = Modifier.fillMaxWidth().align(Alignment.CenterHorizontally).padding(bottom = 32.dp),
R.string.fig,
R.string.fig_language,
flower = flowerLanguageUiModel.getFlowerName(context),
language = flowerLanguageUiModel.getFlowerLanguage(context),
)
TwoTooImageView(
modifier = Modifier.size(99.dp, 164.dp)
.align(Alignment.CenterHorizontally),
model = R.drawable.img_home_fourth_stage_fig_partner,
model = flowerLanguageUiModel.getFlowerImage(context),
previewPlaceholder = R.drawable.img_home_fourth_stage_fig_partner,
)
Spacer(modifier = Modifier.height(22.dp))
ChallengeCountCard(
modifier = Modifier
.align(Alignment.CenterHorizontally)
.padding(bottom = 30.dp),
1,
flowerLanguageUiModel.challengeNo,
)
}
}
}
}

@Composable
fun FlowerLanguageContent(modifier: Modifier, flower: Int, language: Int) {
fun FlowerLanguageContent(modifier: Modifier, flower: String, language: String) {
Column(
modifier = modifier,
horizontalAlignment = Alignment.CenterHorizontally,
) {
Text(
text = stringResource(id = flower),
text = flower,
textAlign = TextAlign.Center,
style = TwoTooTheme.typography.headLineNormal24,
color = TwoTooTheme.color.mainBrown,
)
Text(
text = stringResource(id = language),
text = language,
textAlign = TextAlign.Center,
style = TwoTooTheme.typography.bodyNormal16,
color = TwoTooTheme.color.mainBrown,
Expand Down Expand Up @@ -133,5 +138,5 @@ fun ChallengeCountCard(
@Preview
@Composable
fun PreviewFlowerDialog() {
FlowerLanguageDialog()
FlowerLanguageDialog(FlowerLanguageUiModel(), {})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.mashup.twotoo.presenter.home.model

import android.content.Context
import com.mashup.twotoo.presenter.model.FlowerName
import com.mashup.twotoo.presenter.model.Stage

data class FlowerLanguageUiModel(
val challengeNo: Int = 0,
val flowerName: FlowerName = FlowerName.Tulip
) {
fun getFlowerLanguage(context: Context): String {
val name = "${flowerName.name.lowercase()}_language"
val flowerLanguage = context.resources.getIdentifier(name, "string", context.packageName)
return context.getString(flowerLanguage)
}

fun getFlowerName(context: Context): String {
val name = flowerName.name.lowercase()
val flowerName = context.resources.getIdentifier(name, "string", context.packageName)
return context.getString(flowerName)
}

fun getFlowerImage(context: Context): Int {
val name = "img_home_${Stage.Fourth.name.lowercase()}_stage_${flowerName.name.lowercase()}_me"
val image = context.resources.getIdentifier(name, "drawable", context.packageName)
return image
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,3 @@ data class FlowerImage(
val height: Dp,
)

fun getFlowerLanguage(flowerName: FlowerName): Int {
return when(flowerName) {
FlowerName.Tulip -> R.string.tulip_language
FlowerName.Rose -> R.string.rose_language
FlowerName.Cotton -> R.string.cotton_language
FlowerName.Fig -> R.string.fig_language
FlowerName.Chrysanthemum -> R.string.chrysanthemum_language
FlowerName.Sunflower -> R.string.sunflower_language
FlowerName.Camellia -> R.string.camellia_language
FlowerName.Delphinium -> R.string.delphinium_language
}
}

0 comments on commit 3e318c6

Please sign in to comment.