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
|
|
|
|
2020-11-07 12:06:28 +01:00
|
|
|
public extension UIAlertAction {
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-07 12:06:28 +01:00
|
|
|
static func cancel(title: String = "Cancel".localize(), handler: ((UIAlertAction) -> Void)? = nil) -> UIAlertAction {
|
2020-08-23 01:15:23 +02:00
|
|
|
UIAlertAction(title: title, style: .cancel, handler: handler)
|
2020-04-18 22:35:17 -07:00
|
|
|
}
|
|
|
|
|
|
2020-11-07 12:06:28 +01:00
|
|
|
static func dismiss(handler: ((UIAlertAction) -> Void)? = nil) -> UIAlertAction {
|
2020-08-23 01:15:23 +02:00
|
|
|
cancel(title: "Dismiss".localize(), handler: handler)
|
2020-04-18 22:35:17 -07:00
|
|
|
}
|
|
|
|
|
|
2020-11-07 12:06:28 +01:00
|
|
|
static func ok(handler: ((UIAlertAction) -> Void)? = nil) -> UIAlertAction {
|
2020-04-18 22:35:17 -07:00
|
|
|
UIAlertAction(title: "Ok".localize(), style: .default, handler: handler)
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-29 16:19:12 -08:00
|
|
|
static func remove(handler: ((UIAlertAction) -> Void)? = nil) -> UIAlertAction {
|
|
|
|
|
UIAlertAction(title: "Remove".localize(), style: .destructive, handler: handler)
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-07 12:06:28 +01:00
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 16:16:50 +01:00
|
|
|
static func selectKey(type: PGPKey, controller: UIViewController, handler: ((UIAlertAction) -> Void)?) -> UIAlertAction {
|
2020-04-18 22:35:17 -07:00
|
|
|
UIAlertAction(title: "Select Key", style: .default) { _ in
|
|
|
|
|
let selectKeyAlert = UIAlertController(title: "Select from imported keys", message: nil, preferredStyle: .actionSheet)
|
2026-03-11 16:16:50 +01:00
|
|
|
try? PGPAgent.shared.getShortKeyIDs(type: type).forEach { keyID in
|
2020-09-20 15:07:18 +02:00
|
|
|
let action = UIAlertAction(title: keyID, style: .default, handler: handler)
|
2020-04-18 22:35:17 -07:00
|
|
|
selectKeyAlert.addAction(action)
|
2020-06-28 21:25:40 +02:00
|
|
|
}
|
2021-10-07 19:19:56 +02:00
|
|
|
selectKeyAlert.addAction(Self.cancelAndPopView(controller: controller))
|
2020-04-18 22:35:17 -07:00
|
|
|
controller.present(selectKeyAlert, animated: true, completion: nil)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|