Skip to content

Commit d44ed38

Browse files
committed
ui 분리
1 parent 1b2d488 commit d44ed38

File tree

2 files changed

+90
-49
lines changed

2 files changed

+90
-49
lines changed

feature/call/src/main/java/com/example/call/ui/chat/ChattingUi.kt

Lines changed: 9 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import androidx.compose.foundation.layout.Row
1414
import androidx.compose.foundation.layout.fillMaxSize
1515
import androidx.compose.foundation.layout.fillMaxWidth
1616
import androidx.compose.foundation.layout.padding
17+
import androidx.compose.foundation.lazy.LazyListState
1718
import androidx.compose.foundation.lazy.rememberLazyListState
18-
import androidx.compose.material3.ExperimentalMaterial3Api
1919
import androidx.compose.material3.MaterialTheme
2020
import androidx.compose.material3.Text
2121
import androidx.compose.material3.TextButton
@@ -31,6 +31,7 @@ import androidx.compose.ui.Modifier
3131
import androidx.compose.ui.graphics.Color
3232
import androidx.compose.ui.unit.dp
3333
import com.example.call.state.CallState
34+
import kotlinx.coroutines.CoroutineScope
3435
import kotlinx.coroutines.launch
3536

3637
sealed interface ChatMessage {
@@ -88,60 +89,19 @@ fun Chatting(
8889
enter = slideInVertically(initialOffsetY = { it }) + fadeIn(),
8990
exit = slideOutVertically(targetOffsetY = { it }) + fadeOut(),
9091
) {
91-
Box(
92-
modifier = Modifier
93-
.fillMaxWidth()
94-
.background(MaterialTheme.colorScheme.secondary)
95-
.padding(8.dp)
96-
) {
97-
Row(
98-
horizontalArrangement = Arrangement.SpaceBetween,
99-
verticalAlignment = Alignment.CenterVertically,
100-
modifier = Modifier.fillMaxWidth()
101-
) {
102-
Text(
103-
text = "other user on input",
104-
color = MaterialTheme.colorScheme.onSecondary,
105-
style = MaterialTheme.typography.bodyMedium
106-
)
107-
}
108-
}
92+
OtherUserOnInputNotification()
10993
}
11094
AnimatedVisibility(
11195
visible = showNewMessageNotification,
11296
enter = slideInVertically(initialOffsetY = { it }) + fadeIn(),
11397
exit = slideOutVertically(targetOffsetY = { it }) + fadeOut(),
11498
) {
115-
Box(
116-
modifier = Modifier
117-
.fillMaxWidth()
118-
.background(MaterialTheme.colorScheme.secondary)
119-
.padding(8.dp)
120-
) {
121-
Row(
122-
horizontalArrangement = Arrangement.SpaceBetween,
123-
verticalAlignment = Alignment.CenterVertically,
124-
modifier = Modifier.fillMaxWidth()
125-
) {
126-
val message = state.messages[state.messages.size - 1]
127-
128-
if (message is ChatMessage.TextMessage) {
129-
Text(
130-
text = message.message ?: "",
131-
color = MaterialTheme.colorScheme.onSecondary,
132-
style = MaterialTheme.typography.bodyMedium
133-
)
134-
}
135-
TextButton(onClick = {
136-
scope.launch {
137-
lazyListState.animateScrollToItem(state.messages.size - 1)
138-
}
139-
showNewMessageNotification = false
140-
}) {
141-
Text("View", color = Color.White)
142-
}
143-
}
144-
}
99+
NewMessageReceivedNotification(
100+
state = state,
101+
scope = scope,
102+
lazyListState = lazyListState,
103+
onClick = { showNewMessageNotification = false }
104+
)
145105
}
146106
ChatMessageInput(
147107
onMessage = {
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package com.example.call.ui.chat
2+
3+
import androidx.compose.foundation.background
4+
import androidx.compose.foundation.layout.Arrangement
5+
import androidx.compose.foundation.layout.Box
6+
import androidx.compose.foundation.layout.Row
7+
import androidx.compose.foundation.layout.fillMaxWidth
8+
import androidx.compose.foundation.layout.padding
9+
import androidx.compose.foundation.lazy.LazyListState
10+
import androidx.compose.material3.MaterialTheme
11+
import androidx.compose.material3.Text
12+
import androidx.compose.material3.TextButton
13+
import androidx.compose.runtime.Composable
14+
import androidx.compose.ui.Alignment
15+
import androidx.compose.ui.Modifier
16+
import androidx.compose.ui.graphics.Color
17+
import androidx.compose.ui.unit.dp
18+
import com.example.call.state.CallState
19+
import kotlinx.coroutines.CoroutineScope
20+
import kotlinx.coroutines.launch
21+
22+
@Composable
23+
fun OtherUserOnInputNotification() {
24+
Box(
25+
modifier = Modifier
26+
.fillMaxWidth()
27+
.background(MaterialTheme.colorScheme.secondary)
28+
.padding(8.dp)
29+
) {
30+
Row(
31+
horizontalArrangement = Arrangement.SpaceBetween,
32+
verticalAlignment = Alignment.CenterVertically,
33+
modifier = Modifier.fillMaxWidth()
34+
) {
35+
Text(
36+
text = "other user on input",
37+
color = MaterialTheme.colorScheme.onSecondary,
38+
style = MaterialTheme.typography.bodyMedium
39+
)
40+
}
41+
}
42+
}
43+
44+
@Composable
45+
fun NewMessageReceivedNotification(
46+
state: CallState.Success,
47+
scope: CoroutineScope,
48+
lazyListState: LazyListState,
49+
onClick: () -> Unit
50+
) {
51+
Box(
52+
modifier = Modifier
53+
.fillMaxWidth()
54+
.background(MaterialTheme.colorScheme.secondary)
55+
.padding(8.dp)
56+
) {
57+
Row(
58+
horizontalArrangement = Arrangement.SpaceBetween,
59+
verticalAlignment = Alignment.CenterVertically,
60+
modifier = Modifier.fillMaxWidth()
61+
) {
62+
val message = state.messages[state.messages.size - 1]
63+
64+
if (message is ChatMessage.TextMessage) {
65+
Text(
66+
text = message.message ?: "",
67+
color = MaterialTheme.colorScheme.onSecondary,
68+
style = MaterialTheme.typography.bodyMedium
69+
)
70+
}
71+
TextButton(onClick = {
72+
scope.launch {
73+
lazyListState.animateScrollToItem(state.messages.size - 1)
74+
}
75+
onClick()
76+
}) {
77+
Text("View", color = Color.White)
78+
}
79+
}
80+
}
81+
}

0 commit comments

Comments
 (0)