Skip to content

Commit 6c0930e

Browse files
author
Jon Petersson
committed
Allow deleting custom lists
1 parent 2768aa5 commit 6c0930e

6 files changed

+49
-20
lines changed

ios/MullvadSettings/CustomListRepository.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public enum CustomRelayListError: LocalizedError, Equatable {
1818
switch self {
1919
case .duplicateName:
2020
NSLocalizedString(
21-
"DUPLICATE_CUSTOM_LIST_ERROR",
21+
"DUPLICATE_CUSTOM_LISTS_ERROR",
2222
tableName: "CustomListRepository",
2323
value: "Name is already taken.",
2424
comment: ""

ios/MullvadVPN/Coordinators/CustomLists/AddCustomListCoordinator.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ class AddCustomListCoordinator: Coordinator, Presentable, Presenting {
3636
controller.delegate = self
3737

3838
controller.navigationItem.title = NSLocalizedString(
39-
"CUSTOM_LIST_NAVIGATION_EDIT_TITLE",
39+
"CUSTOM_LISTS_NAVIGATION_EDIT_TITLE",
4040
tableName: "CustomLists",
4141
value: "New custom list",
4242
comment: ""
4343
)
4444

4545
controller.saveBarButton.title = NSLocalizedString(
46-
"CUSTOM_LIST_NAVIGATION_CREATE_BUTTON",
46+
"CUSTOM_LISTS_NAVIGATION_CREATE_BUTTON",
4747
tableName: "CustomLists",
4848
value: "Create",
4949
comment: ""

ios/MullvadVPN/Coordinators/CustomLists/CustomListViewController.swift

-10
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,6 @@ class CustomListViewController: UIViewController {
8686
}
8787

8888
private func configureNavigationItem() {
89-
<<<<<<< HEAD
90-
=======
91-
navigationItem.title = NSLocalizedString(
92-
"CUSTOM_LIST_NAVIGATION_EDIT_TITLE",
93-
tableName: "CustomLists",
94-
value: subject.value.name,
95-
comment: ""
96-
)
97-
98-
>>>>>>> ba5bb4354 (Add UI for creating and editing a custom list)
9989
navigationItem.leftBarButtonItem = UIBarButtonItem(
10090
systemItem: .cancel,
10191
primaryAction: UIAction(handler: { _ in

ios/MullvadVPN/Coordinators/CustomLists/EditCustomListCoordinator.swift

+44-5
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ import MullvadSettings
1111
import Routing
1212
import UIKit
1313

14-
class EditCustomListCoordinator: Coordinator, Presentable {
14+
class EditCustomListCoordinator: Coordinator, Presentable, Presenting {
1515
let navigationController: UINavigationController
1616
let customListInteractor: CustomListInteractorProtocol
17+
let subject: CurrentValueSubject<CustomListViewModel, Never>
18+
19+
lazy var alertPresenter: AlertPresenter = {
20+
AlertPresenter(context: self)
21+
}()
1722

1823
var presentedViewController: UIViewController {
1924
navigationController
@@ -25,18 +30,18 @@ class EditCustomListCoordinator: Coordinator, Presentable {
2530
) {
2631
self.navigationController = navigationController
2732
self.customListInteractor = customListInteractor
28-
}
2933

30-
func start() {
31-
let subject = CurrentValueSubject<CustomListViewModel, Never>(
34+
subject = CurrentValueSubject<CustomListViewModel, Never>(
3235
CustomListViewModel(
3336
id: UUID(),
3437
name: "A list",
3538
locations: [],
3639
tableSections: [.name, .editLocations, .deleteList]
3740
)
3841
)
42+
}
3943

44+
func start() {
4045
let controller = CustomListViewController(interactor: customListInteractor, subject: subject)
4146
controller.delegate = self
4247

@@ -57,7 +62,41 @@ extension EditCustomListCoordinator: CustomListViewControllerDelegate {
5762
}
5863

5964
func customListDidDelete() {
60-
dismiss(animated: true)
65+
let presentation = AlertPresentation(
66+
id: "api-custom-lists-delete-list-alert",
67+
icon: .alert,
68+
message: NSLocalizedString(
69+
"CUSTOM_LISTS_DELETE_PROMPT",
70+
tableName: "APIAccess",
71+
value: "Delete \(subject.value.name)?",
72+
comment: ""
73+
),
74+
buttons: [
75+
AlertAction(
76+
title: NSLocalizedString(
77+
"CUSTOM_LISTS_DELETE_BUTTON",
78+
tableName: "APIAccess",
79+
value: "Delete",
80+
comment: ""
81+
),
82+
style: .destructive,
83+
handler: {
84+
self.customListInteractor.deleteCustomList(id: self.subject.value.id)
85+
}
86+
),
87+
AlertAction(
88+
title: NSLocalizedString(
89+
"CUSTOM_LISTS_CANCEL_BUTTON",
90+
tableName: "APIAccess",
91+
value: "Cancel",
92+
comment: ""
93+
),
94+
style: .default
95+
)
96+
]
97+
)
98+
99+
alertPresenter.showAlert(presentation: presentation, animated: true)
61100
}
62101

63102
func showLocations() {

ios/MullvadVPN/Coordinators/SelectLocationCoordinator.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class SelectLocationCoordinator: Coordinator, Presentable, Presenting, RelayCach
7070
guard let self else { return }
7171

7272
// let coordinator = makeRelayFilterCoordinator(forModalPresentation: true)
73-
let coordinator = AddCustomListCoordinator(
73+
let coordinator = EditCustomListCoordinator(
7474
navigationController: CustomNavigationController(),
7575
customListInteractor: CustomListInteractor(repository: CustomListRepository())
7676
)

ios/MullvadVPN/Coordinators/Settings/APIAccess/Edit/EditAccessMethodViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ class EditAccessMethodViewController: UITableViewController {
333333
id: "api-access-methods-delete-method-alert",
334334
icon: .alert,
335335
message: NSLocalizedString(
336-
"METHOD_SETTINGS_SAVE_PROMPT",
336+
"METHOD_SETTINGS_DELETE_PROMPT",
337337
tableName: "APIAccess",
338338
value: "Delete \(methodName)?",
339339
comment: ""

0 commit comments

Comments
 (0)