From 4afeba866b8bf8d27f39d89a5a3234bd3f65beca Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Tue, 19 Nov 2019 14:35:38 +1100 Subject: [PATCH] Convert ScanQRCodeVC to Swift --- Signal.xcodeproj/project.pbxproj | 10 ++- .../Loki/Messaging/NewConversationVC.swift | 6 +- Signal/src/Loki/Messaging/ScanQRCodeVC.h | 12 ---- Signal/src/Loki/Messaging/ScanQRCodeVC.m | 62 ------------------- Signal/src/Loki/Messaging/ScanQRCodeVC.swift | 50 +++++++++++++++ Signal/src/Signal-Bridging-Header.h | 2 +- 6 files changed, 58 insertions(+), 84 deletions(-) delete mode 100644 Signal/src/Loki/Messaging/ScanQRCodeVC.h delete mode 100644 Signal/src/Loki/Messaging/ScanQRCodeVC.m create mode 100644 Signal/src/Loki/Messaging/ScanQRCodeVC.swift diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index 7429af9b2..7d31ab871 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -564,7 +564,6 @@ B8162F0522892C5F00D46544 /* FriendRequestViewDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8162F0422892C5F00D46544 /* FriendRequestViewDelegate.swift */; }; B821F2F82272CED3002C88C0 /* DisplayNameVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B821F2F72272CED3002C88C0 /* DisplayNameVC.swift */; }; B821F2FA2272CEEE002C88C0 /* SeedVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B821F2F92272CEEE002C88C0 /* SeedVC.swift */; }; - B8258493230FA5E9001B41CB /* ScanQRCodeVC.m in Sources */ = {isa = PBXBuildFile; fileRef = B8258492230FA5E9001B41CB /* ScanQRCodeVC.m */; }; B82584A02315024B001B41CB /* LokiRSSFeedPoller.swift in Sources */ = {isa = PBXBuildFile; fileRef = B825849F2315024B001B41CB /* LokiRSSFeedPoller.swift */; }; B846365B22B7418B00AF1514 /* Identicon+ObjC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B846365A22B7418B00AF1514 /* Identicon+ObjC.swift */; }; B84664F5235022F30083A1CD /* MentionUtilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = B84664F4235022F30083A1CD /* MentionUtilities.swift */; }; @@ -576,6 +575,7 @@ B891105C2320872800F15FCC /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = B891105B2320872800F15FCC /* GoogleService-Info.plist */; }; B891105E2320872800F15FCC /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = B891105B2320872800F15FCC /* GoogleService-Info.plist */; }; B891105F2320872800F15FCC /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = B891105B2320872800F15FCC /* GoogleService-Info.plist */; }; + B893063F2383961A005EAA8E /* ScanQRCodeVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B893063E2383961A005EAA8E /* ScanQRCodeVC.swift */; }; B894D0712339D6F300B4D94D /* DeviceLinkingModalDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B894D0702339D6F300B4D94D /* DeviceLinkingModalDelegate.swift */; }; B894D0752339EDCF00B4D94D /* NukeDataModal.swift in Sources */ = {isa = PBXBuildFile; fileRef = B894D0742339EDCF00B4D94D /* NukeDataModal.swift */; }; B89841E322B7579F00B1BDC6 /* NewConversationVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B89841E222B7579F00B1BDC6 /* NewConversationVC.swift */; }; @@ -1375,8 +1375,6 @@ B8162F0422892C5F00D46544 /* FriendRequestViewDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FriendRequestViewDelegate.swift; sourceTree = ""; }; B821F2F72272CED3002C88C0 /* DisplayNameVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisplayNameVC.swift; sourceTree = ""; }; B821F2F92272CEEE002C88C0 /* SeedVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeedVC.swift; sourceTree = ""; }; - B8258491230FA5DA001B41CB /* ScanQRCodeVC.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ScanQRCodeVC.h; sourceTree = ""; }; - B8258492230FA5E9001B41CB /* ScanQRCodeVC.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ScanQRCodeVC.m; sourceTree = ""; }; B825849F2315024B001B41CB /* LokiRSSFeedPoller.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LokiRSSFeedPoller.swift; sourceTree = ""; }; B846365A22B7418B00AF1514 /* Identicon+ObjC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Identicon+ObjC.swift"; sourceTree = ""; }; B84664F4235022F30083A1CD /* MentionUtilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MentionUtilities.swift; sourceTree = ""; }; @@ -1386,6 +1384,7 @@ B885D5F3233491AB00EE0D8E /* DeviceLinkingModal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceLinkingModal.swift; sourceTree = ""; }; B885D5F52334A32100EE0D8E /* UIView+Constraint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+Constraint.swift"; sourceTree = ""; }; B891105B2320872800F15FCC /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = ""; }; + B893063E2383961A005EAA8E /* ScanQRCodeVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScanQRCodeVC.swift; sourceTree = ""; }; B894D0702339D6F300B4D94D /* DeviceLinkingModalDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceLinkingModalDelegate.swift; sourceTree = ""; }; B894D0742339EDCF00B4D94D /* NukeDataModal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NukeDataModal.swift; sourceTree = ""; }; B89841E222B7579F00B1BDC6 /* NewConversationVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewConversationVC.swift; sourceTree = ""; }; @@ -2708,8 +2707,7 @@ B8B26C90234D8CBD004ED98C /* MentionCandidateSelectionViewDelegate.swift */, B89841E222B7579F00B1BDC6 /* NewConversationVC.swift */, 24BD2608234DA2050008EB0A /* NewPublicChatVC.swift */, - B8258491230FA5DA001B41CB /* ScanQRCodeVC.h */, - B8258492230FA5E9001B41CB /* ScanQRCodeVC.m */, + B893063E2383961A005EAA8E /* ScanQRCodeVC.swift */, ); path = Messaging; sourceTree = ""; @@ -3734,6 +3732,7 @@ 34D99C931F2937CC00D284D6 /* OWSAnalytics.swift in Sources */, 340FC8B8204DAC8D007AEB0F /* AddToGroupViewController.m in Sources */, 341F2C0F1F2B8AE700D07D6B /* DebugUIMisc.m in Sources */, + B893063F2383961A005EAA8E /* ScanQRCodeVC.swift in Sources */, 340FC8AF204DAC8D007AEB0F /* OWSLinkDeviceViewController.m in Sources */, 34E3EF0D1EFC235B007F6822 /* DebugUIDiskUsage.m in Sources */, 454A84042059C787008B8C75 /* MediaTileViewController.swift in Sources */, @@ -3930,7 +3929,6 @@ B86BD08423399ACF000F5AE3 /* Modal.swift in Sources */, 34D1F0861F8678AA0066283D /* ConversationViewController.m in Sources */, 3427C64320F500E000EEC730 /* OWSMessageTimerView.m in Sources */, - B8258493230FA5E9001B41CB /* ScanQRCodeVC.m in Sources */, B90418E6183E9DD40038554A /* DateUtil.m in Sources */, 3448E15E221333F5004B052E /* OnboardingController.swift in Sources */, 340FC8BD204DAC8D007AEB0F /* ShowGroupMembersViewController.m in Sources */, diff --git a/Signal/src/Loki/Messaging/NewConversationVC.swift b/Signal/src/Loki/Messaging/NewConversationVC.swift index ba63e612d..7fed92b34 100644 --- a/Signal/src/Loki/Messaging/NewConversationVC.swift +++ b/Signal/src/Loki/Messaging/NewConversationVC.swift @@ -81,9 +81,9 @@ final class NewConversationVC : OWSViewController, OWSQRScannerDelegate { @objc private func scanQRCode() { ows_ask(forCameraPermissions: { [weak self] hasCameraAccess in if hasCameraAccess { - let scanQRCodeVC = ScanQRCodeVC() - scanQRCodeVC.delegate = self - self?.navigationController!.pushViewController(scanQRCodeVC, animated: true) + let scanQRCodeWrapperVC = ScanQRCodeWrapperVC() + scanQRCodeWrapperVC.delegate = self + self?.navigationController!.pushViewController(scanQRCodeWrapperVC, animated: true) } else { // Do nothing } diff --git a/Signal/src/Loki/Messaging/ScanQRCodeVC.h b/Signal/src/Loki/Messaging/ScanQRCodeVC.h deleted file mode 100644 index c4a50a564..000000000 --- a/Signal/src/Loki/Messaging/ScanQRCodeVC.h +++ /dev/null @@ -1,12 +0,0 @@ -#import -#import "OWSQRCodeScanningViewController.h" - -NS_ASSUME_NONNULL_BEGIN - -@interface ScanQRCodeVC : OWSViewController - -@property (nonatomic, weak) UIViewController *delegate; - -@end - -NS_ASSUME_NONNULL_END diff --git a/Signal/src/Loki/Messaging/ScanQRCodeVC.m b/Signal/src/Loki/Messaging/ScanQRCodeVC.m deleted file mode 100644 index c035dd0e3..000000000 --- a/Signal/src/Loki/Messaging/ScanQRCodeVC.m +++ /dev/null @@ -1,62 +0,0 @@ -#import "ScanQRCodeVC.h" -#import "Session-Swift.h" - -NS_ASSUME_NONNULL_BEGIN - -@interface ScanQRCodeVC () - -@property (nonatomic) OWSQRCodeScanningViewController *qrCodeScanningVC; - -@end - -@implementation ScanQRCodeVC - -- (UIInterfaceOrientationMask)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; } - -- (void)viewDidLoad -{ - [super viewDidLoad]; - // Background color - self.view.backgroundColor = Theme.backgroundColor; - // QR code scanning VC - self.qrCodeScanningVC = [OWSQRCodeScanningViewController new]; - self.qrCodeScanningVC.scanDelegate = self.delegate; - [self.view addSubview:self.qrCodeScanningVC.view]; - [self.qrCodeScanningVC.view autoPinEdgeToSuperviewEdge:ALEdgeLeading]; - [self.qrCodeScanningVC.view autoPinEdgeToSuperviewEdge:ALEdgeTrailing]; - [self.qrCodeScanningVC.view autoPinToTopLayoutGuideOfViewController:self withInset:0.0]; - [self.qrCodeScanningVC.view autoPinToSquareAspectRatio]; - // Explanation label - UILabel *explanationLabel = [UILabel new]; - explanationLabel.text = NSLocalizedString(@"Scan the QR code of the person you'd like to securely message. They can find their QR code by going into Loki Messenger's in-app settings and clicking \"Show QR Code\".", @""); - explanationLabel.textColor = Theme.primaryColor; - explanationLabel.font = UIFont.ows_dynamicTypeSubheadlineClampedFont; - explanationLabel.numberOfLines = 0; - explanationLabel.lineBreakMode = NSLineBreakByWordWrapping; - explanationLabel.textAlignment = NSTextAlignmentCenter; - // Bottom view - UIView *bottomView = [UIView new]; - [self.view addSubview:bottomView]; - [bottomView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.qrCodeScanningVC.view]; - [bottomView autoPinEdgeToSuperviewEdge:ALEdgeLeading]; - [bottomView autoPinEdgeToSuperviewEdge:ALEdgeTrailing]; - [bottomView autoPinEdgeToSuperviewEdge:ALEdgeBottom]; - [bottomView addSubview:explanationLabel]; - [explanationLabel autoPinWidthToSuperviewWithMargin:32]; - [explanationLabel autoPinHeightToSuperviewWithMargin:32]; - // Title - self.title = NSLocalizedString(@"Scan QR Code", ""); -} - -- (void)viewDidAppear:(BOOL)animated -{ - [super viewDidAppear:animated]; - [UIDevice.currentDevice ows_setOrientation:UIInterfaceOrientationPortrait]; - dispatch_async(dispatch_get_main_queue(), ^{ - [self.qrCodeScanningVC startCapture]; - }); -} - -@end - -NS_ASSUME_NONNULL_END diff --git a/Signal/src/Loki/Messaging/ScanQRCodeVC.swift b/Signal/src/Loki/Messaging/ScanQRCodeVC.swift new file mode 100644 index 000000000..1db307b45 --- /dev/null +++ b/Signal/src/Loki/Messaging/ScanQRCodeVC.swift @@ -0,0 +1,50 @@ + +final class ScanQRCodeWrapperVC : UIViewController { + var delegate: (UIViewController & OWSQRScannerDelegate)? = nil + private let scanQRCodeVC = OWSQRCodeScanningViewController() + + // MARK: Settings + override var supportedInterfaceOrientations: UIInterfaceOrientationMask { return .portrait } + + // MARK: Lifecycle + override func viewDidLoad() { + // Background color + view.backgroundColor = Theme.backgroundColor + // Scan QR code VC + scanQRCodeVC.scanDelegate = delegate + let scanQRCodeVCView = scanQRCodeVC.view! + view.addSubview(scanQRCodeVCView) + scanQRCodeVCView.pin(.leading, to: .leading, of: view) + scanQRCodeVCView.pin(.trailing, to: .trailing, of: view) + scanQRCodeVCView.autoPin(toTopLayoutGuideOf: self, withInset: 0) + scanQRCodeVCView.autoPinToSquareAspectRatio() + // Bottom view + let bottomView = UIView() + view.addSubview(bottomView) + bottomView.pin(.top, to: .bottom, of: scanQRCodeVCView) + bottomView.pin(.leading, to: .leading, of: view) + bottomView.pin(.trailing, to: .trailing, of: view) + bottomView.pin(.bottom, to: .bottom, of: view) + // Explanation label + let explanationLabel = UILabel() + explanationLabel.text = NSLocalizedString("Scan the QR code of the person you'd like to securely message. They can find their QR code by going into Loki Messenger's in-app settings and clicking \"Show QR Code\".", comment: "") + explanationLabel.textColor = Theme.primaryColor + explanationLabel.font = .ows_dynamicTypeSubheadlineClamped + explanationLabel.numberOfLines = 0 + explanationLabel.lineBreakMode = .byWordWrapping + explanationLabel.textAlignment = .center + bottomView.addSubview(explanationLabel) + explanationLabel.autoPinWidthToSuperview(withMargin: 32) + explanationLabel.autoPinHeightToSuperview(withMargin: 32) + // Title + title = NSLocalizedString("Scan QR Code", comment: "") + } + + override func viewDidAppear(_ animated: Bool) { + super.viewDidAppear(animated) + UIDevice.current.ows_setOrientation(.portrait) + DispatchQueue.main.async { [weak self] in + self?.scanQRCodeVC.startCapture() + } + } +} diff --git a/Signal/src/Signal-Bridging-Header.h b/Signal/src/Signal-Bridging-Header.h index 4e2f57b67..90a923fac 100644 --- a/Signal/src/Signal-Bridging-Header.h +++ b/Signal/src/Signal-Bridging-Header.h @@ -44,7 +44,7 @@ #import "PrivacySettingsTableViewController.h" #import "ProfileViewController.h" #import "RemoteVideoView.h" -#import "ScanQRCodeVC.h" +#import "OWSQRCodeScanningViewController.h" #import "SignalApp.h" #import "UIViewController+Permissions.h" #import "ViewControllerUtils.h"