@@ -7,25 +7,33 @@ import androidx.compose.foundation.layout.Row
7
7
import androidx.compose.foundation.layout.fillMaxHeight
8
8
import androidx.compose.foundation.layout.fillMaxWidth
9
9
import androidx.compose.foundation.layout.padding
10
+ import androidx.compose.foundation.lazy.LazyRow
11
+ import androidx.compose.material.icons.Icons
12
+ import androidx.compose.material.icons.filled.Close
10
13
import androidx.compose.material3.AssistChip
14
+ import androidx.compose.material3.AssistChipDefaults
11
15
import androidx.compose.material3.Card
12
16
import androidx.compose.material3.CircularProgressIndicator
17
+ import androidx.compose.material3.ElevatedAssistChip
13
18
import androidx.compose.material3.Icon
14
19
import androidx.compose.material3.MaterialTheme
20
+ import androidx.compose.material3.OutlinedButton
15
21
import androidx.compose.material3.Text
16
22
import androidx.compose.runtime.Composable
17
23
import androidx.compose.ui.Alignment
18
24
import androidx.compose.ui.Modifier
19
25
import androidx.compose.ui.res.painterResource
20
26
import androidx.compose.ui.res.stringResource
21
27
import androidx.compose.ui.unit.Dp
28
+ import androidx.compose.ui.unit.dp
22
29
import dev.musakavak.uzayan.R
23
30
import dev.musakavak.uzayan.socket.ConnectionState
24
31
25
32
@Composable
26
33
fun ConnectionStateCard (
27
34
padding : Dp ,
28
35
startService : (String? , Int? , Int? , Boolean? ) -> Unit ,
36
+ closeConnection : () -> Unit ,
29
37
startServiceFromUri : (Uri ) -> Unit ,
30
38
setSheetContent : (String ) -> Unit
31
39
) {
@@ -41,28 +49,32 @@ fun ConnectionStateCard(
41
49
) {
42
50
when (ConnectionState .currentStatus) {
43
51
200 -> ManualPairCard (startService, startServiceFromUri)
44
- 201 -> ConnectingStatus (padding)
45
- 202 -> ConnectedDeviceCard (padding, setSheetContent)
52
+ 201 -> ConnectingStatus (padding,closeConnection )
53
+ 202 -> ConnectedDeviceCard (padding, setSheetContent,closeConnection )
46
54
}
47
55
}
48
56
}
49
57
}
50
58
51
59
@Composable
52
- fun ConnectingStatus (padding : Dp ) {
60
+ fun ConnectingStatus (padding : Dp , closeConnection : () -> Unit ) {
53
61
Row (
62
+ modifier = Modifier .fillMaxWidth(),
54
63
verticalAlignment = Alignment .CenterVertically ,
55
64
horizontalArrangement = Arrangement .SpaceBetween
56
65
) {
57
66
ConnectionState .connectingStatus?.let {
58
67
CircularProgressIndicator (modifier = Modifier .padding(end = padding))
59
68
Text (text = stringResource(id = it), style = MaterialTheme .typography.headlineLarge)
69
+ OutlinedButton (onClick = closeConnection) {
70
+ Text (text = stringResource(id = R .string.cancel))
71
+ }
60
72
}
61
73
}
62
74
}
63
75
64
76
@Composable
65
- fun ConnectedDeviceCard (padding : Dp , setSheetContent : (String ) -> Unit ) {
77
+ fun ConnectedDeviceCard (padding : Dp , setSheetContent : (String ) -> Unit , closeConnection : () -> Unit ) {
66
78
Column (modifier = Modifier .fillMaxHeight()) {
67
79
Row (
68
80
modifier = Modifier .fillMaxWidth(),
@@ -90,29 +102,56 @@ fun ConnectedDeviceCard(padding: Dp, setSheetContent: (String) -> Unit) {
90
102
)
91
103
}
92
104
}
93
- Row (modifier = Modifier .fillMaxWidth()) {
94
- AssistChip (onClick = { setSheetContent(" commands" ) },
95
- leadingIcon = {
96
- Icon (
97
- painter = painterResource(R .drawable.terminal),
98
- contentDescription = stringResource(R .string.remote_commands)
99
- )
100
- },
101
- label = {
102
- Text (text = stringResource(R .string.remote_commands))
103
- }
104
- )
105
- AssistChip (onClick = { setSheetContent(" screencast" ) },
106
- leadingIcon = {
107
- Icon (
108
- painter = painterResource(R .drawable.terminal),
109
- contentDescription = stringResource(R .string.screencast)
110
- )
111
- },
112
- label = {
113
- Text (text = stringResource(R .string.screencast))
114
- }
115
- )
105
+ LazyRow (
106
+ modifier = Modifier .fillMaxWidth(),
107
+ horizontalArrangement = Arrangement .spacedBy(8 .dp)
108
+ ) {
109
+ item {
110
+ AssistChip (
111
+ onClick = { setSheetContent(" commands" ) },
112
+ leadingIcon = {
113
+ Icon (
114
+ painter = painterResource(R .drawable.terminal),
115
+ contentDescription = stringResource(R .string.remote_commands)
116
+ )
117
+ },
118
+ label = {
119
+ Text (text = stringResource(R .string.remote_commands))
120
+ }
121
+ )
122
+ }
123
+ item {
124
+ AssistChip (
125
+ onClick = { setSheetContent(" screencast" ) },
126
+ leadingIcon = {
127
+ Icon (
128
+ painter = painterResource(R .drawable.terminal),
129
+ contentDescription = stringResource(R .string.screencast)
130
+ )
131
+ },
132
+ label = {
133
+ Text (text = stringResource(R .string.screencast))
134
+ }
135
+ )
136
+ }
137
+ item {
138
+ AssistChip (
139
+ onClick = closeConnection,
140
+ leadingIcon = {
141
+ Icon (
142
+ imageVector = Icons .Default .Close ,
143
+ contentDescription = " Dangerous Action" ,
144
+ tint = MaterialTheme .colorScheme.error
145
+ )
146
+ },
147
+ label = {
148
+ Text (
149
+ text = stringResource(R .string.close),
150
+ color = MaterialTheme .colorScheme.error
151
+ )
152
+ },
153
+ )
154
+ }
116
155
}
117
156
}
118
157
}
0 commit comments