Skip to content

Commit faec1b7

Browse files
committed
[#441] HighlightedText 컴포넌트 분리
1 parent eda149b commit faec1b7

File tree

4 files changed

+97
-45
lines changed

4 files changed

+97
-45
lines changed

feature/timetable/src/main/java/in/koreatech/koin/feature/timetable/component/FilledTextButton.kt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ package `in`.koreatech.koin.feature.timetable.component
33
import androidx.compose.foundation.interaction.MutableInteractionSource
44
import androidx.compose.foundation.layout.PaddingValues
55
import androidx.compose.foundation.layout.height
6+
import androidx.compose.foundation.layout.padding
67
import androidx.compose.foundation.layout.width
78
import androidx.compose.material3.Button
89
import androidx.compose.material3.ButtonColors
10+
import androidx.compose.material3.Surface
911
import androidx.compose.material3.Text
1012
import androidx.compose.runtime.Composable
1113
import androidx.compose.runtime.remember
@@ -64,10 +66,15 @@ object FilledTextButtonDefaults {
6466
@Composable
6567
private fun FilledTextButtonPreview() {
6668
KoinTheme {
67-
FilledTextButton(
68-
modifier = Modifier.width(96.dp).height(48.dp),
69-
text = "Preview",
70-
onClick = {}
71-
)
69+
Surface(modifier = Modifier.padding(24.dp)) {
70+
FilledTextButton(
71+
modifier = Modifier
72+
.width(96.dp)
73+
.height(48.dp),
74+
text = "Preview",
75+
onClick = {}
76+
)
77+
78+
}
7279
}
7380
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package `in`.koreatech.koin.feature.timetable.component
2+
3+
import androidx.compose.material3.Text
4+
import androidx.compose.runtime.Composable
5+
import androidx.compose.ui.Modifier
6+
import androidx.compose.ui.text.ParagraphStyle
7+
import androidx.compose.ui.text.TextStyle
8+
import androidx.compose.ui.text.buildAnnotatedString
9+
import androidx.compose.ui.text.style.LineBreak
10+
import androidx.compose.ui.text.style.TextAlign
11+
import androidx.compose.ui.text.withStyle
12+
import `in`.koreatech.koin.core.designsystem.theme.KoinTheme
13+
import `in`.koreatech.koin.core.designsystem.theme.ThemePreviews
14+
15+
@Composable
16+
fun HighlightedText(
17+
texts: Array<String>,
18+
highlightIndices: List<Int>,
19+
defaultStyle: TextStyle,
20+
highlightStyle: TextStyle,
21+
modifier: Modifier = Modifier
22+
) {
23+
val annotatedString = buildAnnotatedString {
24+
pushStyle(
25+
ParagraphStyle(
26+
lineBreak = LineBreak(
27+
strategy = LineBreak.Strategy.Balanced,
28+
wordBreak = LineBreak.WordBreak.Phrase,
29+
strictness = LineBreak.Strictness.Normal
30+
)
31+
)
32+
)
33+
texts.forEachIndexed { idx, text ->
34+
withStyle(
35+
style = highlightIndices.find { it == idx }
36+
?.let { highlightStyle.toSpanStyle() }
37+
?: defaultStyle.toSpanStyle()
38+
) {
39+
append(text)
40+
}
41+
}
42+
}
43+
44+
Text(
45+
text = annotatedString,
46+
style = defaultStyle,
47+
textAlign = TextAlign.Center,
48+
modifier = modifier
49+
)
50+
}
51+
52+
@ThemePreviews
53+
@Composable
54+
private fun HighlightedTextPreview() {
55+
KoinTheme {
56+
HighlightedText(
57+
texts = arrayOf("안녕하세요 ", "강조", "입니다"),
58+
highlightIndices = listOf(1),
59+
defaultStyle = KoinTheme.typography.regular15,
60+
highlightStyle = KoinTheme.typography.bold15,
61+
)
62+
}
63+
}

feature/timetable/src/main/java/in/koreatech/koin/feature/timetable/view/LectureDuplicationDialog.kt

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,26 @@ import androidx.compose.runtime.remember
2525
import androidx.compose.runtime.setValue
2626
import androidx.compose.ui.Alignment
2727
import androidx.compose.ui.Modifier
28+
import androidx.compose.ui.res.stringArrayResource
2829
import androidx.compose.ui.res.stringResource
29-
import androidx.compose.ui.text.ParagraphStyle
30-
import androidx.compose.ui.text.buildAnnotatedString
31-
import androidx.compose.ui.text.style.LineBreak
3230
import androidx.compose.ui.text.style.TextAlign
33-
import androidx.compose.ui.text.withStyle
3431
import androidx.compose.ui.unit.dp
3532
import `in`.koreatech.koin.core.designsystem.theme.FontScalePreviews
3633
import `in`.koreatech.koin.core.designsystem.theme.KoinTheme
3734
import `in`.koreatech.koin.feature.timetable.R
3835
import `in`.koreatech.koin.feature.timetable.component.FilledTextButton
36+
import `in`.koreatech.koin.feature.timetable.component.HighlightedText
3937

4038
@OptIn(ExperimentalMaterial3Api::class)
4139
@Composable
4240
fun LectureDuplicationDialog(
4341
onConfirm: () -> Unit,
44-
onDismiss: () -> Unit
42+
onDismiss: () -> Unit,
43+
modifier: Modifier = Modifier
4544
) {
4645
BasicAlertDialog(
4746
onDismissRequest = { onDismiss() },
48-
modifier = Modifier,
47+
modifier = modifier,
4948
) {
5049
Surface(
5150
modifier = Modifier
@@ -69,40 +68,15 @@ fun LectureDuplicationDialog(
6968
style = KoinTheme.typography.bold16,
7069
)
7170
Spacer(modifier = Modifier.height(8.dp))
72-
Text(
73-
text = buildAnnotatedString {
74-
pushStyle(
75-
ParagraphStyle(
76-
lineBreak = LineBreak(
77-
strategy = LineBreak.Strategy.Balanced,
78-
wordBreak = LineBreak.WordBreak.Phrase,
79-
strictness = LineBreak.Strictness.Normal
80-
)
81-
)
82-
)
83-
withStyle(
84-
style = KoinTheme.typography.regular14.copy(
85-
color = KoinTheme.colors.neutral600,
86-
).toSpanStyle()
87-
) {
88-
append("추가하시려는 시간에 이미 다른 강의가 있어요.")
89-
}
90-
withStyle(
91-
style = KoinTheme.typography.regular14.copy(
92-
color = KoinTheme.colors.warning600,
93-
).toSpanStyle()
94-
) {
95-
append(" 새로운 강의로 대체")
96-
}
97-
withStyle(
98-
style = KoinTheme.typography.regular14.copy(
99-
color = KoinTheme.colors.neutral600,
100-
).toSpanStyle()
101-
) {
102-
append("하시겠어요?")
103-
}
104-
},
105-
textAlign = TextAlign.Center
71+
HighlightedText(
72+
texts = stringArrayResource(id = R.array.lecture_duplication_description),
73+
highlightIndices = listOf(1),
74+
defaultStyle = KoinTheme.typography.regular14.copy(
75+
color = KoinTheme.colors.neutral600,
76+
),
77+
highlightStyle = KoinTheme.typography.regular14.copy(
78+
color = KoinTheme.colors.warning600,
79+
)
10680
)
10781
Spacer(modifier = Modifier.height(24.dp))
10882
Row(

feature/timetable/src/main/res/values/strings.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,12 @@
33
<string name="lecture_duplication_title">시간표가 중복돼요.</string>
44
<string name="lecture_duplication_cancellation">취소</string>
55
<string name="lecture_duplication_confirmation">대체하기</string>
6+
7+
<string-array name="lecture_duplication_description">
8+
<item>추가하시려는 시간에 이미 다른 강의가 있어요.</item>
9+
<item>" 새로운 강의로 대체"</item>
10+
<item>하시겠어요?</item>
11+
</string-array>
12+
13+
614
</resources>

0 commit comments

Comments
 (0)