diff --git a/Signal/src/ViewControllers/SignalsViewController.m b/Signal/src/ViewControllers/SignalsViewController.m index 7377df5b0..2fac986ca 100644 --- a/Signal/src/ViewControllers/SignalsViewController.m +++ b/Signal/src/ViewControllers/SignalsViewController.m @@ -59,8 +59,8 @@ // Views -@property (weak, nonatomic) ReminderView *missingContactsPermissionView; -@property (weak, nonatomic) NSLayoutConstraint *hideMissingContactsPermissionViewConstraint; +@property (nonatomic) NSLayoutConstraint *hideArchiveReminderViewConstraint; +@property (nonatomic) NSLayoutConstraint *hideMissingContactsPermissionViewConstraint; @property (nonatomic) TSThread *lastThread; @@ -166,13 +166,31 @@ target:self action:@selector(composeNew)]; + ReminderView *archiveReminderView = [ReminderView new]; + archiveReminderView.text = NSLocalizedString( + @"INBOX_VIEW_ARCHIVE_MODE_REMINDER", @"Label reminding the user that they are in archive mode."); + __weak SignalsViewController *weakSelf = self; + archiveReminderView.tapAction = ^{ + [weakSelf selectedInbox]; + }; + [self.view addSubview:archiveReminderView]; + [archiveReminderView autoPinWidthToSuperview]; + [archiveReminderView autoPinToTopLayoutGuideOfViewController:self withInset:0]; + self.hideArchiveReminderViewConstraint = [archiveReminderView autoSetDimension:ALDimensionHeight toSize:0]; + self.hideArchiveReminderViewConstraint.priority = UILayoutPriorityRequired; + ReminderView *missingContactsPermissionView = [ReminderView new]; - self.missingContactsPermissionView = missingContactsPermissionView; + missingContactsPermissionView.text = NSLocalizedString(@"INBOX_VIEW_MISSING_CONTACTS_PERMISSION", + @"Multiline label explaining how to show names instead of phone numbers in your inbox"); + missingContactsPermissionView.tapAction = ^{ + [[UIApplication sharedApplication] openSystemSettings]; + }; [self.view addSubview:missingContactsPermissionView]; [missingContactsPermissionView autoPinWidthToSuperview]; - [missingContactsPermissionView autoPinToTopLayoutGuideOfViewController:self withInset:0]; + [missingContactsPermissionView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:archiveReminderView]; self.hideMissingContactsPermissionViewConstraint = [missingContactsPermissionView autoSetDimension:ALDimensionHeight toSize:0]; + self.hideMissingContactsPermissionViewConstraint.priority = UILayoutPriorityRequired; self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]; self.tableView.delegate = self; @@ -189,19 +207,21 @@ [emptyBoxLabel autoPinToTopLayoutGuideOfViewController:self withInset:0]; [emptyBoxLabel autoPinToBottomLayoutGuideOfViewController:self withInset:0]; - [self updateReminderView]; -} - -- (void)viewDidLayoutSubviews -{ - [super viewDidLayoutSubviews]; - - DDLogError(@"self.tableView: %@", NSStringFromCGRect(self.tableView.frame)); + [self updateReminderViews]; } -- (void)updateReminderView +- (void)updateReminderViews { - self.hideMissingContactsPermissionViewConstraint.active = !self.shouldShowMissingContactsPermissionView; + BOOL shouldHideArchiveReminderView = self.viewingThreadsIn != kArchiveState; + BOOL shouldHideMissingContactsPermissionView = !self.shouldShowMissingContactsPermissionView; + if (self.hideArchiveReminderViewConstraint.active == shouldHideArchiveReminderView + && self.hideMissingContactsPermissionViewConstraint.active == shouldHideMissingContactsPermissionView) { + return; + } + self.hideArchiveReminderViewConstraint.active = shouldHideArchiveReminderView; + self.hideMissingContactsPermissionViewConstraint.active = shouldHideMissingContactsPermissionView; + [self.view setNeedsLayout]; + [self.view layoutSubviews]; } - (void)viewDidLoad { @@ -215,7 +235,7 @@ // Create the database connection. [self uiDatabaseConnection]; - [self selectedInbox:self]; + [self selectedInbox]; self.segmentedControl = [[UISegmentedControl alloc] initWithItems:@[ NSLocalizedString(@"WHISPER_NAV_BAR_TITLE", nil), @@ -231,13 +251,6 @@ navigationItem.leftBarButtonItem.accessibilityLabel = NSLocalizedString( @"SETTINGS_BUTTON_ACCESSIBILITY", @"Accessibility hint for the settings button"); - - self.missingContactsPermissionView.text = NSLocalizedString(@"INBOX_VIEW_MISSING_CONTACTS_PERMISSION", - @"Multiline label explaining how to show names instead of phone numbers in your inbox"); - self.missingContactsPermissionView.tapAction = ^{ - [[UIApplication sharedApplication] openSystemSettings]; - }; - if ([self.traitCollection respondsToSelector:@selector(forceTouchCapability)] && (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable)) { [self registerForPreviewingWithDelegate:self sourceView:self.tableView]; @@ -332,9 +345,9 @@ - (void)swappedSegmentedControl { if (self.segmentedControl.selectedSegmentIndex == 0) { - [self selectedInbox:nil]; + [self selectedInbox]; } else { - [self selectedArchive:nil]; + [self selectedArchive]; } } @@ -343,7 +356,7 @@ if ([TSThread numberOfKeysInCollection] > 0) { [self.contactsManager requestSystemContactsOnceWithCompletion:^(NSError *_Nullable error) { dispatch_async(dispatch_get_main_queue(), ^{ - [self updateReminderView]; + [self updateReminderViews]; }); }]; } @@ -773,14 +786,16 @@ #pragma mark - Groupings -- (void)selectedInbox:(id)sender +- (void)selectedInbox { + self.segmentedControl.selectedSegmentIndex = 0; self.viewingThreadsIn = kInboxState; [self changeToGrouping:TSInboxGroup]; } -- (void)selectedArchive:(id)sender +- (void)selectedArchive { + self.segmentedControl.selectedSegmentIndex = 1; self.viewingThreadsIn = kArchiveState; [self changeToGrouping:TSArchiveGroup]; } @@ -797,6 +812,7 @@ [self updateShouldObserveDBModifications]; [self checkIfEmptyView]; + [self updateReminderViews]; } #pragma mark Database delegates diff --git a/Signal/src/views/ReminderView.swift b/Signal/src/views/ReminderView.swift index dc48fd02d..906459006 100644 --- a/Signal/src/views/ReminderView.swift +++ b/Signal/src/views/ReminderView.swift @@ -51,10 +51,10 @@ class ReminderView: UIView { self.backgroundColor = UIColor.ows_reminderYellow() self.clipsToBounds = true - let container = UIView() - let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTap(gestureRecognizer:))) - container.addGestureRecognizer(tapGesture) + self.addGestureRecognizer(tapGesture) + + let container = UIView() self.addSubview(container) container.autoPinWidthToSuperview(withMargin: 16) diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index c8072fb2f..162afb032 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -643,6 +643,9 @@ /* Call setup status label */ "IN_CALL_TERMINATED" = "Call Ended."; +/* Label reminding the user that they are in archive mode. */ +"INBOX_VIEW_ARCHIVE_MODE_REMINDER" = "You're in archive mode. Tap to return to your Inbox."; + /* Multiline label explaining how to show names instead of phone numbers in your inbox */ "INBOX_VIEW_MISSING_CONTACTS_PERMISSION" = "To see the names of your contacts, update your system settings to allow contact access.";