Skip to content

Commit 3ed3404

Browse files
committed
FIX: 감정구슬 이미지 데이터 클래스 및 감정구슬 이미지 Ui 분리
1 parent 626487e commit 3ed3404

5 files changed

Lines changed: 87 additions & 26 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.threegap.bitnagil.presentation.emotion.component.atom
2+
3+
import androidx.compose.foundation.Image
4+
import androidx.compose.runtime.Composable
5+
import androidx.compose.ui.Modifier
6+
import androidx.compose.ui.platform.LocalContext
7+
import androidx.compose.ui.res.painterResource
8+
import coil3.compose.AsyncImage
9+
import coil3.request.ImageRequest
10+
import coil3.request.crossfade
11+
import com.threegap.bitnagil.presentation.emotion.model.EmotionImageUiModel
12+
13+
@Composable
14+
fun EmotionMarbleImage(
15+
modifier: Modifier,
16+
image: EmotionImageUiModel,
17+
contentDescription: String? = null,
18+
) {
19+
when (image) {
20+
is EmotionImageUiModel.Url -> {
21+
AsyncImage(
22+
model = ImageRequest.Builder(LocalContext.current)
23+
.data(image.url)
24+
.crossfade(true)
25+
.build(),
26+
modifier = modifier,
27+
contentDescription = null,
28+
error = image.offlineBackupImageResourceId?.let { painterResource(it) },
29+
)
30+
}
31+
is EmotionImageUiModel.Resource -> {
32+
Image(
33+
painter = painterResource(id = image.resourceId),
34+
contentDescription = contentDescription,
35+
modifier = modifier,
36+
)
37+
}
38+
}
39+
}

presentation/src/main/java/com/threegap/bitnagil/presentation/emotion/component/template/EmotionRecommendRoutineScreen.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import com.threegap.bitnagil.designsystem.BitnagilTheme
2121
import com.threegap.bitnagil.designsystem.component.atom.BitnagilSelectButton
2222
import com.threegap.bitnagil.designsystem.component.atom.BitnagilTextButton
2323
import com.threegap.bitnagil.designsystem.component.atom.BitnagilTextButtonColor
24+
import com.threegap.bitnagil.presentation.emotion.model.EmotionImageUiModel
2425
import com.threegap.bitnagil.presentation.emotion.model.EmotionRecommendRoutineUiModel
2526
import com.threegap.bitnagil.presentation.emotion.model.EmotionScreenStep
2627
import com.threegap.bitnagil.presentation.emotion.model.EmotionUiModel
@@ -110,9 +111,11 @@ private fun Preview() {
110111
emotionTypeUiModels = listOf(
111112
EmotionUiModel(
112113
emotionType = "emotionType",
113-
imageUrl = "https://bitnagil-s3.s3.ap-northeast-2.amazonaws.com/home_satisfaction.png",
114114
emotionMarbleName = "emotionMarbleName",
115-
offlineBackupImageResourceId = null,
115+
image = EmotionImageUiModel.Url(
116+
url = "https://bitnagil-s3.s3.ap-northeast-2.amazonaws.com/home_satisfaction.png",
117+
offlineBackupImageResourceId = null,
118+
),
116119
),
117120
),
118121
isLoading = false,

presentation/src/main/java/com/threegap/bitnagil/presentation/emotion/component/template/SimpleEmotionSelectionScreen.kt

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,13 @@ import androidx.compose.material3.Text
1616
import androidx.compose.runtime.Composable
1717
import androidx.compose.ui.Alignment
1818
import androidx.compose.ui.Modifier
19-
import androidx.compose.ui.platform.LocalContext
20-
import androidx.compose.ui.res.painterResource
2119
import androidx.compose.ui.tooling.preview.Preview
2220
import androidx.compose.ui.unit.dp
23-
import coil3.compose.AsyncImage
24-
import coil3.request.ImageRequest
25-
import coil3.request.crossfade
2621
import com.threegap.bitnagil.designsystem.BitnagilTheme
2722
import com.threegap.bitnagil.designsystem.component.block.BitnagilTopBar
2823
import com.threegap.bitnagil.designsystem.modifier.clickableWithoutRipple
24+
import com.threegap.bitnagil.presentation.emotion.component.atom.EmotionMarbleImage
25+
import com.threegap.bitnagil.presentation.emotion.model.EmotionImageUiModel
2926
import com.threegap.bitnagil.presentation.emotion.model.EmotionScreenStep
3027
import com.threegap.bitnagil.presentation.emotion.model.EmotionUiModel
3128
import com.threegap.bitnagil.presentation.emotion.model.mvi.EmotionState
@@ -65,14 +62,9 @@ fun SimpleEmotionSelectionScreen(
6562
.clickableWithoutRipple { onClickEmotion(emotion.emotionType) },
6663
horizontalAlignment = Alignment.CenterHorizontally,
6764
) {
68-
AsyncImage(
69-
model = ImageRequest.Builder(LocalContext.current)
70-
.data(emotion.imageUrl)
71-
.crossfade(true)
72-
.build(),
65+
EmotionMarbleImage(
7366
modifier = Modifier.aspectRatio(1f),
74-
contentDescription = null,
75-
error = emotion.offlineBackupImageResourceId?.let { painterResource(it) },
67+
image = emotion.image,
7668
)
7769

7870
Text(
@@ -95,27 +87,35 @@ private fun Preview() {
9587
emotionTypeUiModels = listOf(
9688
EmotionUiModel(
9789
emotionType = "emotionType",
98-
imageUrl = "https://bitnagil-s3.s3.ap-northeast-2.amazonaws.com/home_satisfaction.png",
9990
emotionMarbleName = "name1",
100-
offlineBackupImageResourceId = null,
91+
image = EmotionImageUiModel.Url(
92+
url = "https://bitnagil-s3.s3.ap-northeast-2.amazonaws.com/home_satisfaction.png",
93+
offlineBackupImageResourceId = null,
94+
),
10195
),
10296
EmotionUiModel(
10397
emotionType = "emotionType",
104-
imageUrl = "https://bitnagil-s3.s3.ap-northeast-2.amazonaws.com/home_satisfaction.png",
10598
emotionMarbleName = "name2",
106-
offlineBackupImageResourceId = null,
99+
image = EmotionImageUiModel.Url(
100+
url = "https://bitnagil-s3.s3.ap-northeast-2.amazonaws.com/home_satisfaction.png",
101+
offlineBackupImageResourceId = null,
102+
),
107103
),
108104
EmotionUiModel(
109105
emotionType = "emotionType",
110-
imageUrl = "https://bitnagil-s3.s3.ap-northeast-2.amazonaws.com/home_satisfaction.png",
111106
emotionMarbleName = "name3",
112-
offlineBackupImageResourceId = null,
107+
image = EmotionImageUiModel.Url(
108+
url = "https://bitnagil-s3.s3.ap-northeast-2.amazonaws.com/home_satisfaction.png",
109+
offlineBackupImageResourceId = null,
110+
),
113111
),
114112
EmotionUiModel(
115113
emotionType = "emotionType",
116-
imageUrl = "https://bitnagil-s3.s3.ap-northeast-2.amazonaws.com/home_satisfaction.png",
117114
emotionMarbleName = "name4",
118-
offlineBackupImageResourceId = null,
115+
image = EmotionImageUiModel.Url(
116+
url = "https://bitnagil-s3.s3.ap-northeast-2.amazonaws.com/home_satisfaction.png",
117+
offlineBackupImageResourceId = null,
118+
),
119119
),
120120
),
121121
isLoading = false,
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.threegap.bitnagil.presentation.emotion.model
2+
3+
import android.os.Parcelable
4+
import kotlinx.parcelize.Parcelize
5+
6+
@Parcelize
7+
sealed class EmotionImageUiModel : Parcelable {
8+
class Url(val url: String, val offlineBackupImageResourceId: Int?) : EmotionImageUiModel()
9+
class Resource(val resourceId: Int) : EmotionImageUiModel()
10+
}

presentation/src/main/java/com/threegap/bitnagil/presentation/emotion/model/EmotionUiModel.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@ import kotlinx.parcelize.Parcelize
99
data class EmotionUiModel(
1010
val emotionType: String,
1111
val emotionMarbleName: String,
12-
val imageUrl: String,
13-
val offlineBackupImageResourceId: Int?,
12+
val image: EmotionImageUiModel,
13+
val selectable: Boolean = true,
1414
) : Parcelable {
1515
companion object {
1616
fun fromDomain(emotion: Emotion) = EmotionUiModel(
1717
emotionType = emotion.emotionType,
1818
emotionMarbleName = emotion.emotionMarbleName,
19-
imageUrl = emotion.imageUrl,
20-
offlineBackupImageResourceId = getOfflineBackupImageResourceId(emotion.emotionType),
19+
image = EmotionImageUiModel.Url(
20+
url = emotion.imageUrl,
21+
offlineBackupImageResourceId = getOfflineBackupImageResourceId(emotion.emotionType)
22+
),
2123
)
2224

2325
private fun getOfflineBackupImageResourceId(emotionType: String): Int? {
@@ -31,5 +33,12 @@ data class EmotionUiModel(
3133
else -> null
3234
}
3335
}
36+
37+
val Default = EmotionUiModel(
38+
emotionType = "NONE",
39+
emotionMarbleName = "구슬 선택",
40+
image = EmotionImageUiModel.Resource(R.drawable.default_marble),
41+
selectable = false,
42+
)
3443
}
3544
}

0 commit comments

Comments
 (0)