2020-04-18 22:35:17 -07:00
|
|
|
//
|
|
|
|
|
// UIAlertActionExtension.swift
|
|
|
|
|
// passKit
|
|
|
|
|
//
|
|
|
|
|
// Created by Sun, Mingshen on 4/17/20.
|
|
|
|
|
// Copyright © 2020 Bob Sun. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import Foundation
|
2020-06-28 21:25:40 +02:00
|
|
|
import UIKit
|
2020-04-18 22:35:17 -07:00
|
|
|
|
|
|
|
|
extension UIAlertAction {
|
|
|
|
|
public static func cancelAndPopView(controller: UIViewController) -> UIAlertAction {
|
2020-06-28 21:25:40 +02:00
|
|
|
cancel { _ in
|
2020-04-18 22:35:17 -07:00
|
|
|
controller.navigationController?.popViewController(animated: true)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static func cancel(handler: ((UIAlertAction) -> Void)? = nil) -> UIAlertAction {
|
|
|
|
|
cancel(with: "Cancel", handler: handler)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static func dismiss(handler: ((UIAlertAction) -> Void)? = nil) -> UIAlertAction {
|
|
|
|
|
cancel(with: "Dismiss", handler: handler)
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-28 21:25:40 +02:00
|
|
|
public static func cancel(with _: String, handler: ((UIAlertAction) -> Void)? = nil) -> UIAlertAction {
|
2020-04-18 22:35:17 -07:00
|
|
|
UIAlertAction(title: "Cancel".localize(), style: .cancel, handler: handler)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static func ok(handler: ((UIAlertAction) -> Void)? = nil) -> UIAlertAction {
|
|
|
|
|
UIAlertAction(title: "Ok".localize(), style: .default, handler: handler)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static func okAndPopView(controller: UIViewController) -> UIAlertAction {
|
2020-06-28 21:25:40 +02:00
|
|
|
ok { _ in
|
2020-04-18 22:35:17 -07:00
|
|
|
controller.navigationController?.popViewController(animated: true)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static func selectKey(controller: UIViewController, handler: ((UIAlertAction) -> Void)?) -> UIAlertAction {
|
|
|
|
|
UIAlertAction(title: "Select Key", style: .default) { _ in
|
|
|
|
|
let selectKeyAlert = UIAlertController(title: "Select from imported keys", message: nil, preferredStyle: .actionSheet)
|
2020-06-28 21:25:40 +02:00
|
|
|
try? PGPAgent.shared.getShortKeyID().forEach { k in
|
2020-04-18 22:35:17 -07:00
|
|
|
let action = UIAlertAction(title: k, style: .default, handler: handler)
|
|
|
|
|
selectKeyAlert.addAction(action)
|
2020-06-28 21:25:40 +02:00
|
|
|
}
|
2020-04-18 22:35:17 -07:00
|
|
|
selectKeyAlert.addAction(UIAlertAction.cancelAndPopView(controller: controller))
|
|
|
|
|
controller.present(selectKeyAlert, animated: true, completion: nil)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|