WIP
This commit is contained in:
parent
cd93d8e25d
commit
994ee82a89
|
@ -219,4 +219,4 @@ SPEC CHECKSUMS:
|
|||
|
||||
PODFILE CHECKSUM: bb4f6cffd6e7c08814b945e1787d01d639036b1e
|
||||
|
||||
COCOAPODS: 1.10.1
|
||||
COCOAPODS: 1.10.0.rc.1
|
||||
|
|
|
@ -226,6 +226,8 @@
|
|||
B83786802586D296003CE78E /* KeyPairMigrationSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = B837867F2586D296003CE78E /* KeyPairMigrationSheet.swift */; };
|
||||
B83F2B88240CB75A000A54AB /* UIImage+Scaling.swift in Sources */ = {isa = PBXBuildFile; fileRef = B83F2B87240CB75A000A54AB /* UIImage+Scaling.swift */; };
|
||||
B84664F5235022F30083A1CD /* MentionUtilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = B84664F4235022F30083A1CD /* MentionUtilities.swift */; };
|
||||
B84A897D25DE0F4D0040017D /* LinkDeviceVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B84A897C25DE0F4D0040017D /* LinkDeviceVC.swift */; };
|
||||
B84A898725DE1EE90040017D /* Notification+MessageReceiver.swift in Sources */ = {isa = PBXBuildFile; fileRef = B84A898625DE1EE90040017D /* Notification+MessageReceiver.swift */; };
|
||||
B85357BF23A1AE0800AAF6CD /* SeedReminderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B85357BE23A1AE0800AAF6CD /* SeedReminderView.swift */; };
|
||||
B85357C323A1BD1200AAF6CD /* SeedVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B85357C223A1BD1200AAF6CD /* SeedVC.swift */; };
|
||||
B8544E3323D50E4900299F14 /* AppearanceUtilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8544E3223D50E4900299F14 /* AppearanceUtilities.swift */; };
|
||||
|
@ -1292,6 +1294,8 @@
|
|||
B840729F2565F1670037CB17 /* OWSQuotedReplyModel+Conversion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OWSQuotedReplyModel+Conversion.swift"; sourceTree = "<group>"; };
|
||||
B84664F4235022F30083A1CD /* MentionUtilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MentionUtilities.swift; sourceTree = "<group>"; };
|
||||
B847570023D568EB00759540 /* SignalServiceKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SignalServiceKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
B84A897C25DE0F4D0040017D /* LinkDeviceVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkDeviceVC.swift; sourceTree = "<group>"; };
|
||||
B84A898625DE1EE90040017D /* Notification+MessageReceiver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Notification+MessageReceiver.swift"; sourceTree = "<group>"; };
|
||||
B85357BE23A1AE0800AAF6CD /* SeedReminderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeedReminderView.swift; sourceTree = "<group>"; };
|
||||
B85357C223A1BD1200AAF6CD /* SeedVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeedVC.swift; sourceTree = "<group>"; };
|
||||
B8544E3023D16CA500299F14 /* DeviceUtilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceUtilities.swift; sourceTree = "<group>"; };
|
||||
|
@ -2236,6 +2240,14 @@
|
|||
path = ..;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
B84A897B25DE0F3E0040017D /* Device Linking */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
B84A897C25DE0F4D0040017D /* LinkDeviceVC.swift */,
|
||||
);
|
||||
path = "Device Linking";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
B8A582AB258C64E800AFD84C /* Database */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
|
@ -2446,6 +2458,7 @@
|
|||
C32C5ADE256DBF7F003C73A2 /* Read Tracking */,
|
||||
C32C5995256DAF85003C73A2 /* Typing Indicators */,
|
||||
C3471FA32555439E00297E91 /* Notification+MessageSender.swift */,
|
||||
B84A898625DE1EE90040017D /* Notification+MessageReceiver.swift */,
|
||||
C300A5F12554B09800555489 /* MessageSender.swift */,
|
||||
C38D5E8C2575011E00B6A65C /* MessageSender+ClosedGroups.swift */,
|
||||
B8D8F1EF256621180092EF10 /* MessageSender+Convenience.swift */,
|
||||
|
@ -3668,6 +3681,7 @@
|
|||
C36096AE25AD1909008B62B2 /* Conversations */,
|
||||
C32C5D49256DD522003C73A2 /* Database */,
|
||||
C32B405424A961E1001117B5 /* Dependencies */,
|
||||
B84A897B25DE0F3E0040017D /* Device Linking */,
|
||||
C360968E25AD16E8008B62B2 /* Home */,
|
||||
C36096BA25AD1B14008B62B2 /* Media Viewing & Editing */,
|
||||
C36096BB25AD1BBB008B62B2 /* Notifications */,
|
||||
|
@ -4906,6 +4920,7 @@
|
|||
C379DCF4256735770002D4EB /* VisibleMessage+Attachment.swift in Sources */,
|
||||
B8856D34256F1192001CE70E /* Environment.m in Sources */,
|
||||
B8B320B7258C30D70020074B /* HTMLMetadata.swift in Sources */,
|
||||
B84A898725DE1EE90040017D /* Notification+MessageReceiver.swift in Sources */,
|
||||
C32C5AB1256DBE8F003C73A2 /* TSIncomingMessage.m in Sources */,
|
||||
C3A3A107256E1A5C004D228D /* OWSDisappearingMessagesFinder.m in Sources */,
|
||||
C32C59C3256DB41F003C73A2 /* TSGroupModel.m in Sources */,
|
||||
|
@ -5024,6 +5039,7 @@
|
|||
34DBF007206C3CB200025978 /* OWSBubbleShapeView.m in Sources */,
|
||||
4C04392A220A9EC800BAEA63 /* VoiceNoteLock.swift in Sources */,
|
||||
3496956E21A301A100DCFE74 /* OWSBackupExportJob.m in Sources */,
|
||||
B84A897D25DE0F4D0040017D /* LinkDeviceVC.swift in Sources */,
|
||||
4C1885D2218F8E1C00B67051 /* PhotoGridViewCell.swift in Sources */,
|
||||
34D1F0501F7D45A60066283D /* GifPickerCell.swift in Sources */,
|
||||
3496957421A301A100DCFE74 /* OWSBackupAPI.swift in Sources */,
|
||||
|
|
|
@ -0,0 +1,331 @@
|
|||
import PromiseKit
|
||||
|
||||
final class LinkDeviceVC : BaseVC, UIPageViewControllerDataSource, UIPageViewControllerDelegate, OWSQRScannerDelegate {
|
||||
private let pageVC = UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil)
|
||||
private var pages: [UIViewController] = []
|
||||
private var targetVCIndex: Int?
|
||||
private var tabBarTopConstraint: NSLayoutConstraint!
|
||||
private var activityIndicatorModal: ModalActivityIndicatorViewController?
|
||||
|
||||
// MARK: Components
|
||||
private lazy var tabBar: TabBar = {
|
||||
let tabs = [
|
||||
TabBar.Tab(title: "Recovery Phrase") { [weak self] in
|
||||
guard let self = self else { return }
|
||||
self.pageVC.setViewControllers([ self.pages[0] ], direction: .forward, animated: false, completion: nil)
|
||||
},
|
||||
TabBar.Tab(title: "Scan QR Code") { [weak self] in
|
||||
guard let self = self else { return }
|
||||
self.pageVC.setViewControllers([ self.pages[1] ], direction: .forward, animated: false, completion: nil)
|
||||
}
|
||||
]
|
||||
return TabBar(tabs: tabs)
|
||||
}()
|
||||
|
||||
private lazy var recoveryPhraseVC: RecoveryPhraseVC = {
|
||||
let result = RecoveryPhraseVC()
|
||||
result.linkDeviceVC = self
|
||||
return result
|
||||
}()
|
||||
|
||||
private lazy var scanQRCodePlaceholderVC: ScanQRCodePlaceholderVC = {
|
||||
let result = ScanQRCodePlaceholderVC()
|
||||
result.linkDeviceVC = self
|
||||
return result
|
||||
}()
|
||||
|
||||
private lazy var scanQRCodeWrapperVC: ScanQRCodeWrapperVC = {
|
||||
let message = "Bla bla foo bar"
|
||||
let result = ScanQRCodeWrapperVC(message: message)
|
||||
result.delegate = self
|
||||
return result
|
||||
}()
|
||||
|
||||
// MARK: Lifecycle
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
setUpGradientBackground()
|
||||
setUpNavBarStyle()
|
||||
setNavBarTitle("Link a Device")
|
||||
let navigationBar = navigationController!.navigationBar
|
||||
// Page VC
|
||||
let hasCameraAccess = (AVCaptureDevice.authorizationStatus(for: .video) == .authorized)
|
||||
pages = [ recoveryPhraseVC, (hasCameraAccess ? scanQRCodeWrapperVC : scanQRCodePlaceholderVC) ]
|
||||
pageVC.dataSource = self
|
||||
pageVC.delegate = self
|
||||
pageVC.setViewControllers([ recoveryPhraseVC ], direction: .forward, animated: false, completion: nil)
|
||||
// Tab bar
|
||||
view.addSubview(tabBar)
|
||||
tabBar.pin(.leading, to: .leading, of: view)
|
||||
tabBarTopConstraint = tabBar.autoPinEdge(toSuperviewSafeArea: .top)
|
||||
view.pin(.trailing, to: .trailing, of: tabBar)
|
||||
// Page VC constraints
|
||||
let pageVCView = pageVC.view!
|
||||
view.addSubview(pageVCView)
|
||||
pageVCView.pin(.leading, to: .leading, of: view)
|
||||
pageVCView.pin(.top, to: .bottom, of: tabBar)
|
||||
view.pin(.trailing, to: .trailing, of: pageVCView)
|
||||
view.pin(.bottom, to: .bottom, of: pageVCView)
|
||||
let screen = UIScreen.main.bounds
|
||||
pageVCView.set(.width, to: screen.width)
|
||||
let statusBarHeight = UIApplication.shared.statusBarFrame.height
|
||||
let height = navigationController!.view.bounds.height - navigationBar.height() - Values.tabBarHeight - statusBarHeight
|
||||
pageVCView.set(.height, to: height)
|
||||
recoveryPhraseVC.constrainHeight(to: height)
|
||||
scanQRCodePlaceholderVC.constrainHeight(to: height)
|
||||
}
|
||||
|
||||
override func viewDidAppear(_ animated: Bool) {
|
||||
super.viewDidAppear(animated)
|
||||
tabBarTopConstraint.constant = navigationController!.navigationBar.height()
|
||||
}
|
||||
|
||||
deinit {
|
||||
NotificationCenter.default.removeObserver(self)
|
||||
}
|
||||
|
||||
// MARK: General
|
||||
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
|
||||
guard let index = pages.firstIndex(of: viewController), index != 0 else { return nil }
|
||||
return pages[index - 1]
|
||||
}
|
||||
|
||||
func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
|
||||
guard let index = pages.firstIndex(of: viewController), index != (pages.count - 1) else { return nil }
|
||||
return pages[index + 1]
|
||||
}
|
||||
|
||||
fileprivate func handleCameraAccessGranted() {
|
||||
pages[1] = scanQRCodeWrapperVC
|
||||
pageVC.setViewControllers([ scanQRCodeWrapperVC ], direction: .forward, animated: false, completion: nil)
|
||||
}
|
||||
|
||||
// MARK: Updating
|
||||
func pageViewController(_ pageViewController: UIPageViewController, willTransitionTo pendingViewControllers: [UIViewController]) {
|
||||
guard let targetVC = pendingViewControllers.first, let index = pages.firstIndex(of: targetVC) else { return }
|
||||
targetVCIndex = index
|
||||
}
|
||||
|
||||
func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating isFinished: Bool, previousViewControllers: [UIViewController], transitionCompleted isCompleted: Bool) {
|
||||
guard isCompleted, let index = targetVCIndex else { return }
|
||||
tabBar.selectTab(at: index)
|
||||
}
|
||||
|
||||
// MARK: Interaction
|
||||
@objc private func close() {
|
||||
dismiss(animated: true, completion: nil)
|
||||
}
|
||||
|
||||
func controller(_ controller: OWSQRCodeScanningViewController, didDetectQRCodeWith string: String) {
|
||||
print(string)
|
||||
}
|
||||
|
||||
func continueWithSeed(_ seed: Data) {
|
||||
let (ed25519KeyPair, x25519KeyPair) = KeyPairUtilities.generate(from: seed)
|
||||
KeyPairUtilities.store(seed: seed, ed25519KeyPair: ed25519KeyPair, x25519KeyPair: x25519KeyPair)
|
||||
TSAccountManager.sharedInstance().phoneNumberAwaitingVerification = x25519KeyPair.hexEncodedPublicKey
|
||||
OWSPrimaryStorage.shared().setRestorationTime(Date().timeIntervalSince1970)
|
||||
UserDefaults.standard[.hasViewedSeed] = true
|
||||
UserDefaults.standard[.isUsingFullAPNs] = true // TODO: Get this from the sync message or show the PN mode screen
|
||||
TSAccountManager.sharedInstance().didRegister()
|
||||
let syncTokensJob = SyncPushTokensJob(accountManager: AppEnvironment.shared.accountManager, preferences: Environment.shared.preferences)
|
||||
syncTokensJob.uploadOnlyIfStale = false
|
||||
let _: Promise<Void> = syncTokensJob.run()
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(handleConfigurationMessageReceived), name: .configurationMessageReceived, object: nil)
|
||||
ModalActivityIndicatorViewController.present(fromViewController: navigationController!) { [weak self] modal in
|
||||
self?.activityIndicatorModal = modal
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func handleConfigurationMessageReceived() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private final class RecoveryPhraseVC : UIViewController {
|
||||
weak var linkDeviceVC: LinkDeviceVC!
|
||||
private var spacer1HeightConstraint: NSLayoutConstraint!
|
||||
private var spacer2HeightConstraint: NSLayoutConstraint!
|
||||
private var restoreButtonBottomOffsetConstraint: NSLayoutConstraint!
|
||||
private var bottomConstraint: NSLayoutConstraint!
|
||||
|
||||
private lazy var mnemonicTextView: TextView = {
|
||||
let result = TextView(placeholder: NSLocalizedString("vc_restore_seed_text_field_hint", comment: ""))
|
||||
result.layer.borderColor = Colors.text.cgColor
|
||||
result.accessibilityLabel = "Recovery phrase text view"
|
||||
return result
|
||||
}()
|
||||
|
||||
// MARK: Lifecycle
|
||||
override func viewDidLoad() {
|
||||
view.backgroundColor = .clear
|
||||
// Title label
|
||||
let titleLabel = UILabel()
|
||||
titleLabel.textColor = Colors.text
|
||||
titleLabel.font = .boldSystemFont(ofSize: isIPhone5OrSmaller ? Values.largeFontSize : Values.veryLargeFontSize)
|
||||
titleLabel.text = "Recovery Phrase"
|
||||
titleLabel.numberOfLines = 0
|
||||
titleLabel.lineBreakMode = .byWordWrapping
|
||||
// Explanation label
|
||||
let explanationLabel = UILabel()
|
||||
explanationLabel.textColor = Colors.text
|
||||
explanationLabel.font = .systemFont(ofSize: Values.smallFontSize)
|
||||
explanationLabel.text = "To link your device, enter the recovery phrase that was given to you when you signed up."
|
||||
explanationLabel.numberOfLines = 0
|
||||
explanationLabel.lineBreakMode = .byWordWrapping
|
||||
// Spacers
|
||||
let topSpacer = UIView.vStretchingSpacer()
|
||||
let spacer1 = UIView()
|
||||
spacer1HeightConstraint = spacer1.set(.height, to: isIPhone5OrSmaller ? Values.smallSpacing : Values.veryLargeSpacing)
|
||||
let spacer2 = UIView()
|
||||
spacer2HeightConstraint = spacer2.set(.height, to: isIPhone5OrSmaller ? Values.smallSpacing : Values.veryLargeSpacing)
|
||||
let bottomSpacer = UIView.vStretchingSpacer()
|
||||
let restoreButtonBottomOffsetSpacer = UIView()
|
||||
restoreButtonBottomOffsetConstraint = restoreButtonBottomOffsetSpacer.set(.height, to: Values.onboardingButtonBottomOffset)
|
||||
// Continue button
|
||||
let continueButton = Button(style: .prominentFilled, size: .large)
|
||||
continueButton.setTitle(NSLocalizedString("continue_2", comment: ""), for: UIControl.State.normal)
|
||||
continueButton.titleLabel!.font = .boldSystemFont(ofSize: Values.mediumFontSize)
|
||||
continueButton.addTarget(self, action: #selector(handleContinueButtonTapped), for: UIControl.Event.touchUpInside)
|
||||
// Continue button container
|
||||
let continueButtonContainer = UIView()
|
||||
continueButtonContainer.addSubview(continueButton)
|
||||
continueButton.pin(.leading, to: .leading, of: continueButtonContainer, withInset: Values.massiveSpacing)
|
||||
continueButton.pin(.top, to: .top, of: continueButtonContainer)
|
||||
continueButtonContainer.pin(.trailing, to: .trailing, of: continueButton, withInset: Values.massiveSpacing)
|
||||
continueButtonContainer.pin(.bottom, to: .bottom, of: continueButton)
|
||||
// Top stack view
|
||||
let topStackView = UIStackView(arrangedSubviews: [ titleLabel, spacer1, explanationLabel, spacer2, mnemonicTextView ])
|
||||
topStackView.axis = .vertical
|
||||
topStackView.alignment = .fill
|
||||
// Top stack view container
|
||||
let topStackViewContainer = UIView()
|
||||
topStackViewContainer.addSubview(topStackView)
|
||||
topStackView.pin(.leading, to: .leading, of: topStackViewContainer, withInset: Values.veryLargeSpacing)
|
||||
topStackView.pin(.top, to: .top, of: topStackViewContainer)
|
||||
topStackViewContainer.pin(.trailing, to: .trailing, of: topStackView, withInset: Values.veryLargeSpacing)
|
||||
topStackViewContainer.pin(.bottom, to: .bottom, of: topStackView)
|
||||
// Main stack view
|
||||
let mainStackView = UIStackView(arrangedSubviews: [ topSpacer, topStackViewContainer, bottomSpacer, continueButtonContainer, restoreButtonBottomOffsetSpacer ])
|
||||
mainStackView.axis = .vertical
|
||||
mainStackView.alignment = .fill
|
||||
view.addSubview(mainStackView)
|
||||
mainStackView.pin(.leading, to: .leading, of: view)
|
||||
mainStackView.pin(.top, to: .top, of: view)
|
||||
mainStackView.pin(.trailing, to: .trailing, of: view)
|
||||
bottomConstraint = mainStackView.pin(.bottom, to: .bottom, of: view)
|
||||
topSpacer.heightAnchor.constraint(equalTo: bottomSpacer.heightAnchor, multiplier: 1).isActive = true
|
||||
// Dismiss keyboard on tap
|
||||
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard))
|
||||
view.addGestureRecognizer(tapGestureRecognizer)
|
||||
// Listen to keyboard notifications
|
||||
let notificationCenter = NotificationCenter.default
|
||||
notificationCenter.addObserver(self, selector: #selector(handleKeyboardWillChangeFrameNotification(_:)), name: UIResponder.keyboardWillChangeFrameNotification, object: nil)
|
||||
notificationCenter.addObserver(self, selector: #selector(handleKeyboardWillHideNotification(_:)), name: UIResponder.keyboardWillHideNotification, object: nil)
|
||||
// Set up width constraint
|
||||
view.set(.width, to: UIScreen.main.bounds.width)
|
||||
}
|
||||
|
||||
deinit {
|
||||
NotificationCenter.default.removeObserver(self)
|
||||
}
|
||||
|
||||
// MARK: General
|
||||
func constrainHeight(to height: CGFloat) {
|
||||
view.set(.height, to: height)
|
||||
}
|
||||
|
||||
@objc private func dismissKeyboard() {
|
||||
mnemonicTextView.resignFirstResponder()
|
||||
}
|
||||
|
||||
// MARK: Updating
|
||||
@objc private func handleKeyboardWillChangeFrameNotification(_ notification: Notification) {
|
||||
guard let newHeight = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue.size.height else { return }
|
||||
bottomConstraint.constant = -newHeight // Negative due to how the constraint is set up
|
||||
restoreButtonBottomOffsetConstraint.constant = isIPhone6OrSmaller ? Values.smallSpacing : Values.largeSpacing
|
||||
spacer1HeightConstraint.constant = isIPhone6OrSmaller ? Values.smallSpacing : Values.mediumSpacing
|
||||
spacer2HeightConstraint.constant = isIPhone6OrSmaller ? Values.smallSpacing : Values.mediumSpacing
|
||||
UIView.animate(withDuration: 0.25) {
|
||||
self.view.layoutIfNeeded()
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func handleKeyboardWillHideNotification(_ notification: Notification) {
|
||||
bottomConstraint.constant = 0
|
||||
restoreButtonBottomOffsetConstraint.constant = Values.onboardingButtonBottomOffset
|
||||
spacer1HeightConstraint.constant = isIPhone5OrSmaller ? Values.smallSpacing : Values.veryLargeSpacing
|
||||
spacer2HeightConstraint.constant = isIPhone5OrSmaller ? Values.smallSpacing : Values.veryLargeSpacing
|
||||
UIView.animate(withDuration: 0.25) {
|
||||
self.view.layoutIfNeeded()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Interaction
|
||||
@objc private func handleContinueButtonTapped() {
|
||||
func showError(title: String, message: String = "") {
|
||||
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
|
||||
alert.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: ""), style: .default, handler: nil))
|
||||
presentAlert(alert)
|
||||
}
|
||||
let mnemonic = mnemonicTextView.text!
|
||||
do {
|
||||
let hexEncodedSeed = try Mnemonic.decode(mnemonic: mnemonic)
|
||||
let seed = Data(hex: hexEncodedSeed)
|
||||
mnemonicTextView.resignFirstResponder()
|
||||
linkDeviceVC.continueWithSeed(seed)
|
||||
} catch let error {
|
||||
let error = error as? Mnemonic.DecodingError ?? Mnemonic.DecodingError.generic
|
||||
showError(title: error.errorDescription!)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class ScanQRCodePlaceholderVC : UIViewController {
|
||||
weak var linkDeviceVC: LinkDeviceVC!
|
||||
|
||||
override func viewDidLoad() {
|
||||
// Remove background color
|
||||
view.backgroundColor = .clear
|
||||
// Set up explanation label
|
||||
let explanationLabel = UILabel()
|
||||
explanationLabel.textColor = Colors.text
|
||||
explanationLabel.font = .systemFont(ofSize: Values.smallFontSize)
|
||||
explanationLabel.text = NSLocalizedString("vc_scan_qr_code_camera_access_explanation", comment: "")
|
||||
explanationLabel.numberOfLines = 0
|
||||
explanationLabel.textAlignment = .center
|
||||
explanationLabel.lineBreakMode = .byWordWrapping
|
||||
// Set up call to action button
|
||||
let callToActionButton = UIButton()
|
||||
callToActionButton.titleLabel!.font = .boldSystemFont(ofSize: Values.mediumFontSize)
|
||||
callToActionButton.setTitleColor(Colors.accent, for: UIControl.State.normal)
|
||||
callToActionButton.setTitle(NSLocalizedString("vc_scan_qr_code_grant_camera_access_button_title", comment: ""), for: UIControl.State.normal)
|
||||
callToActionButton.addTarget(self, action: #selector(requestCameraAccess), for: UIControl.Event.touchUpInside)
|
||||
// Set up stack view
|
||||
let stackView = UIStackView(arrangedSubviews: [ explanationLabel, callToActionButton ])
|
||||
stackView.axis = .vertical
|
||||
stackView.spacing = Values.mediumSpacing
|
||||
stackView.alignment = .center
|
||||
// Set up constraints
|
||||
view.set(.width, to: UIScreen.main.bounds.width)
|
||||
view.addSubview(stackView)
|
||||
stackView.pin(.leading, to: .leading, of: view, withInset: Values.massiveSpacing)
|
||||
view.pin(.trailing, to: .trailing, of: stackView, withInset: Values.massiveSpacing)
|
||||
let verticalCenteringConstraint = stackView.center(.vertical, in: view)
|
||||
verticalCenteringConstraint.constant = -16 // Makes things appear centered visually
|
||||
}
|
||||
|
||||
func constrainHeight(to height: CGFloat) {
|
||||
view.set(.height, to: height)
|
||||
}
|
||||
|
||||
@objc private func requestCameraAccess() {
|
||||
ows_ask(forCameraPermissions: { [weak self] hasCameraAccess in
|
||||
if hasCameraAccess {
|
||||
self?.linkDeviceVC.handleCameraAccessGranted()
|
||||
} else {
|
||||
// Do nothing
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
|
@ -30,39 +30,49 @@ final class LandingVC : BaseVC {
|
|||
setUpGradientBackground()
|
||||
setUpNavBarStyle()
|
||||
setUpNavBarSessionIcon()
|
||||
// Set up title label
|
||||
// Title label
|
||||
let titleLabel = UILabel()
|
||||
titleLabel.textColor = Colors.text
|
||||
titleLabel.font = .boldSystemFont(ofSize: isIPhone5OrSmaller ? Values.largeFontSize : Values.veryLargeFontSize)
|
||||
titleLabel.text = NSLocalizedString("vc_landing_title_2", comment: "")
|
||||
titleLabel.numberOfLines = 0
|
||||
titleLabel.lineBreakMode = .byWordWrapping
|
||||
// Set up title label container
|
||||
// Title label container
|
||||
let titleLabelContainer = UIView()
|
||||
titleLabelContainer.addSubview(titleLabel)
|
||||
titleLabel.pin(.leading, to: .leading, of: titleLabelContainer, withInset: Values.veryLargeSpacing)
|
||||
titleLabel.pin(.top, to: .top, of: titleLabelContainer)
|
||||
titleLabelContainer.pin(.trailing, to: .trailing, of: titleLabel, withInset: Values.veryLargeSpacing)
|
||||
titleLabelContainer.pin(.bottom, to: .bottom, of: titleLabel)
|
||||
// Set up spacers
|
||||
// Spacers
|
||||
let topSpacer = UIView.vStretchingSpacer()
|
||||
let bottomSpacer = UIView.vStretchingSpacer()
|
||||
// Set up link button container
|
||||
// Link button
|
||||
let linkButton = UIButton()
|
||||
linkButton.setTitle("Link a Device", for: UIControl.State.normal)
|
||||
linkButton.setTitleColor(Colors.text, for: UIControl.State.normal)
|
||||
linkButton.titleLabel!.font = .boldSystemFont(ofSize: Values.smallFontSize)
|
||||
linkButton.addTarget(self, action: #selector(link), for: UIControl.Event.touchUpInside)
|
||||
// Link button container
|
||||
let linkButtonContainer = UIView()
|
||||
linkButtonContainer.set(.height, to: Values.onboardingButtonBottomOffset)
|
||||
// Set up button stack view
|
||||
linkButtonContainer.addSubview(linkButton)
|
||||
linkButton.center(.horizontal, in: linkButtonContainer)
|
||||
let isIPhoneX = (UIApplication.shared.keyWindow!.safeAreaInsets.bottom > 0)
|
||||
linkButton.centerYAnchor.constraint(equalTo: linkButtonContainer.centerYAnchor, constant: isIPhoneX ? -4 : 0).isActive = true
|
||||
// Button stack view
|
||||
let buttonStackView = UIStackView(arrangedSubviews: [ registerButton, restoreButton ])
|
||||
buttonStackView.axis = .vertical
|
||||
buttonStackView.spacing = isIPhone5OrSmaller ? Values.smallSpacing : Values.mediumSpacing
|
||||
buttonStackView.alignment = .fill
|
||||
// Set up button stack view container
|
||||
// Button stack view container
|
||||
let buttonStackViewContainer = UIView()
|
||||
buttonStackViewContainer.addSubview(buttonStackView)
|
||||
buttonStackView.pin(.leading, to: .leading, of: buttonStackViewContainer, withInset: isIPhone5OrSmaller ? CGFloat(52) : Values.massiveSpacing)
|
||||
buttonStackView.pin(.top, to: .top, of: buttonStackViewContainer)
|
||||
buttonStackViewContainer.pin(.trailing, to: .trailing, of: buttonStackView, withInset: isIPhone5OrSmaller ? CGFloat(52) : Values.massiveSpacing)
|
||||
buttonStackViewContainer.pin(.bottom, to: .bottom, of: buttonStackView)
|
||||
// Set up main stack view
|
||||
// Main stack view
|
||||
let mainStackView = UIStackView(arrangedSubviews: [ topSpacer, titleLabelContainer, UIView.spacer(withHeight: isIPhone5OrSmaller ? Values.smallSpacing : Values.mediumSpacing), fakeChatView, bottomSpacer, buttonStackViewContainer, linkButtonContainer ])
|
||||
mainStackView.axis = .vertical
|
||||
mainStackView.alignment = .fill
|
||||
|
@ -88,4 +98,9 @@ final class LandingVC : BaseVC {
|
|||
let restoreVC = RestoreVC()
|
||||
navigationController!.pushViewController(restoreVC, animated: true)
|
||||
}
|
||||
|
||||
@objc private func link() {
|
||||
let linkVC = LinkDeviceVC()
|
||||
navigationController!.pushViewController(linkVC, animated: true)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ final class NukeDataModal : Modal {
|
|||
func proceed() {
|
||||
let appDelegate = UIApplication.shared.delegate as! AppDelegate
|
||||
ModalActivityIndicatorViewController.present(fromViewController: self, canCancel: false) { [weak self] _ in
|
||||
appDelegate.forceSyncConfigurationNowIfNeeded().done(on: DispatchQueue.main) {
|
||||
appDelegate.forceSyncConfigurationNowIfNeeded().ensure(on: DispatchQueue.main) {
|
||||
self?.dismiss(animated: true, completion: nil) // Dismiss the loader
|
||||
UserDefaults.removeAll() // Not done in the nuke data implementation as unlinking requires this to happen later
|
||||
NotificationCenter.default.post(name: .dataNukeRequested, object: nil)
|
||||
|
|
|
@ -147,6 +147,7 @@ extension MessageReceiver {
|
|||
guard message.sender == getUserHexEncodedPublicKey(), !UserDefaults.standard[.hasSyncedConfiguration] else { return }
|
||||
let storage = SNMessagingKitConfiguration.shared.storage
|
||||
let allClosedGroupPublicKeys = storage.getUserClosedGroupPublicKeys()
|
||||
NotificationCenter.default.post(name: .configurationMessageReceived, object: nil)
|
||||
for closedGroup in message.closedGroups {
|
||||
guard !allClosedGroupPublicKeys.contains(closedGroup.publicKey) else { continue }
|
||||
handleNewClosedGroup(groupPublicKey: closedGroup.publicKey, name: closedGroup.name, encryptionKeyPair: closedGroup.encryptionKeyPair,
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
public extension Notification.Name {
|
||||
|
||||
static let configurationMessageReceived = Notification.Name("configurationMessageReceived")
|
||||
}
|
||||
|
||||
@objc public extension NSNotification {
|
||||
|
||||
@objc static let configurationMessageReceived = Notification.Name.configurationMessageReceived.rawValue as NSString
|
||||
}
|
Loading…
Reference in New Issue