-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
Copy pathOutgoingDeviceTransferNavigationController.swift
137 lines (111 loc) · 5.16 KB
/
OutgoingDeviceTransferNavigationController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//
// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
//
import SignalServiceKit
import SignalUI
class OutgoingDeviceTransferNavigationController: UINavigationController {
init() {
super.init(nibName: nil, bundle: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
pushViewController(OutgoingDeviceTransferInitialViewController(), animated: false)
setNavigationBarHidden(true, animated: false)
let dismissButton = UIButton()
dismissButton.setTemplateImage(Theme.iconImage(.buttonX), tintColor: Theme.primaryIconColor)
dismissButton.addTarget(self, action: #selector(tappedDismiss), for: .touchUpInside)
view.addSubview(dismissButton)
dismissButton.autoSetDimensions(to: CGSize(square: 40))
dismissButton.autoPinEdge(toSuperviewEdge: .leading, withInset: 8)
dismissButton.autoPinEdge(toSuperviewEdge: .top, withInset: 10)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
@objc
private func tappedDismiss() {
AssertIsOnMainThread()
if let topVC = topViewController as? DeviceTransferBaseViewController, topVC.requiresDismissConfirmation {
let actionSheet = ActionSheetController(
title: OWSLocalizedString("DEVICE_TRANSFER_CANCEL_CONFIRMATION_TITLE",
comment: "The title of the dialog asking the user if they want to cancel a device transfer"),
message: OWSLocalizedString("DEVICE_TRANSFER_CANCEL_CONFIRMATION_MESSAGE",
comment: "The message of the dialog asking the user if they want to cancel a device transfer")
)
actionSheet.addAction(OWSActionSheets.cancelAction)
let okAction = ActionSheetAction(
title: OWSLocalizedString("DEVICE_TRANSFER_CANCEL_CONFIRMATION_ACTION",
comment: "The stop action of the dialog asking the user if they want to cancel a device transfer"),
style: .destructive
) { _ in
self.dismissActionSheet()
}
actionSheet.addAction(okAction)
present(actionSheet, animated: true)
} else {
dismissActionSheet()
}
}
func dismissActionSheet() {
AssertIsOnMainThread()
AppEnvironment.shared.deviceTransferServiceRef.cancelTransferToNewDevice()
actionSheetController?.dismiss(animated: true, completion: nil)
}
var actionSheetController: ActionSheetController?
func present(fromViewController: UIViewController) {
let actionSheetController = ActionSheetController()
self.actionSheetController = actionSheetController
actionSheetController.customHeader = view
view.autoSetDimension(.height, toSize: 440)
fromViewController.presentActionSheet(actionSheetController)
}
}
class DeviceTransferBaseViewController: UIViewController {
var transferNavigationController: OutgoingDeviceTransferNavigationController? {
return navigationController as? OutgoingDeviceTransferNavigationController
}
var requiresDismissConfirmation: Bool { false }
let contentView = UIStackView()
override func loadView() {
view = UIView()
view.backgroundColor = Theme.actionSheetBackgroundColor
view.addSubview(contentView)
contentView.autoPinEdgesToSuperviewEdges()
contentView.isLayoutMarginsRelativeArrangement = true
contentView.layoutMargins = UIEdgeInsets(top: 16, leading: 32, bottom: 16, trailing: 32)
contentView.axis = .vertical
}
func titleLabel(text: String) -> UILabel {
let titleLabel = UILabel()
titleLabel.text = text
titleLabel.textColor = Theme.primaryTextColor
titleLabel.font = UIFont.dynamicTypeTitle2.semibold()
titleLabel.numberOfLines = 0
titleLabel.lineBreakMode = .byWordWrapping
titleLabel.textAlignment = .center
return titleLabel
}
func explanationLabel(explanationText: String) -> UILabel {
let explanationLabel = UILabel()
explanationLabel.textColor = Theme.secondaryTextAndIconColor
explanationLabel.font = .dynamicTypeBody2
explanationLabel.text = explanationText
explanationLabel.numberOfLines = 0
explanationLabel.textAlignment = .center
explanationLabel.lineBreakMode = .byWordWrapping
return explanationLabel
}
func button(title: String, selector: Selector) -> OWSFlatButton {
let font = UIFont.dynamicTypeBodyClamped.semibold()
let buttonHeight = OWSFlatButton.heightForFont(font)
let button = OWSFlatButton.button(title: title,
font: font,
titleColor: .white,
backgroundColor: .ows_accentBlue,
target: self,
selector: selector)
button.autoSetDimension(.height, toSize: buttonHeight)
return button
}
}