Skip to content

Commit

Permalink
Remove some unnecessary LocationNode subclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Petersson committed May 14, 2024
1 parent c828a96 commit 54e3a30
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class AllLocationDataSource: LocationDataSourceProtocol {
) {
switch location {
case let .country(countryCode):
let countryNode = CountryLocationNode(
let countryNode = LocationNode(
name: serverLocation.country,
code: LocationNode.combineNodeCodes([countryCode]),
locations: [location],
Expand All @@ -73,7 +73,7 @@ class AllLocationDataSource: LocationDataSourceProtocol {
}

case let .city(countryCode, cityCode):
let cityNode = CityLocationNode(
let cityNode = LocationNode(
name: serverLocation.city,
code: LocationNode.combineNodeCodes([countryCode, cityCode]),
locations: [location],
Expand All @@ -88,7 +88,7 @@ class AllLocationDataSource: LocationDataSourceProtocol {
}

case let .hostname(countryCode, cityCode, hostCode):
let hostNode = HostLocationNode(
let hostNode = LocationNode(
name: relay.hostname,
code: LocationNode.combineNodeCodes([hostCode]),
locations: [location],
Expand Down
25 changes: 15 additions & 10 deletions ios/MullvadVPN/View controllers/SelectLocation/LocationCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -316,18 +316,23 @@ extension LocationCell {
checkboxButton.accessibilityIdentifier = .customListLocationCheckmarkButton
checkboxButton.isSelected = item.isSelected
checkboxButton.tintColor = item.isSelected ? .successColor : .white
accessibilityValue = item.node.code

if item.node is CountryLocationNode {
accessibilityIdentifier = .countryLocationCell
accessibilityValue = item.node.code
} else if item.node is CityLocationNode {
accessibilityIdentifier = .cityLocationCell
accessibilityValue = item.node.code
} else if item.node is HostLocationNode {
accessibilityIdentifier = .relayLocationCell
accessibilityValue = item.node.code
} else if item.node is CustomListLocationNode {
if item.node is CustomListLocationNode {
accessibilityIdentifier = .customListLocationCell
} else {
// Only custom list nodes have more than one location. Therefore checking first
// location here is fine.
switch item.node.locations.first {
case .country:
accessibilityIdentifier = .countryLocationCell
case .city:
accessibilityIdentifier = .cityLocationCell
case .hostname:
accessibilityIdentifier = .relayLocationCell
case nil:
break
}
}

setBehavior(behavior)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,3 @@ class CustomListLocationNode: LocationNode {
)
}
}

class CountryLocationNode: LocationNode {}

class CityLocationNode: LocationNode {}

class HostLocationNode: LocationNode {}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ class LocationNodeTests: XCTestCase {
showsChildren: false,
customList: CustomList(name: "List", locations: [])
)
let countryNode = CountryLocationNode(name: "Country", code: "country", showsChildren: false)
let cityNode = CityLocationNode(name: "City", code: "city", showsChildren: false)
let hostNode = HostLocationNode(name: "Host", code: "host", showsChildren: false)
let countryNode = LocationNode(name: "Country", code: "country", showsChildren: false)
let cityNode = LocationNode(name: "City", code: "city", showsChildren: false)
let hostNode = LocationNode(name: "Host", code: "host", showsChildren: false)

override func setUp() async throws {
createNodeTree()
Expand Down

0 comments on commit 54e3a30

Please sign in to comment.