Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix device name not appearing in device logout screen #5251

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,40 +183,49 @@ 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(
"DELETE_ALERT_CANCEL_ACTION",
"DELETE_ALERT_CONFIRM_ACTION",
tableName: "DeviceManagement",
value: "Back",
value: "Yes, log out device",
comment: ""
),
style: .default,
style: .destructive,
handler: {
completion(false)
completion(true)
}
),
AlertAction(
title: NSLocalizedString(
"DELETE_ALERT_CONFIRM_ACTION",
"DELETE_ALERT_CANCEL_ACTION",
tableName: "DeviceManagement",
value: "Yes, log out device",
value: "Back",
comment: ""
),
style: .destructive,
style: .default,
handler: {
completion(true)
completion(false)
}
),
]
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