2017-05-08 18:34:50 +02:00
|
|
|
//
|
2019-03-20 15:45:36 +01:00
|
|
|
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
2017-05-08 18:34:50 +02:00
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
2022-06-01 09:41:20 +02:00
|
|
|
import SessionUtilitiesKit
|
2017-05-08 18:34:50 +02:00
|
|
|
|
2017-12-04 16:35:47 +01:00
|
|
|
@objc public class OWSAlerts: NSObject {
|
2018-08-08 18:49:21 +02:00
|
|
|
@objc
|
|
|
|
public class func showAlert(_ alert: UIAlertController) {
|
|
|
|
guard let frontmostViewController = CurrentAppContext().frontmostViewController() else {
|
2018-08-27 16:27:48 +02:00
|
|
|
owsFailDebug("frontmostViewController was unexpectedly nil")
|
2018-08-08 18:49:21 +02:00
|
|
|
return
|
|
|
|
}
|
2019-03-21 15:26:38 +01:00
|
|
|
frontmostViewController.presentAlert(alert)
|
2018-08-08 18:49:21 +02:00
|
|
|
}
|
|
|
|
|
2017-12-04 16:35:47 +01:00
|
|
|
@objc
|
2018-03-01 20:41:45 +01:00
|
|
|
public class func showAlert(title: String) {
|
|
|
|
self.showAlert(title: title, message: nil, buttonTitle: nil)
|
2017-05-09 16:04:48 +02:00
|
|
|
}
|
|
|
|
|
2017-12-04 16:35:47 +01:00
|
|
|
@objc
|
2018-03-01 20:41:45 +01:00
|
|
|
public class func showAlert(title: String?, message: String) {
|
|
|
|
self.showAlert(title: title, message: message, buttonTitle: nil)
|
2017-05-08 19:29:10 +02:00
|
|
|
}
|
|
|
|
|
2017-12-04 16:35:47 +01:00
|
|
|
@objc
|
2018-03-01 20:41:45 +01:00
|
|
|
public class func showAlert(title: String?, message: String? = nil, buttonTitle: String? = nil, buttonAction: ((UIAlertAction) -> Void)? = nil) {
|
2018-04-16 23:39:13 +02:00
|
|
|
guard let fromViewController = CurrentAppContext().frontmostViewController() else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
showAlert(title: title, message: message, buttonTitle: buttonTitle, buttonAction: buttonAction,
|
|
|
|
fromViewController: fromViewController)
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc
|
|
|
|
public class func showAlert(title: String?, message: String? = nil, buttonTitle: String? = nil, buttonAction: ((UIAlertAction) -> Void)? = nil, fromViewController: UIViewController?) {
|
2017-05-09 16:45:20 +02:00
|
|
|
|
2017-05-08 19:29:10 +02:00
|
|
|
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
|
2019-03-20 15:45:36 +01:00
|
|
|
|
2022-01-13 06:37:23 +01:00
|
|
|
let actionTitle = buttonTitle ?? NSLocalizedString("BUTTON_OK", comment: "")
|
2019-03-20 15:45:36 +01:00
|
|
|
let okAction = UIAlertAction(title: actionTitle, style: .default, handler: buttonAction)
|
|
|
|
okAction.accessibilityIdentifier = "OWSAlerts.\("ok")"
|
|
|
|
alert.addAction(okAction)
|
2019-03-21 15:26:38 +01:00
|
|
|
fromViewController?.presentAlert(alert)
|
2017-05-08 19:29:10 +02:00
|
|
|
}
|
2017-08-21 22:58:26 +02:00
|
|
|
|
2017-12-04 16:35:47 +01:00
|
|
|
@objc
|
2018-03-01 20:41:45 +01:00
|
|
|
public class func showConfirmationAlert(title: String, message: String? = nil, proceedTitle: String? = nil, proceedAction: @escaping (UIAlertAction) -> Void) {
|
2017-12-04 16:35:47 +01:00
|
|
|
assert(title.count > 0)
|
2017-09-29 21:51:06 +02:00
|
|
|
|
|
|
|
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
|
|
|
|
alert.addAction(self.cancelAction)
|
|
|
|
|
2022-01-13 06:37:23 +01:00
|
|
|
let actionTitle = proceedTitle ?? NSLocalizedString("BUTTON_OK", comment: "")
|
2019-03-20 15:45:36 +01:00
|
|
|
let okAction = UIAlertAction(title: actionTitle, style: .default, handler: proceedAction)
|
|
|
|
okAction.accessibilityIdentifier = "OWSAlerts.\("ok")"
|
|
|
|
alert.addAction(okAction)
|
2017-09-29 21:51:06 +02:00
|
|
|
|
2019-03-21 15:26:38 +01:00
|
|
|
CurrentAppContext().frontmostViewController()?.presentAlert(alert)
|
2017-09-29 21:51:06 +02:00
|
|
|
}
|
|
|
|
|
2018-03-06 14:29:25 +01:00
|
|
|
@objc
|
2018-03-14 14:02:44 +01:00
|
|
|
public class func showErrorAlert(message: String) {
|
2018-03-06 21:40:29 +01:00
|
|
|
self.showAlert(title: CommonStrings.errorAlertTitle, message: message, buttonTitle: nil)
|
2018-03-06 14:29:25 +01:00
|
|
|
}
|
|
|
|
|
2017-12-04 16:35:47 +01:00
|
|
|
@objc
|
2017-09-29 21:51:06 +02:00
|
|
|
public class var cancelAction: UIAlertAction {
|
2017-09-01 15:30:16 +02:00
|
|
|
let action = UIAlertAction(title: CommonStrings.cancelButton, style: .cancel) { _ in
|
2017-08-21 22:58:26 +02:00
|
|
|
Logger.debug("Cancel item")
|
|
|
|
// Do nothing.
|
|
|
|
}
|
2019-03-20 15:45:36 +01:00
|
|
|
action.accessibilityIdentifier = "OWSAlerts.\("cancel")"
|
2017-08-21 22:58:26 +02:00
|
|
|
return action
|
|
|
|
}
|
2017-05-08 18:34:50 +02:00
|
|
|
}
|