Skip to content

Commit 8506380

Browse files
mojganiibuggmagnet
authored andcommitted
adding section header view in select location

- each section should have its own distinct header view. - custom list section has an action that should take user to add/edit custom list.it will be coming during upcoming changes. - refactoring location cell - removing LocationCellFactory
1 parent 1c89cd0 commit 8506380

11 files changed

+210
-223
lines changed

ios/MullvadVPN.xcodeproj/project.pbxproj

+4-4
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@
116116
584023292A407F5F007B27AC /* libtunnel_obfuscator_proxy.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 584023282A407F5F007B27AC /* libtunnel_obfuscator_proxy.a */; };
117117
58421030282D8A3C00F24E46 /* UpdateAccountDataOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5842102F282D8A3C00F24E46 /* UpdateAccountDataOperation.swift */; };
118118
58421032282E42B000F24E46 /* UpdateDeviceDataOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58421031282E42B000F24E46 /* UpdateDeviceDataOperation.swift */; };
119-
58435AC229CB2A350099C71B /* LocationCellFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58435AC129CB2A350099C71B /* LocationCellFactory.swift */; };
120119
584592612639B4A200EF967F /* TermsOfServiceContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 584592602639B4A200EF967F /* TermsOfServiceContentView.swift */; };
121120
5846227126E229F20035F7C2 /* StoreSubscription.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5846227026E229F20035F7C2 /* StoreSubscription.swift */; };
122121
5846227326E22A160035F7C2 /* StorePaymentObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5846227226E22A160035F7C2 /* StorePaymentObserver.swift */; };
@@ -850,6 +849,7 @@
850849
F09D04C12AF39EA2003D4F89 /* OutgoingConnectionService.swift in Sources */ = {isa = PBXBuildFile; fileRef = F09D04BC2AEBB7C5003D4F89 /* OutgoingConnectionService.swift */; };
851850
F0A92B3C2B8E44F900DC7B37 /* InMemoryCustomListRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0A92B3B2B8E44F900DC7B37 /* InMemoryCustomListRepository.swift */; };
852851
F0B0E6972AFE6E7E001DC66B /* XCTest+Async.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0B0E6962AFE6E7E001DC66B /* XCTest+Async.swift */; };
852+
F0BE65372B9F136A005CC385 /* LocationSectionHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0BE65362B9F136A005CC385 /* LocationSectionHeaderView.swift */; };
853853
F0C2AEFD2A0BB5CC00986207 /* NotificationProviderIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0C2AEFC2A0BB5CC00986207 /* NotificationProviderIdentifier.swift */; };
854854
F0C3333C2B31A29C00D1A478 /* MullvadSettings.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 58B2FDD32AA71D2A003EB5C6 /* MullvadSettings.framework */; };
855855
F0C6A8432AB08E54000777A8 /* RedeemVoucherViewConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0C6A8422AB08E54000777A8 /* RedeemVoucherViewConfiguration.swift */; };
@@ -1420,7 +1420,6 @@
14201420
5842102D282D3FC200F24E46 /* ResultBlockOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResultBlockOperation.swift; sourceTree = "<group>"; };
14211421
5842102F282D8A3C00F24E46 /* UpdateAccountDataOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpdateAccountDataOperation.swift; sourceTree = "<group>"; };
14221422
58421031282E42B000F24E46 /* UpdateDeviceDataOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpdateDeviceDataOperation.swift; sourceTree = "<group>"; };
1423-
58435AC129CB2A350099C71B /* LocationCellFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocationCellFactory.swift; sourceTree = "<group>"; };
14241423
584592602639B4A200EF967F /* TermsOfServiceContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TermsOfServiceContentView.swift; sourceTree = "<group>"; };
14251424
5846226426E0D9630035F7C2 /* ProductsRequestOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductsRequestOperation.swift; sourceTree = "<group>"; };
14261425
5846227026E229F20035F7C2 /* StoreSubscription.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreSubscription.swift; sourceTree = "<group>"; };
@@ -1984,6 +1983,7 @@
19841983
F09D04BF2AF39D63003D4F89 /* OutgoingConnectionServiceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OutgoingConnectionServiceTests.swift; sourceTree = "<group>"; };
19851984
F0A92B3B2B8E44F900DC7B37 /* InMemoryCustomListRepository.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InMemoryCustomListRepository.swift; sourceTree = "<group>"; };
19861985
F0B0E6962AFE6E7E001DC66B /* XCTest+Async.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "XCTest+Async.swift"; sourceTree = "<group>"; };
1986+
F0BE65362B9F136A005CC385 /* LocationSectionHeaderView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocationSectionHeaderView.swift; sourceTree = "<group>"; };
19871987
F0C2AEFC2A0BB5CC00986207 /* NotificationProviderIdentifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationProviderIdentifier.swift; sourceTree = "<group>"; };
19881988
F0C6A8422AB08E54000777A8 /* RedeemVoucherViewConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RedeemVoucherViewConfiguration.swift; sourceTree = "<group>"; };
19891989
F0C6FA842A6A733700F521F0 /* InAppPurchaseInteractor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InAppPurchaseInteractor.swift; sourceTree = "<group>"; };
@@ -2407,12 +2407,12 @@
24072407
F050AE612B74DBAC003F4EDB /* CustomListsDataSource.swift */,
24082408
F0A92B3B2B8E44F900DC7B37 /* InMemoryCustomListRepository.swift */,
24092409
5888AD82227B11080051EB06 /* LocationCell.swift */,
2410-
58435AC129CB2A350099C71B /* LocationCellFactory.swift */,
24112410
F050AE4D2B70D7F8003F4EDB /* LocationCellViewModel.swift */,
24122411
583DA21325FA4B5C00318683 /* LocationDataSource.swift */,
24132412
F050AE5D2B739A73003F4EDB /* LocationDataSourceProtocol.swift */,
24142413
7A6389F72B864CDF008E77E1 /* LocationNode.swift */,
24152414
F050AE512B70DFC0003F4EDB /* LocationSection.swift */,
2415+
F0BE65362B9F136A005CC385 /* LocationSectionHeaderView.swift */,
24162416
5888AD86227B17950051EB06 /* LocationViewController.swift */,
24172417
);
24182418
path = SelectLocation;
@@ -5118,7 +5118,6 @@
51185118
58B26E22294351EA00D5980C /* InAppNotificationProvider.swift in Sources */,
51195119
5893716A28817A45004EE76C /* DeviceManagementViewController.swift in Sources */,
51205120
7A9CCCB82A96302800DD6A34 /* SetupAccountCompletedCoordinator.swift in Sources */,
5121-
58435AC229CB2A350099C71B /* LocationCellFactory.swift in Sources */,
51225121
58BFA5C622A7C97F00A6173D /* RelayCacheTracker.swift in Sources */,
51235122
7A0B311E2B303A0D004B12E0 /* AccessbilityIdentifier.swift in Sources */,
51245123
E158B360285381C60002F069 /* String+AccountFormatting.swift in Sources */,
@@ -5132,6 +5131,7 @@
51325131
7ABE318D2A1CDD4500DF4963 /* UIFont+Weight.swift in Sources */,
51335132
58C774BE29A7A249003A1A56 /* CustomNavigationController.swift in Sources */,
51345133
E1FD0DF528AA7CE400299DB4 /* StatusActivityView.swift in Sources */,
5134+
F0BE65372B9F136A005CC385 /* LocationSectionHeaderView.swift in Sources */,
51355135
F0A92B3C2B8E44F900DC7B37 /* InMemoryCustomListRepository.swift in Sources */,
51365136
7A2960FD2A964BB700389B82 /* AlertPresentation.swift in Sources */,
51375137
0697D6E728F01513007A9E99 /* TransportMonitor.swift in Sources */,

ios/MullvadVPN/Coordinators/CustomLists/CustomListsDataSource.swift

-103
This file was deleted.

ios/MullvadVPN/Coordinators/LocationCoordinator.swift

+1-8
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,6 @@ class LocationCoordinator: Coordinator, Presentable, Presenting, RelayCacheTrack
140140

141141
extension LocationCoordinator: LocationViewControllerDelegate {
142142
func didRequestRouteToCustomLists(_ controller: LocationViewController) {
143-
let coordinator = AddCustomListCoordinator(
144-
navigationController: CustomNavigationController(),
145-
customListInteractor: CustomListInteractor(
146-
repository: customListRepository
147-
)
148-
)
149-
coordinator.start()
150-
presentChild(coordinator, animated: true)
143+
// TODO: Show add/Edit bottom sheet.
151144
}
152145
}

ios/MullvadVPN/View controllers/SelectLocation/AllLocationDataSource.swift

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import Foundation
1010
import MullvadREST
1111
import MullvadTypes
12-
import UIKit
1312

1413
class AllLocationDataSource: LocationDataSourceProtocol {
1514
private(set) var nodes = [LocationNode]()

ios/MullvadVPN/View controllers/SelectLocation/InMemoryCustomListRepository.swift

+14-6
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,20 @@ class InMemoryCustomListRepository: CustomListRepositoryProtocol {
1717
}
1818

1919
private var customRelayLists: [CustomList] = [
20-
CustomList(id: UUID(), name: "Netflix", locations: [.city("al", "tia")]),
21-
CustomList(id: UUID(), name: "Streaming", locations: [
22-
.city("us", "dal"),
23-
.country("se"),
24-
.city("de", "ber"),
25-
]),
20+
CustomList(
21+
id: UUID(uuidString: "F17948CB-18E2-4F84-82CD-5780F94216DB")!,
22+
name: "Netflix",
23+
locations: [.city("al", "tia")]
24+
),
25+
CustomList(
26+
id: UUID(uuidString: "4104C603-B35D-4A64-8865-96C0BF33D57F")!,
27+
name: "Streaming",
28+
locations: [
29+
.city("us", "dal"),
30+
.country("se"),
31+
.city("de", "ber"),
32+
]
33+
),
2634
]
2735

2836
private let passthroughSubject = PassthroughSubject<[CustomList], Never>()

ios/MullvadVPN/View controllers/SelectLocation/LocationCell.swift

+44-27
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,46 @@
88

99
import UIKit
1010

11-
private let kCollapseButtonWidth: CGFloat = 24
12-
private let kRelayIndicatorSize: CGFloat = 16
11+
protocol LocationCellDelegate: AnyObject {
12+
func toggle(cell: LocationCell)
13+
}
1314

1415
class LocationCell: UITableViewCell {
15-
typealias CollapseHandler = (LocationCell) -> Void
16+
weak var delegate: LocationCellDelegate?
17+
18+
private let locationLabel: UILabel = {
19+
let label = UILabel()
20+
label.font = UIFont.systemFont(ofSize: 16)
21+
label.textColor = .white
22+
label.lineBreakMode = .byWordWrapping
23+
label.numberOfLines = 0
24+
label.lineBreakStrategy = []
25+
return label
26+
}()
1627

17-
let locationLabel = UILabel()
18-
let statusIndicator: UIView = {
28+
private let statusIndicator: UIView = {
1929
let view = UIView()
20-
view.layer.cornerRadius = kRelayIndicatorSize * 0.5
30+
view.layer.cornerRadius = 8
2131
view.layer.cornerCurve = .circular
2232
return view
2333
}()
2434

25-
let tickImageView = UIImageView(image: UIImage(named: "IconTick"))
26-
let collapseButton = UIButton(type: .custom)
35+
private let tickImageView: UIImageView = {
36+
let imageView = UIImageView(image: UIImage(resource: .iconTick))
37+
imageView.tintColor = .white
38+
return imageView
39+
}()
40+
41+
private let collapseButton: UIButton = {
42+
let button = UIButton(type: .custom)
43+
button.accessibilityIdentifier = .collapseButton
44+
button.isAccessibilityElement = false
45+
button.tintColor = .white
46+
return button
47+
}()
2748

28-
private let chevronDown = UIImage(named: "IconChevronDown")
29-
private let chevronUp = UIImage(named: "IconChevronUp")
49+
private let chevronDown = UIImage(resource: .iconChevronDown)
50+
private let chevronUp = UIImage(resource: .iconChevronUp)
3051

3152
var isDisabled = false {
3253
didSet {
@@ -50,8 +71,6 @@ class LocationCell: UITableViewCell {
5071
}
5172
}
5273

53-
var didCollapseHandler: CollapseHandler?
54-
5574
override var indentationLevel: Int {
5675
didSet {
5776
updateBackgroundColor()
@@ -103,17 +122,6 @@ class LocationCell: UITableViewCell {
103122
selectedBackgroundView = UIView()
104123
selectedBackgroundView?.backgroundColor = UIColor.Cell.Background.selected
105124

106-
locationLabel.font = UIFont.systemFont(ofSize: 17)
107-
locationLabel.textColor = .white
108-
locationLabel.lineBreakMode = .byWordWrapping
109-
locationLabel.numberOfLines = 0
110-
locationLabel.lineBreakStrategy = []
111-
112-
tickImageView.tintColor = .white
113-
114-
collapseButton.accessibilityIdentifier = .collapseButton
115-
collapseButton.isAccessibilityElement = false
116-
collapseButton.tintColor = .white
117125
collapseButton.addTarget(self, action: #selector(handleCollapseButton(_:)), for: .touchUpInside)
118126

119127
[locationLabel, tickImageView, statusIndicator, collapseButton].forEach { subview in
@@ -131,7 +139,7 @@ class LocationCell: UITableViewCell {
131139
tickImageView.leadingAnchor.constraint(equalTo: contentView.layoutMarginsGuide.leadingAnchor),
132140
tickImageView.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
133141

134-
statusIndicator.widthAnchor.constraint(equalToConstant: kRelayIndicatorSize),
142+
statusIndicator.widthAnchor.constraint(equalToConstant: 16),
135143
statusIndicator.heightAnchor.constraint(equalTo: statusIndicator.widthAnchor),
136144
statusIndicator.centerXAnchor.constraint(equalTo: tickImageView.centerXAnchor),
137145
statusIndicator.centerYAnchor.constraint(equalTo: tickImageView.centerYAnchor),
@@ -148,7 +156,7 @@ class LocationCell: UITableViewCell {
148156
collapseButton.widthAnchor
149157
.constraint(
150158
equalToConstant: UIMetrics.contentLayoutMargins.leading + UIMetrics
151-
.contentLayoutMargins.trailing + kCollapseButtonWidth
159+
.contentLayoutMargins.trailing + 24
152160
),
153161
collapseButton.topAnchor.constraint(equalTo: contentView.topAnchor),
154162
collapseButton.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
@@ -213,11 +221,11 @@ class LocationCell: UITableViewCell {
213221
}
214222

215223
@objc private func handleCollapseButton(_ sender: UIControl) {
216-
didCollapseHandler?(self)
224+
delegate?.toggle(cell: self)
217225
}
218226

219227
@objc private func toggleCollapseAccessibilityAction() -> Bool {
220-
didCollapseHandler?(self)
228+
delegate?.toggle(cell: self)
221229
return true
222230
}
223231

@@ -255,3 +263,12 @@ class LocationCell: UITableViewCell {
255263
}
256264
}
257265
}
266+
267+
extension LocationCell {
268+
func configureCell(item: LocationCellViewModel) {
269+
accessibilityIdentifier = item.node.code
270+
locationLabel.text = item.node.name
271+
showsCollapseControl = !item.node.children.isEmpty
272+
isExpanded = item.node.showsChildren
273+
}
274+
}

ios/MullvadVPN/View controllers/SelectLocation/LocationCellFactory.swift

-51
This file was deleted.

0 commit comments

Comments
 (0)