Skip to content

Commit

Permalink
Fix device name not appearing in device logout screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Petersson committed Oct 9, 2023
1 parent 48d6a75 commit 7cd9ed7
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 58 deletions.
1 change: 1 addition & 0 deletions ios/MullvadVPN/Coordinators/AccountCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ final class AccountCoordinator: Coordinator, Presentable, Presenting {

let presentation = AlertPresentation(
id: "account-device-info-alert",
icon: .info,
message: message,
buttons: [AlertAction(
title: NSLocalizedString(
Expand Down
20 changes: 2 additions & 18 deletions ios/MullvadVPN/Coordinators/AlertCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,10 @@ final class AlertCoordinator: Coordinator, Presentable {
}

func start() {
let alertController = AlertViewController(
header: presentation.header,
title: presentation.title,
message: presentation.message,
icon: presentation.icon
)
alertController = AlertViewController(presentation: presentation)

self.alertController = alertController

alertController.onDismiss = { [weak self] in
alertController?.onDismiss = { [weak self] in
self?.didFinish?()
}

presentation.buttons.forEach { action in
alertController.addAction(
title: action.title,
style: action.style,
accessibilityId: action.accessibilityID,
handler: action.handler
)
}
}
}
37 changes: 19 additions & 18 deletions ios/MullvadVPN/Coordinators/ChangeLogCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,28 @@ final class ChangeLogCoordinator: Coordinator, Presentable {
}

func start() {
let alertController = AlertViewController(
let presentation = AlertPresentation(
id: "change-log-ok-alert",
header: interactor.viewModel.header,
title: interactor.viewModel.title,
attributedMessage: interactor.viewModel.body
attributedMessage: interactor.viewModel.body,
buttons: [
AlertAction(
title: NSLocalizedString(
"CHANGE_LOG_OK_ACTION",
tableName: "Account",
value: "Got it!",
comment: ""
),
style: .default,
handler: { [weak self] in
guard let self else { return }
didFinish?(self)
}
),
]
)

alertController.addAction(
title: NSLocalizedString(
"CHANGE_LOG_OK_ACTION",
tableName: "Account",
value: "Got it!",
comment: ""
),
style: .default,
accessibilityId: "OkButton",
handler: { [weak self] in
guard let self else { return }
didFinish?(self)
}
)

self.alertController = alertController
alertController = AlertViewController(presentation: presentation)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ struct AlertPresentation: Identifiable, CustomDebugStringConvertible {
var header: String?
var icon: AlertIcon?
var title: String?
let message: String?
var message: String?
var attributedMessage: NSAttributedString?
let buttons: [AlertAction]

var debugDescription: String {
Expand Down
30 changes: 19 additions & 11 deletions ios/MullvadVPN/View controllers/Alert/AlertViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,27 @@ class AlertViewController: UIViewController {

private var handlers = [UIButton: Handler]()

init(header: String? = nil, title: String? = nil, message: String? = nil, icon: AlertIcon? = nil) {
init(presentation: AlertPresentation) {
super.init(nibName: nil, bundle: nil)

setUp(header: header, title: title, icon: icon) {
message.flatMap { addMessage($0) }
setUp(
header: presentation.header,
title: presentation.title,
icon: presentation.icon
) {
if let message = presentation.attributedMessage {
addMessage(message)
} else if let message = presentation.message {
addMessage(message)
}
}
}

init(header: String? = nil, title: String? = nil, attributedMessage: NSAttributedString?, icon: AlertIcon? = nil) {
super.init(nibName: nil, bundle: nil)

setUp(header: header, title: title, icon: icon) {
attributedMessage.flatMap { addMessage($0) }
presentation.buttons.forEach { action in
addAction(
title: action.title,
style: action.style,
handler: action.handler
)
}
}

Expand Down Expand Up @@ -120,14 +128,13 @@ class AlertViewController: UIViewController {
}
}

func addAction(title: String, style: AlertActionStyle, accessibilityId: String?, handler: (() -> Void)? = nil) {
func addAction(title: String, style: AlertActionStyle, handler: (() -> Void)? = nil) {
// The presence of a button should reset any custom button margin to default.
containerView.directionalLayoutMargins.bottom = UIMetrics.CustomAlert.containerMargins.bottom

let button = AppButton(style: style.buttonStyle)

button.setTitle(title, for: .normal)
button.accessibilityIdentifier = accessibilityId
button.addTarget(self, action: #selector(didTapButton), for: .touchUpInside)

containerView.addArrangedSubview(button)
Expand Down Expand Up @@ -185,6 +192,7 @@ class AlertViewController: UIViewController {
let label = UILabel()

label.attributedText = message
label.textColor = .white.withAlphaComponent(0.8)
label.adjustsFontForContentSizeCategory = true
label.numberOfLines = 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,26 @@ class DeviceManagementViewController: UIViewController, RootContainment {
deviceName: String,
completion: @escaping (_ shouldDelete: Bool) -> Void
) {
let text = String(
format: NSLocalizedString(
"DELETE_ALERT_TITLE",
tableName: "DeviceManagement",
value: "Are you sure you want to log **\(deviceName)** out?",
comment: ""
)
)

let attributedText = NSAttributedString(
markdownString: text,
options: MarkdownStylingOptions(
font: .preferredFont(forTextStyle: .body)
)
)

let presentation = AlertPresentation(
id: "logout-confirmation-alert",
icon: .alert,
message: String(
format: NSLocalizedString(
"DELETE_ALERT_TITLE",
tableName: "DeviceManagement",
value: "Are you sure you want to log %@ out?",
comment: ""
), deviceName
),
attributedMessage: attributedText,
buttons: [
AlertAction(
title: NSLocalizedString(
Expand Down
4 changes: 2 additions & 2 deletions ios/MullvadVPNScreenshots/MullvadVPNScreenshots.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class MullvadVPNScreenshots: XCTestCase {
app.buttons["AgreeButton"].tap()

// Dismiss changelog screen
_ = app.buttons["OkButton"].waitForExistence(timeout: 10)
app.buttons["OkButton"].tap()
_ = app.buttons["Got it!"].waitForExistence(timeout: 10)
app.buttons["Got it!"].tap()

// Wait for Login screen
let textField = app.textFields["LoginTextField"]
Expand Down

0 comments on commit 7cd9ed7

Please sign in to comment.