mirror of https://github.com/oxen-io/session-ios
Merge branch 'dev' into group-chat
commit
d95df736d5
@ -0,0 +1,39 @@
|
|||||||
|
|
||||||
|
final class QRCodeViewController : OWSViewController {
|
||||||
|
|
||||||
|
public override var supportedInterfaceOrientations: UIInterfaceOrientationMask { return .portrait}
|
||||||
|
public override var preferredStatusBarStyle: UIStatusBarStyle { return .lightContent}
|
||||||
|
|
||||||
|
override func viewDidLoad() {
|
||||||
|
super.viewDidLoad()
|
||||||
|
let stackView = UIStackView(arrangedSubviews: [])
|
||||||
|
stackView.axis = .vertical
|
||||||
|
stackView.spacing = 32
|
||||||
|
stackView.alignment = .center
|
||||||
|
stackView.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
view.addSubview(stackView)
|
||||||
|
NSLayoutConstraint.activate([
|
||||||
|
stackView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 32),
|
||||||
|
stackView.topAnchor.constraint(equalTo: view.topAnchor, constant: 24),
|
||||||
|
view.trailingAnchor.constraint(equalTo: stackView.trailingAnchor, constant: 32)
|
||||||
|
])
|
||||||
|
let label = UILabel()
|
||||||
|
label.font = UIFont.ows_dynamicTypeSubheadlineClamped
|
||||||
|
label.text = NSLocalizedString("This is your personal QR code. Other people can scan it to start a secure conversation with you.", comment: "")
|
||||||
|
label.numberOfLines = 0
|
||||||
|
label.textAlignment = .center
|
||||||
|
label.lineBreakMode = .byWordWrapping
|
||||||
|
label.textColor = UIColor.ows_white
|
||||||
|
stackView.addArrangedSubview(label)
|
||||||
|
let imageView = UIImageView()
|
||||||
|
let hexEncodedPublicKey = OWSIdentityManager.shared().identityKeyPair()!.hexEncodedPublicKey
|
||||||
|
let data = hexEncodedPublicKey.data(using: .utf8)
|
||||||
|
let filter = CIFilter(name: "CIQRCodeGenerator")!
|
||||||
|
filter.setValue(data, forKey: "inputMessage")
|
||||||
|
let qrCodeAsCIImage = filter.outputImage!
|
||||||
|
let scaledQRCodeAsCIImage = qrCodeAsCIImage.transformed(by: CGAffineTransform(scaleX: 6.4, y: 6.4))
|
||||||
|
let qrCode = UIImage(ciImage: scaledQRCodeAsCIImage)
|
||||||
|
imageView.image = qrCode
|
||||||
|
stackView.addArrangedSubview(imageView)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
#import <SignalMessaging/OWSViewController.h>
|
||||||
|
#import "OWSQRCodeScanningViewController.h"
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
@interface ScanQRCodeViewController : OWSViewController
|
||||||
|
|
||||||
|
@property (nonatomic, weak) UIViewController<OWSQRScannerDelegate> *delegate;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_END
|
@ -0,0 +1,62 @@
|
|||||||
|
#import "ScanQRCodeViewController.h"
|
||||||
|
#import "Session-Swift.h"
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
@interface ScanQRCodeViewController ()
|
||||||
|
|
||||||
|
@property (nonatomic) OWSQRCodeScanningViewController *qrCodeScanningVC;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation ScanQRCodeViewController
|
||||||
|
|
||||||
|
- (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
|
Loading…
Reference in New Issue