Skip to content

Commit 7022d7a

Browse files
committed
Improve divider useage and replace deprecated divider
1 parent 5418208 commit 7022d7a

File tree

6 files changed

+27
-50
lines changed

6 files changed

+27
-50
lines changed

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/RelayLocationCell.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import androidx.compose.foundation.layout.wrapContentHeight
1717
import androidx.compose.foundation.shape.CircleShape
1818
import androidx.compose.material3.MaterialTheme
1919
import androidx.compose.material3.Text
20+
import androidx.compose.material3.VerticalDivider
2021
import androidx.compose.runtime.Composable
2122
import androidx.compose.runtime.mutableStateOf
2223
import androidx.compose.runtime.saveable.rememberSaveable
@@ -29,7 +30,6 @@ import androidx.compose.ui.res.painterResource
2930
import androidx.compose.ui.tooling.preview.Preview
3031
import net.mullvad.mullvadvpn.R
3132
import net.mullvad.mullvadvpn.compose.component.ChevronView
32-
import net.mullvad.mullvadvpn.compose.component.VerticalDivider
3333
import net.mullvad.mullvadvpn.lib.theme.AppTheme
3434
import net.mullvad.mullvadvpn.lib.theme.Dimens
3535
import net.mullvad.mullvadvpn.lib.theme.color.Alpha40

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/VerticalDivider.kt

-28
This file was deleted.

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/extensions/LazyListExtensions.kt

+15-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ package net.mullvad.mullvadvpn.compose.extensions
22

33
import androidx.compose.foundation.lazy.LazyItemScope
44
import androidx.compose.foundation.lazy.LazyListScope
5+
import androidx.compose.foundation.lazy.items
56
import androidx.compose.foundation.lazy.itemsIndexed
6-
import androidx.compose.material3.Divider
7+
import androidx.compose.material3.HorizontalDivider
78
import androidx.compose.runtime.Composable
89

910
inline fun LazyListScope.itemWithDivider(
@@ -13,7 +14,18 @@ inline fun LazyListScope.itemWithDivider(
1314
) =
1415
item(key = key, contentType = contentType) {
1516
itemContent()
16-
Divider()
17+
HorizontalDivider()
18+
}
19+
20+
inline fun <T> LazyListScope.itemsWithDivider(
21+
items: List<T>,
22+
noinline key: ((item: T) -> Any)? = null,
23+
noinline contentType: (item: T) -> Any? = { null },
24+
crossinline itemContent: @Composable LazyItemScope.(item: T) -> Unit
25+
) =
26+
items(items = items, key = key, contentType = contentType) { item ->
27+
itemContent(item)
28+
HorizontalDivider()
1729
}
1830

1931
inline fun <T> LazyListScope.itemsIndexedWithDivider(
@@ -24,5 +36,5 @@ inline fun <T> LazyListScope.itemsIndexedWithDivider(
2436
) =
2537
itemsIndexed(items = items, key = key, contentType = contentType) { index, item ->
2638
itemContent(index, item)
27-
Divider()
39+
HorizontalDivider()
2840
}

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/DeviceListScreen.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import androidx.compose.foundation.layout.size
1212
import androidx.compose.foundation.layout.wrapContentHeight
1313
import androidx.compose.foundation.rememberScrollState
1414
import androidx.compose.foundation.verticalScroll
15-
import androidx.compose.material3.Divider
15+
import androidx.compose.material3.HorizontalDivider
1616
import androidx.compose.material3.Icon
1717
import androidx.compose.material3.IconButton
1818
import androidx.compose.material3.MaterialTheme
@@ -274,7 +274,7 @@ private fun ColumnScope.DeviceListContent(
274274
navigateToRemoveDeviceConfirmationDialog(deviceUiState.device)
275275
}
276276
if (state.deviceUiItems.lastIndex != index) {
277-
Divider()
277+
HorizontalDivider()
278278
}
279279
}
280280
}

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/FilterScreen.kt

+7-12
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import androidx.compose.foundation.layout.fillMaxWidth
99
import androidx.compose.foundation.layout.padding
1010
import androidx.compose.foundation.layout.systemBarsPadding
1111
import androidx.compose.foundation.lazy.LazyColumn
12-
import androidx.compose.foundation.lazy.items
13-
import androidx.compose.material3.Divider
1412
import androidx.compose.material3.Icon
1513
import androidx.compose.material3.IconButton
1614
import androidx.compose.material3.MaterialTheme
@@ -37,6 +35,8 @@ import net.mullvad.mullvadvpn.compose.button.ApplyButton
3735
import net.mullvad.mullvadvpn.compose.cell.CheckboxCell
3836
import net.mullvad.mullvadvpn.compose.cell.ExpandableComposeCell
3937
import net.mullvad.mullvadvpn.compose.cell.SelectableCell
38+
import net.mullvad.mullvadvpn.compose.extensions.itemWithDivider
39+
import net.mullvad.mullvadvpn.compose.extensions.itemsWithDivider
4040
import net.mullvad.mullvadvpn.compose.state.RelayFilterState
4141
import net.mullvad.mullvadvpn.compose.transitions.SlideInFromRightTransition
4242
import net.mullvad.mullvadvpn.lib.theme.AppTheme
@@ -146,8 +146,7 @@ fun FilterScreen(
146146
},
147147
) { contentPadding ->
148148
LazyColumn(modifier = Modifier.padding(contentPadding).fillMaxSize()) {
149-
item {
150-
Divider()
149+
itemWithDivider {
151150
ExpandableComposeCell(
152151
title = stringResource(R.string.ownership),
153152
isExpanded = ownershipExpanded,
@@ -164,17 +163,15 @@ fun FilterScreen(
164163
onCellClicked = { onSelectedOwnership(null) }
165164
)
166165
}
167-
items(uiState.filteredOwnershipByProviders) { ownership ->
168-
Divider()
166+
itemsWithDivider(uiState.filteredOwnershipByProviders) { ownership ->
169167
SelectableCell(
170168
title = stringResource(id = ownership.stringResource()),
171169
isSelected = ownership == uiState.selectedOwnership,
172170
onCellClicked = { onSelectedOwnership(ownership) }
173171
)
174172
}
175173
}
176-
item {
177-
Divider()
174+
itemWithDivider {
178175
ExpandableComposeCell(
179176
title = stringResource(R.string.providers),
180177
isExpanded = providerExpanded,
@@ -184,16 +181,14 @@ fun FilterScreen(
184181
)
185182
}
186183
if (providerExpanded) {
187-
item {
188-
Divider()
184+
itemWithDivider {
189185
CheckboxCell(
190186
providerName = stringResource(R.string.all_providers),
191187
checked = uiState.isAllProvidersChecked,
192188
onCheckedChange = { isChecked -> onAllProviderCheckChange(isChecked) }
193189
)
194190
}
195-
items(uiState.filteredProvidersByOwnership) { provider ->
196-
Divider()
191+
itemsWithDivider(uiState.filteredProvidersByOwnership) { provider ->
197192
CheckboxCell(
198193
providerName = provider.name,
199194
checked = provider in uiState.selectedProviders,

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/VpnSettingsScreen.kt

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import androidx.compose.foundation.layout.Spacer
77
import androidx.compose.foundation.layout.height
88
import androidx.compose.foundation.layout.padding
99
import androidx.compose.foundation.lazy.LazyColumn
10-
import androidx.compose.foundation.lazy.itemsIndexed
11-
import androidx.compose.material3.Divider
1210
import androidx.compose.material3.MaterialTheme
1311
import androidx.compose.material3.SnackbarHostState
1412
import androidx.compose.material3.Text
@@ -67,6 +65,7 @@ import net.mullvad.mullvadvpn.compose.destinations.WireguardPortInfoDialogDestin
6765
import net.mullvad.mullvadvpn.compose.dialog.WireguardCustomPortNavArgs
6866
import net.mullvad.mullvadvpn.compose.dialog.WireguardPortInfoDialogArgument
6967
import net.mullvad.mullvadvpn.compose.extensions.itemWithDivider
68+
import net.mullvad.mullvadvpn.compose.extensions.itemsIndexedWithDivider
7069
import net.mullvad.mullvadvpn.compose.state.VpnSettingsUiState
7170
import net.mullvad.mullvadvpn.compose.test.LAZY_LIST_LAST_ITEM_TEST_TAG
7271
import net.mullvad.mullvadvpn.compose.test.LAZY_LIST_QUANTUM_ITEM_OFF_TEST_TAG
@@ -436,15 +435,14 @@ fun VpnSettingsScreen(
436435
}
437436

438437
if (uiState.isCustomDnsEnabled) {
439-
itemsIndexed(uiState.customDnsItems) { index, item ->
438+
itemsIndexedWithDivider(uiState.customDnsItems) { index, item ->
440439
DnsCell(
441440
address = item.address,
442441
isUnreachableLocalDnsWarningVisible =
443442
item.isLocal && !uiState.isLocalNetworkSharingEnabled,
444443
onClick = { navigateToDns(index, item.address) },
445444
modifier = Modifier.animateItemPlacement()
446445
)
447-
Divider()
448446
}
449447

450448
itemWithDivider {

0 commit comments

Comments
 (0)