@@ -29,7 +29,6 @@ import androidx.compose.ui.text.style.TextOverflow
29
29
import androidx.compose.ui.tooling.preview.Preview
30
30
import androidx.compose.ui.tooling.preview.PreviewParameter
31
31
import androidx.compose.ui.unit.dp
32
- import mullvad_daemon.management_interface.relay
33
32
import net.mullvad.mullvadvpn.R
34
33
import net.mullvad.mullvadvpn.compose.component.Chevron
35
34
import net.mullvad.mullvadvpn.compose.component.MullvadCheckbox
@@ -49,7 +48,10 @@ private fun PreviewCheckableRelayLocationCell(
49
48
) {
50
49
AppTheme {
51
50
Column (Modifier .background(color = MaterialTheme .colorScheme.background)) {
52
- // relayItems.map { CheckableRelayLocationCell(item = it) }
51
+ relayItems.map {
52
+ CheckableRelayLocationCell (
53
+ item = it, checked = false , expanded = false , depth = 0 , onExpand = {})
54
+ }
53
55
}
54
56
}
55
57
}
@@ -71,14 +73,13 @@ fun StatusRelayItemCell(
71
73
) {
72
74
73
75
RelayItemCell (
76
+ modifier = modifier,
74
77
item,
75
78
isSelected,
76
79
leadingContent = {
77
80
if (isSelected) {
78
81
Icon (
79
- painter = painterResource(id = R .drawable.icon_tick),
80
- contentDescription = null
81
- )
82
+ painter = painterResource(id = R .drawable.icon_tick), contentDescription = null )
82
83
} else {
83
84
Box (
84
85
modifier =
@@ -93,23 +94,21 @@ fun StatusRelayItemCell(
93
94
item.active -> activeColor
94
95
else -> inactiveColor
95
96
},
96
- shape = CircleShape
97
- )
98
- )
97
+ shape = CircleShape ))
99
98
}
100
99
},
101
100
onClick = onClick,
102
101
onLongClick = onLongClick,
103
102
onToggleExpand = onToggleExpand,
104
103
isExpanded = isExpanded,
105
104
depth = depth,
106
- modifier = modifier,
107
105
)
108
106
}
109
107
110
108
@OptIn(ExperimentalFoundationApi ::class )
111
109
@Composable
112
110
fun RelayItemCell (
111
+ modifier : Modifier = Modifier ,
113
112
item : RelayItem ,
114
113
isSelected : Boolean ,
115
114
leadingContent : (@Composable RowScope .() -> Unit )? = null,
@@ -118,7 +117,6 @@ fun RelayItemCell(
118
117
onToggleExpand : ((Boolean ) -> Unit ),
119
118
isExpanded : Boolean ,
120
119
depth : Int ,
121
- modifier : Modifier = Modifier ,
122
120
) {
123
121
124
122
val leadingContentStartPadding = Dimens .cellStartPadding
@@ -135,25 +133,23 @@ fun RelayItemCell(
135
133
item is RelayItem .CustomList && ! item.active ->
136
134
MaterialTheme .colorScheme.surfaceTint
137
135
else -> depth.toBackgroundColor()
138
- }
139
- )
136
+ })
140
137
.combinedClickable(
141
138
enabled = item.active,
142
139
onClick = onClick,
143
140
onLongClick = onLongClick,
144
141
)
145
142
.padding(start = startPadding),
146
- verticalAlignment = Alignment .CenterVertically
147
- ) {
148
- if (leadingContent != null ) {
149
- leadingContent()
150
- }
151
- Name (modifier = Modifier .weight(1f ), relay = item)
143
+ verticalAlignment = Alignment .CenterVertically ) {
144
+ if (leadingContent != null ) {
145
+ leadingContent()
146
+ }
147
+ Name (modifier = Modifier .weight(1f ), relay = item)
152
148
153
- if (item.hasChildren) {
154
- ExpandButton (isExpanded = isExpanded, onClick = { onToggleExpand(! isExpanded) })
149
+ if (item.hasChildren) {
150
+ ExpandButton (isExpanded = isExpanded, onClick = { onToggleExpand(! isExpanded) })
151
+ }
155
152
}
156
- }
157
153
}
158
154
159
155
@Composable
@@ -167,20 +163,18 @@ fun CheckableRelayLocationCell(
167
163
depth : Int
168
164
) {
169
165
RelayItemCell (
166
+ modifier = modifier,
170
167
item = item,
171
- isExpanded = expanded,
172
- onToggleExpand = onExpand,
168
+ isSelected = false ,
173
169
leadingContent = {
174
170
MullvadCheckbox (
175
171
checked = checked,
176
- onCheckedChange = { isChecked -> onRelayCheckedChange(isChecked) }
177
- )
172
+ onCheckedChange = { isChecked -> onRelayCheckedChange(isChecked) })
178
173
},
179
- modifier = modifier,
180
174
onClick = { onRelayCheckedChange(! checked) },
181
- onLongClick = null ,
182
- depth = depth ,
183
- isSelected = false
175
+ onToggleExpand = onExpand ,
176
+ isExpanded = expanded ,
177
+ depth = depth
184
178
)
185
179
}
186
180
@@ -196,28 +190,24 @@ private fun Name(modifier: Modifier = Modifier, relay: RelayItem) {
196
190
AlphaVisible
197
191
} else {
198
192
AlphaInactive
199
- }
200
- )
193
+ })
201
194
.padding(horizontal = Dimens .smallPadding, vertical = Dimens .mediumPadding),
202
195
maxLines = 1 ,
203
- overflow = TextOverflow .Ellipsis
204
- )
196
+ overflow = TextOverflow .Ellipsis )
205
197
}
206
198
207
199
@Composable
208
200
private fun RowScope.ExpandButton (isExpanded : Boolean , onClick : (expand: Boolean ) -> Unit ) {
209
201
VerticalDivider (
210
202
color = MaterialTheme .colorScheme.background,
211
- modifier = Modifier .padding(vertical = Dimens .verticalDividerPadding)
212
- )
203
+ modifier = Modifier .padding(vertical = Dimens .verticalDividerPadding))
213
204
Chevron (
214
205
isExpanded = isExpanded,
215
206
modifier =
216
207
Modifier .fillMaxHeight()
217
208
.clickable { onClick(! isExpanded) }
218
209
.padding(horizontal = Dimens .largePadding)
219
- .align(Alignment .CenterVertically )
220
- )
210
+ .align(Alignment .CenterVertically ))
221
211
}
222
212
223
213
@Suppress(" MagicNumber" )
0 commit comments