Convert ScanQRCodeVC to Swift

pull/66/head
Niels Andriesse 5 years ago
parent 4577d574e2
commit 4afeba866b

@ -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 = "<group>"; };
B821F2F72272CED3002C88C0 /* DisplayNameVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisplayNameVC.swift; sourceTree = "<group>"; };
B821F2F92272CEEE002C88C0 /* SeedVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeedVC.swift; sourceTree = "<group>"; };
B8258491230FA5DA001B41CB /* ScanQRCodeVC.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ScanQRCodeVC.h; sourceTree = "<group>"; };
B8258492230FA5E9001B41CB /* ScanQRCodeVC.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ScanQRCodeVC.m; sourceTree = "<group>"; };
B825849F2315024B001B41CB /* LokiRSSFeedPoller.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LokiRSSFeedPoller.swift; sourceTree = "<group>"; };
B846365A22B7418B00AF1514 /* Identicon+ObjC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Identicon+ObjC.swift"; sourceTree = "<group>"; };
B84664F4235022F30083A1CD /* MentionUtilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MentionUtilities.swift; sourceTree = "<group>"; };
@ -1386,6 +1384,7 @@
B885D5F3233491AB00EE0D8E /* DeviceLinkingModal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceLinkingModal.swift; sourceTree = "<group>"; };
B885D5F52334A32100EE0D8E /* UIView+Constraint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+Constraint.swift"; sourceTree = "<group>"; };
B891105B2320872800F15FCC /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
B893063E2383961A005EAA8E /* ScanQRCodeVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScanQRCodeVC.swift; sourceTree = "<group>"; };
B894D0702339D6F300B4D94D /* DeviceLinkingModalDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceLinkingModalDelegate.swift; sourceTree = "<group>"; };
B894D0742339EDCF00B4D94D /* NukeDataModal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NukeDataModal.swift; sourceTree = "<group>"; };
B89841E222B7579F00B1BDC6 /* NewConversationVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewConversationVC.swift; sourceTree = "<group>"; };
@ -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 = "<group>";
@ -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 */,

@ -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
}

@ -1,12 +0,0 @@
#import <SignalMessaging/OWSViewController.h>
#import "OWSQRCodeScanningViewController.h"
NS_ASSUME_NONNULL_BEGIN
@interface ScanQRCodeVC : OWSViewController
@property (nonatomic, weak) UIViewController<OWSQRScannerDelegate> *delegate;
@end
NS_ASSUME_NONNULL_END

@ -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

@ -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()
}
}
}

@ -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"

Loading…
Cancel
Save