diff --git a/Signal/src/Storyboard/Main.storyboard b/Signal/src/Storyboard/Main.storyboard index ca04385c5..3b1417e92 100644 --- a/Signal/src/Storyboard/Main.storyboard +++ b/Signal/src/Storyboard/Main.storyboard @@ -1,224 +1,11 @@ - + - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m b/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m index 3c6f0709f..41fd33cba 100644 --- a/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m +++ b/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 Open Whisper Systems. All rights reserved. +// Copyright (c) 2019 Open Whisper Systems. All rights reserved. // #import "AppSettingsViewController.h" @@ -360,8 +360,7 @@ - (void)showLinkedDevices { - OWSLinkedDevicesTableViewController *vc = - [[UIStoryboard main] instantiateViewControllerWithIdentifier:@"OWSLinkedDevicesTableViewController"]; + OWSLinkedDevicesTableViewController *vc = [OWSLinkedDevicesTableViewController new]; [self.navigationController pushViewController:vc animated:YES]; } diff --git a/Signal/src/ViewControllers/AppSettings/OWSLinkDeviceViewController.h b/Signal/src/ViewControllers/AppSettings/OWSLinkDeviceViewController.h index 7cd3cfbf4..e03c97d50 100644 --- a/Signal/src/ViewControllers/AppSettings/OWSLinkDeviceViewController.h +++ b/Signal/src/ViewControllers/AppSettings/OWSLinkDeviceViewController.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 Open Whisper Systems. All rights reserved. +// Copyright (c) 2019 Open Whisper Systems. All rights reserved. // #import "OWSQRCodeScanningViewController.h" @@ -9,9 +9,9 @@ NS_ASSUME_NONNULL_BEGIN @class OWSLinkedDevicesTableViewController; -@interface OWSLinkDeviceViewController : OWSViewController +@interface OWSLinkDeviceViewController : OWSViewController -@property OWSLinkedDevicesTableViewController *linkedDevicesTableViewController; +@property (nonatomic, weak) OWSLinkedDevicesTableViewController *linkedDevicesTableViewController; - (void)controller:(OWSQRCodeScanningViewController *)controller didDetectQRCodeWithString:(NSString *)string; diff --git a/Signal/src/ViewControllers/AppSettings/OWSLinkDeviceViewController.m b/Signal/src/ViewControllers/AppSettings/OWSLinkDeviceViewController.m index 27501cc83..7e707980a 100644 --- a/Signal/src/ViewControllers/AppSettings/OWSLinkDeviceViewController.m +++ b/Signal/src/ViewControllers/AppSettings/OWSLinkDeviceViewController.m @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 Open Whisper Systems. All rights reserved. +// Copyright (c) 2019 Open Whisper Systems. All rights reserved. // #import "OWSLinkDeviceViewController.h" @@ -16,11 +16,11 @@ NS_ASSUME_NONNULL_BEGIN -@interface OWSLinkDeviceViewController () +@interface OWSLinkDeviceViewController () @property (nonatomic) YapDatabaseConnection *dbConnection; -@property (nonatomic) IBOutlet UIView *qrScanningView; -@property (nonatomic) IBOutlet UILabel *scanningInstructionsLabel; +@property (nonatomic) UIView *qrScanningView; +@property (nonatomic) UILabel *scanningInstructionsLabel; @property (nonatomic) OWSQRCodeScanningViewController *qrScanningController; @property (nonatomic, readonly) OWSReadReceiptManager *readReceiptManager; @@ -32,16 +32,52 @@ NS_ASSUME_NONNULL_BEGIN { [super viewDidLoad]; + self.view.backgroundColor = Theme.backgroundColor; + self.dbConnection = [[OWSPrimaryStorage sharedManager] newDatabaseConnection]; - // HACK to get full width preview layer - CGRect oldFrame = self.qrScanningView.frame; - self.qrScanningView.frame = CGRectMake( - oldFrame.origin.x, oldFrame.origin.y, self.view.frame.size.width, self.view.frame.size.height / 2.0f - 32.0f); - // END HACK to get full width preview layer + UIImage *heroImage = [UIImage imageNamed:@"ic_devices_ios"]; + OWSAssertDebug(heroImage); + UIImageView *heroImageView = [[UIImageView alloc] initWithImage:heroImage]; + [heroImageView autoSetDimensionsToSize:heroImage.size]; + self.scanningInstructionsLabel = [UILabel new]; self.scanningInstructionsLabel.text = NSLocalizedString(@"LINK_DEVICE_SCANNING_INSTRUCTIONS", @"QR Scanning screen instructions, placed alongside a camera view for scanning QR Codes"); + self.scanningInstructionsLabel.textColor = Theme.primaryColor; + self.scanningInstructionsLabel.font = UIFont.ows_dynamicTypeCaption1Font; + self.scanningInstructionsLabel.numberOfLines = 0; + self.scanningInstructionsLabel.lineBreakMode = NSLineBreakByWordWrapping; + self.scanningInstructionsLabel.textAlignment = NSTextAlignmentCenter; + + self.qrScanningController = [OWSQRCodeScanningViewController new]; + self.qrScanningController.scanDelegate = self; + [self.view addSubview:self.qrScanningController.view]; + [self.qrScanningController.view autoPinEdgeToSuperviewEdge:ALEdgeLeading]; + [self.qrScanningController.view autoPinEdgeToSuperviewEdge:ALEdgeTrailing]; + [self.qrScanningController.view autoPinToTopLayoutGuideOfViewController:self withInset:0.f]; + [self.qrScanningController.view autoPinToAspectRatio:1.f]; + + UIView *bottomView = [UIView new]; + [self.view addSubview:bottomView]; + [bottomView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.qrScanningController.view]; + [bottomView autoPinEdgeToSuperviewEdge:ALEdgeLeading]; + [bottomView autoPinEdgeToSuperviewEdge:ALEdgeTrailing]; + [bottomView autoPinEdgeToSuperviewEdge:ALEdgeBottom]; + + UIStackView *bottomStack = [[UIStackView alloc] initWithArrangedSubviews:@[ + heroImageView, + self.scanningInstructionsLabel, + ]]; + bottomStack.axis = UILayoutConstraintAxisVertical; + bottomStack.alignment = UIStackViewAlignmentCenter; + bottomStack.spacing = 2; + bottomStack.layoutMarginsRelativeArrangement = YES; + bottomStack.layoutMargins = UIEdgeInsetsMake(20, 20, 20, 20); + [bottomView addSubview:bottomStack]; + [bottomStack autoPinWidthToSuperview]; + [bottomStack autoVCenterInSuperview]; + self.title = NSLocalizedString(@"LINK_NEW_DEVICE_TITLE", "Navigation title when scanning QR code to add new device."); } @@ -83,21 +119,12 @@ NS_ASSUME_NONNULL_BEGIN - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; - [self.qrScanningController startCapture]; -} -- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(nullable id)sender -{ - if ([segue.identifier isEqualToString:@"embedDeviceQRScanner"]) { - OWSQRCodeScanningViewController *qrScanningController - = (OWSQRCodeScanningViewController *)segue.destinationViewController; - qrScanningController.scanDelegate = self; - self.qrScanningController = qrScanningController; - } + [self.qrScanningController startCapture]; } - // pragma mark - OWSQRScannerDelegate + - (void)controller:(OWSQRCodeScanningViewController *)controller didDetectQRCodeWithString:(NSString *)string { OWSDeviceProvisioningURLParser *parser = [[OWSDeviceProvisioningURLParser alloc] initWithProvisioningURL:string]; diff --git a/Signal/src/ViewControllers/AppSettings/OWSLinkedDevicesTableViewController.m b/Signal/src/ViewControllers/AppSettings/OWSLinkedDevicesTableViewController.m index 304e2df80..f2786ba2b 100644 --- a/Signal/src/ViewControllers/AppSettings/OWSLinkedDevicesTableViewController.m +++ b/Signal/src/ViewControllers/AppSettings/OWSLinkedDevicesTableViewController.m @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 Open Whisper Systems. All rights reserved. +// Copyright (c) 2019 Open Whisper Systems. All rights reserved. // #import "OWSLinkedDevicesTableViewController.h" @@ -49,7 +49,8 @@ int const OWSLinkedDevicesTableViewControllerSectionAddDevice = 1; self.tableView.rowHeight = UITableViewAutomaticDimension; self.tableView.estimatedRowHeight = 60; self.tableView.separatorColor = Theme.cellSeparatorColor; - + [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"AddNewDevice"]; + [self.tableView registerClass:[OWSDeviceTableViewCell class] forCellReuseIdentifier:@"ExistingDevice"]; [self.tableView applyScrollViewInsetsFix]; self.dbConnection = [[OWSPrimaryStorage sharedManager] newDatabaseConnection]; @@ -303,20 +304,29 @@ int const OWSLinkedDevicesTableViewControllerSectionAddDevice = 1; if (!granted) { return; } - [self performSegueWithIdentifier:@"LinkDeviceSegue" sender:self]; + [self showLinkNewDeviceView]; }]; } } +- (void)showLinkNewDeviceView +{ + OWSLinkDeviceViewController *vc = [OWSLinkDeviceViewController new]; + vc.linkedDevicesTableViewController = self; + [self.navigationController pushViewController:vc animated:YES]; +} + - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == OWSLinkedDevicesTableViewControllerSectionAddDevice) { - UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AddNewDevice" forIndexPath:indexPath]; + UITableViewCell *cell = + [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"AddNewDevice"]; [OWSTableItem configureCell:cell]; cell.textLabel.text = NSLocalizedString(@"LINK_NEW_DEVICE_TITLE", @"Navigation title when scanning QR code to add new device."); cell.detailTextLabel.text = NSLocalizedString(@"LINK_NEW_DEVICE_SUBTITLE", @"Subheading for 'Link New Device' navigation"); + cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; return cell; } else if (indexPath.section == OWSLinkedDevicesTableViewControllerSectionExistingDevices) { OWSDeviceTableViewCell *cell = @@ -427,14 +437,6 @@ int const OWSLinkedDevicesTableViewControllerSectionAddDevice = 1; }]; } -- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(nullable id)sender -{ - if ([segue.destinationViewController isKindOfClass:[OWSLinkDeviceViewController class]]) { - OWSLinkDeviceViewController *controller = (OWSLinkDeviceViewController *)segue.destinationViewController; - controller.linkedDevicesTableViewController = self; - } -} - @end NS_ASSUME_NONNULL_END diff --git a/Signal/src/ViewControllers/AppSettings/OWSQRCodeScanningViewController.m b/Signal/src/ViewControllers/AppSettings/OWSQRCodeScanningViewController.m index 046221ece..498191187 100644 --- a/Signal/src/ViewControllers/AppSettings/OWSQRCodeScanningViewController.m +++ b/Signal/src/ViewControllers/AppSettings/OWSQRCodeScanningViewController.m @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 Open Whisper Systems. All rights reserved. +// Copyright (c) 2019 Open Whisper Systems. All rights reserved. // #import "OWSQRCodeScanningViewController.h" @@ -93,6 +93,11 @@ NS_ASSUME_NONNULL_BEGIN [self stopCapture]; } +- (void)viewWillLayoutSubviews +{ + self.capture.layer.frame = self.view.bounds; +} + - (void)startCapture { self.captureEnabled = YES; @@ -101,10 +106,10 @@ NS_ASSUME_NONNULL_BEGIN self.capture = [[ZXCapture alloc] init]; self.capture.camera = self.capture.back; self.capture.focusMode = AVCaptureFocusModeContinuousAutoFocus; - self.capture.layer.frame = self.view.bounds; self.capture.delegate = self; dispatch_async(dispatch_get_main_queue(), ^{ + self.capture.layer.frame = self.view.bounds; [self.view.layer addSublayer:self.capture.layer]; [self.view bringSubviewToFront:self.maskingView]; [self.capture start]; diff --git a/Signal/src/views/OWSDeviceTableViewCell.h b/Signal/src/views/OWSDeviceTableViewCell.h index 7dc65759b..12caed02c 100644 --- a/Signal/src/views/OWSDeviceTableViewCell.h +++ b/Signal/src/views/OWSDeviceTableViewCell.h @@ -1,4 +1,6 @@ -// Copyright © 2016 Open Whisper Systems. All rights reserved. +// +// Copyright (c) 2019 Open Whisper Systems. All rights reserved. +// #import #import @@ -7,9 +9,9 @@ NS_ASSUME_NONNULL_BEGIN @interface OWSDeviceTableViewCell : UITableViewCell -@property (strong, nonatomic) IBOutlet UILabel *nameLabel; -@property (strong, nonatomic) IBOutlet UILabel *linkedLabel; -@property (strong, nonatomic) IBOutlet UILabel *lastSeenLabel; +@property (nonatomic) UILabel *nameLabel; +@property (nonatomic) UILabel *linkedLabel; +@property (nonatomic) UILabel *lastSeenLabel; - (void)configureWithDevice:(OWSDevice *)device; diff --git a/Signal/src/views/OWSDeviceTableViewCell.m b/Signal/src/views/OWSDeviceTableViewCell.m index c4d418127..d77355ae5 100644 --- a/Signal/src/views/OWSDeviceTableViewCell.m +++ b/Signal/src/views/OWSDeviceTableViewCell.m @@ -1,22 +1,57 @@ // -// Copyright (c) 2018 Open Whisper Systems. All rights reserved. +// Copyright (c) 2019 Open Whisper Systems. All rights reserved. // #import "OWSDeviceTableViewCell.h" #import "DateUtil.h" #import #import +#import +#import NS_ASSUME_NONNULL_BEGIN @implementation OWSDeviceTableViewCell +- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(nullable NSString *)reuseIdentifier +{ + if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { + [self configure]; + } + return self; +} + +- (void)configure +{ + self.preservesSuperviewLayoutMargins = YES; + self.contentView.preservesSuperviewLayoutMargins = YES; + + self.nameLabel = [UILabel new]; + self.linkedLabel = [UILabel new]; + self.lastSeenLabel = [UILabel new]; + + UIStackView *stackView = [[UIStackView alloc] initWithArrangedSubviews:@[ + self.nameLabel, + self.linkedLabel, + self.lastSeenLabel, + ]]; + stackView.axis = UILayoutConstraintAxisVertical; + stackView.alignment = UIStackViewAlignmentLeading; + stackView.spacing = 2; + [self.contentView addSubview:stackView]; + [stackView ows_autoPinToSuperviewMargins]; +} + - (void)configureWithDevice:(OWSDevice *)device { OWSAssertDebug(device); [OWSTableItem configureCell:self]; + self.nameLabel.font = UIFont.ows_dynamicTypeBodyFont; + self.linkedLabel.font = UIFont.ows_dynamicTypeCaption1Font; + self.lastSeenLabel.font = UIFont.ows_dynamicTypeCaption1Font; + self.nameLabel.textColor = Theme.primaryColor; self.linkedLabel.textColor = Theme.secondaryColor; self.lastSeenLabel.textColor = Theme.secondaryColor;