Skip to content

Commit c68546e

Browse files
committed
Use MullvadListItem in SelectLocationScreen
1 parent 7c3d859 commit c68546e

File tree

18 files changed

+231
-553
lines changed

18 files changed

+231
-553
lines changed

android/lib/feature/customlist/impl/src/main/java/net/mullvad/mullvadvpn/feature/customlist/impl/screen/editlist/EditCustomListScreen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ fun EditCustomListScreen(
143143
},
144144
) { modifier: Modifier ->
145145
Column(
146-
modifier = modifier,
146+
modifier = modifier.padding(horizontal = Dimens.sideMarginNew),
147147
verticalArrangement = Arrangement.spacedBy(Dimens.listItemDivider),
148148
horizontalAlignment = Alignment.CenterHorizontally,
149149
) {

android/lib/feature/customlist/impl/src/main/java/net/mullvad/mullvadvpn/feature/customlist/impl/screen/editlocations/CustomListLocationsScreen.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ import net.mullvad.mullvadvpn.lib.ui.component.NavigateBackIconButton
4747
import net.mullvad.mullvadvpn.lib.ui.component.ScaffoldWithSmallTopBar
4848
import net.mullvad.mullvadvpn.lib.ui.component.dialog.Confirmed
4949
import net.mullvad.mullvadvpn.lib.ui.component.drawVerticalScrollbar
50-
import net.mullvad.mullvadvpn.lib.ui.component.relaylist.CheckableRelayLocationCell
51-
import net.mullvad.mullvadvpn.lib.ui.component.relaylist.ItemPosition
50+
import net.mullvad.mullvadvpn.lib.ui.component.relaylist.CheckableRelayListItem
5251
import net.mullvad.mullvadvpn.lib.ui.designsystem.MullvadCircularProgressIndicatorLarge
52+
import net.mullvad.mullvadvpn.lib.ui.designsystem.Position
5353
import net.mullvad.mullvadvpn.lib.ui.resource.R
5454
import net.mullvad.mullvadvpn.lib.ui.tag.SAVE_BUTTON_TEST_TAG
5555
import net.mullvad.mullvadvpn.lib.ui.theme.AppTheme
@@ -236,7 +236,7 @@ private fun LazyListScope.content(
236236
}
237237
} else {
238238
items(uiState.locations, key = { listItem -> listItem.item.id }) { listItem ->
239-
CheckableRelayLocationCell(
239+
CheckableRelayListItem(
240240
modifier = Modifier.animateItem().positionalPadding(listItem.itemPosition),
241241
item = listItem,
242242
onRelayCheckedChange = { isChecked ->
@@ -263,10 +263,10 @@ private fun LocationsEmptyText(searchTerm: String) {
263263

264264
// TODO Should maybe be in design system? Maybe if we use the correct composable we have it already?
265265
@Composable
266-
fun Modifier.positionalPadding(itemPosition: ItemPosition): Modifier =
266+
fun Modifier.positionalPadding(itemPosition: Position): Modifier =
267267
when (itemPosition) {
268-
ItemPosition.Top,
269-
ItemPosition.Single -> padding(top = Dimens.miniPadding)
270-
ItemPosition.Middle -> padding(top = Dimens.listItemDivider)
271-
ItemPosition.Bottom -> padding(top = Dimens.listItemDivider, bottom = Dimens.miniPadding)
268+
Position.Top,
269+
Position.Single -> padding(top = Dimens.miniPadding)
270+
Position.Middle -> padding(top = Dimens.listItemDivider)
271+
Position.Bottom -> padding(top = Dimens.listItemDivider, bottom = Dimens.miniPadding)
272272
}

android/lib/feature/customlist/impl/src/main/java/net/mullvad/mullvadvpn/feature/customlist/impl/screen/editlocations/CustomListLocationsViewModel.kt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ import net.mullvad.mullvadvpn.lib.model.communication.CustomListActionResultData
3030
import net.mullvad.mullvadvpn.lib.model.communication.LocationsChanged
3131
import net.mullvad.mullvadvpn.lib.repository.RelayListRepository
3232
import net.mullvad.mullvadvpn.lib.ui.component.relaylist.CheckableRelayListItem
33-
import net.mullvad.mullvadvpn.lib.ui.component.relaylist.ItemPosition
33+
import net.mullvad.mullvadvpn.lib.ui.designsystem.Hierarchy
34+
import net.mullvad.mullvadvpn.lib.ui.designsystem.Position
35+
import net.mullvad.mullvadvpn.lib.ui.designsystem.nextDown
3436
import net.mullvad.mullvadvpn.lib.usecase.customlists.CustomListActionUseCase
3537
import net.mullvad.mullvadvpn.lib.usecase.customlists.CustomListRelayItemsUseCase
3638

@@ -83,6 +85,7 @@ class CustomListLocationsViewModel(
8385
locations =
8486
filteredRelayCountries.flatMap {
8587
it.toRelayItems(
88+
hierarchy = Hierarchy.Parent,
8689
isSelected = { it in selectedLocations },
8790
isExpanded = { it in expandedLocations },
8891
isLastChild = true,
@@ -253,22 +256,22 @@ class CustomListLocationsViewModel(
253256
private fun RelayItem.Location.toRelayItems(
254257
isSelected: (RelayItem) -> Boolean,
255258
isExpanded: (RelayItemId) -> Boolean,
256-
depth: Int = 0,
259+
hierarchy: Hierarchy,
257260
isLastChild: Boolean,
258261
): List<CheckableRelayListItem> = buildList {
259262
val expanded = isExpanded(id)
260263
add(
261264
CheckableRelayListItem(
262265
item = this@toRelayItems,
263-
depth = depth,
266+
hierarchy = hierarchy,
264267
checked = isSelected(this@toRelayItems),
265268
expanded = expanded,
266269
itemPosition =
267270
when {
268271
this@toRelayItems is RelayItem.Location.Country ->
269-
if (!expanded) ItemPosition.Single else ItemPosition.Top
270-
isLastChild && !expanded -> ItemPosition.Bottom
271-
else -> ItemPosition.Middle
272+
if (!expanded) Position.Single else Position.Top
273+
isLastChild && !expanded -> Position.Bottom
274+
else -> Position.Middle
272275
},
273276
)
274277
)
@@ -280,7 +283,7 @@ class CustomListLocationsViewModel(
280283
relay.toRelayItems(
281284
isSelected = isSelected,
282285
isExpanded = isExpanded,
283-
depth = depth + 1,
286+
hierarchy = hierarchy.nextDown(),
284287
isLastChild = isLastChild && index == relays.lastIndex,
285288
)
286289
}
@@ -292,7 +295,7 @@ class CustomListLocationsViewModel(
292295
item.toRelayItems(
293296
isSelected = isSelected,
294297
isExpanded = isExpanded,
295-
depth = depth + 1,
298+
hierarchy = hierarchy.nextDown(),
296299
isLastChild = isLastChild && index == cities.lastIndex,
297300
)
298301
}

android/lib/feature/location/impl/src/androidTest/kotlin/net/mullvad/mullvadvpn/feature/location/impl/SelectLocationScreenTest.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import net.mullvad.mullvadvpn.feature.location.impl.data.DUMMY_RELAY_ITEM_CUSTOM
2222
import net.mullvad.mullvadvpn.feature.location.impl.data.createSimpleRelayListItemList
2323
import net.mullvad.mullvadvpn.feature.location.impl.list.SelectLocationListUiState
2424
import net.mullvad.mullvadvpn.feature.location.impl.list.SelectLocationListViewModel
25-
import net.mullvad.mullvadvpn.feature.location.impl.util.onNodeWithTagAndText
25+
import net.mullvad.mullvadvpn.feature.location.impl.util.onNodeTextAndAncestorTag
2626
import net.mullvad.mullvadvpn.feature.location.impl.util.performLongClick
2727
import net.mullvad.mullvadvpn.lib.common.Lc
2828
import net.mullvad.mullvadvpn.lib.common.Lce
@@ -31,8 +31,9 @@ import net.mullvad.mullvadvpn.lib.model.HopSelection
3131
import net.mullvad.mullvadvpn.lib.model.MultihopRelayListType
3232
import net.mullvad.mullvadvpn.lib.model.RelayItem
3333
import net.mullvad.mullvadvpn.lib.model.RelayListType
34-
import net.mullvad.mullvadvpn.lib.ui.component.relaylist.ItemPosition
3534
import net.mullvad.mullvadvpn.lib.ui.component.relaylist.RelayListItem
35+
import net.mullvad.mullvadvpn.lib.ui.designsystem.Hierarchy
36+
import net.mullvad.mullvadvpn.lib.ui.designsystem.Position
3637
import net.mullvad.mullvadvpn.lib.ui.tag.GEOLOCATION_NAME_TAG
3738
import net.mullvad.mullvadvpn.lib.ui.tag.RECENT_CELL_TEST_TAG
3839
import net.mullvad.mullvadvpn.lib.ui.tag.SELECT_LOCATION_CUSTOM_LIST_BOTTOM_SHEET_TEST_TAG
@@ -151,7 +152,8 @@ class SelectLocationScreenTest {
151152
DUMMY_RELAY_COUNTRIES.map {
152153
RelayListItem.GeoLocationItem(
153154
item = it,
154-
itemPosition = ItemPosition.Single,
155+
itemPosition = Position.Single,
156+
hierarchy = Hierarchy.Parent,
155157
)
156158
},
157159
customLists = emptyList(),
@@ -362,7 +364,8 @@ class SelectLocationScreenTest {
362364
listOf(
363365
RelayListItem.GeoLocationItem(
364366
relayItem,
365-
itemPosition = ItemPosition.Single,
367+
itemPosition = Position.Single,
368+
hierarchy = Hierarchy.Parent,
366369
)
367370
),
368371
customLists = emptyList(),
@@ -491,8 +494,8 @@ class SelectLocationScreenTest {
491494
)
492495

493496
// Assert
494-
onNodeWithTagAndText(
495-
testTag = GEOLOCATION_NAME_TAG,
497+
onNodeTextAndAncestorTag(
498+
ancestorTag = GEOLOCATION_NAME_TAG,
496499
text = selectableItem.name,
497500
useUnmergedTree = true,
498501
)

android/lib/feature/location/impl/src/androidTest/kotlin/net/mullvad/mullvadvpn/feature/location/impl/data/DummyRelayListItem.kt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ package net.mullvad.mullvadvpn.feature.location.impl.data
33
import net.mullvad.mullvadvpn.lib.common.util.relaylist.descendants
44
import net.mullvad.mullvadvpn.lib.model.RelayItem
55
import net.mullvad.mullvadvpn.lib.model.RelayItemId
6-
import net.mullvad.mullvadvpn.lib.ui.component.relaylist.ItemPosition
76
import net.mullvad.mullvadvpn.lib.ui.component.relaylist.RelayListItem
7+
import net.mullvad.mullvadvpn.lib.ui.designsystem.Hierarchy
8+
import net.mullvad.mullvadvpn.lib.ui.designsystem.Position
89

910
@Suppress("CyclomaticComplexMethod")
1011
fun createSimpleRelayListItemList(
@@ -35,11 +36,12 @@ fun createSimpleRelayListItemList(
3536
item = country,
3637
isSelected = country == selectedItem,
3738
expanded = descendantIsSelected,
39+
hierarchy = Hierarchy.Parent,
3840
itemPosition =
3941
if (descendantIsSelected) {
40-
ItemPosition.Top
42+
Position.Top
4143
} else {
42-
ItemPosition.Single
44+
Position.Single
4345
},
4446
)
4547
)
@@ -51,11 +53,12 @@ fun createSimpleRelayListItemList(
5153
item = city,
5254
isSelected = city.id == selectedItem,
5355
expanded = childIsSelected,
56+
hierarchy = Hierarchy.Parent,
5457
itemPosition =
5558
if (country.cities.last() == city && !childIsSelected) {
56-
ItemPosition.Bottom
59+
Position.Bottom
5760
} else {
58-
ItemPosition.Middle
61+
Position.Middle
5962
},
6063
)
6164
)
@@ -65,11 +68,12 @@ fun createSimpleRelayListItemList(
6568
RelayListItem.GeoLocationItem(
6669
item = relay,
6770
isSelected = relay.id == selectedItem,
71+
hierarchy = Hierarchy.Parent,
6872
itemPosition =
6973
if (city.relays.last() == relay) {
70-
ItemPosition.Bottom
74+
Position.Bottom
7175
} else {
72-
ItemPosition.Middle
76+
Position.Middle
7377
},
7478
)
7579
)

android/lib/feature/location/impl/src/androidTest/kotlin/net/mullvad/mullvadvpn/feature/location/impl/util/Finders.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package net.mullvad.mullvadvpn.feature.location.impl.util
22

33
import androidx.compose.ui.test.SemanticsNodeInteraction
44
import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
5+
import androidx.compose.ui.test.hasAnyAncestor
56
import androidx.compose.ui.test.hasContentDescription
67
import androidx.compose.ui.test.hasParent
78
import androidx.compose.ui.test.hasTestTag
@@ -16,6 +17,18 @@ fun SemanticsNodeInteractionsProvider.onNodeWithTagAndText(
1617
): SemanticsNodeInteraction =
1718
onNode(hasTestTag(testTag).and(hasText(text, substring, ignoreCase)), useUnmergedTree)
1819

20+
fun SemanticsNodeInteractionsProvider.onNodeTextAndAncestorTag(
21+
text: String,
22+
ancestorTag: String,
23+
substring: Boolean = false,
24+
ignoreCase: Boolean = false,
25+
useUnmergedTree: Boolean = false,
26+
): SemanticsNodeInteraction =
27+
onNode(
28+
hasText(text, substring, ignoreCase).and(hasAnyAncestor(hasTestTag(ancestorTag))),
29+
useUnmergedTree,
30+
)
31+
1932
fun SemanticsNodeInteractionsProvider.onNodeWithContentDescriptionAndParentTag(
2033
contentDescription: String,
2134
parentTag: String,

android/lib/feature/location/impl/src/main/kotlin/net/mullvad/mullvadvpn/feature/location/impl/RelayListContent.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ import net.mullvad.mullvadvpn.lib.model.RelayItem
2626
import net.mullvad.mullvadvpn.lib.model.RelayItemId
2727
import net.mullvad.mullvadvpn.lib.model.RelayListType
2828
import net.mullvad.mullvadvpn.lib.ui.component.listitem.SelectableListItem
29-
import net.mullvad.mullvadvpn.lib.ui.component.relaylist.ItemPosition
3029
import net.mullvad.mullvadvpn.lib.ui.component.relaylist.RelayListItem
3130
import net.mullvad.mullvadvpn.lib.ui.component.relaylist.SelectableRelayListItem
3231
import net.mullvad.mullvadvpn.lib.ui.component.text.ListItemInfo
32+
import net.mullvad.mullvadvpn.lib.ui.designsystem.Hierarchy
3333
import net.mullvad.mullvadvpn.lib.ui.designsystem.ListHeader
34+
import net.mullvad.mullvadvpn.lib.ui.designsystem.Position
3435
import net.mullvad.mullvadvpn.lib.ui.tag.LOCATION_CELL_TEST_TAG
3536
import net.mullvad.mullvadvpn.lib.ui.tag.RECENT_CELL_TEST_TAG
3637
import net.mullvad.mullvadvpn.lib.ui.tag.SELECT_LOCATION_CUSTOM_LIST_HEADER_TEST_TAG
@@ -113,12 +114,12 @@ private fun LocationsEmptyText(searchTerm: String) {
113114
}
114115

115116
@Composable
116-
fun Modifier.positionalPadding(itemPosition: ItemPosition): Modifier =
117+
fun Modifier.positionalPadding(itemPosition: Position): Modifier =
117118
when (itemPosition) {
118-
ItemPosition.Top,
119-
ItemPosition.Single -> padding(top = Dimens.miniPadding)
120-
ItemPosition.Middle -> padding(top = Dimens.listItemDivider)
121-
ItemPosition.Bottom -> padding(top = Dimens.listItemDivider, bottom = Dimens.miniPadding)
119+
Position.Top,
120+
Position.Single -> padding(top = Dimens.miniPadding)
121+
Position.Middle -> padding(top = Dimens.listItemDivider)
122+
Position.Bottom -> padding(top = Dimens.listItemDivider, bottom = Dimens.miniPadding)
122123
}
123124

124125
@Composable
@@ -231,7 +232,7 @@ private fun CustomListEntryItem(
231232
onClick = { onSelect(listItem.item) },
232233
// Only direct children can be removed
233234
onLongClick =
234-
if (listItem.depth == 1) {
235+
if (listItem.hierarchy == Hierarchy.Child1) {
235236
{
236237
onUpdateBottomSheetState(
237238
LocationBottomSheetState.ShowCustomListsEntryBottomSheet(

0 commit comments

Comments
 (0)