From 4694ae8458d425e84c6d68067256643d028a184b Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 16 Feb 2017 22:21:57 -0500 Subject: [PATCH 1/5] Ensure "close new conversation view" always works. // FREEBIE --- Signal/src/view controllers/MessageComposeTableViewController.m | 1 + 1 file changed, 1 insertion(+) diff --git a/Signal/src/view controllers/MessageComposeTableViewController.m b/Signal/src/view controllers/MessageComposeTableViewController.m index 1950f5185..d78bbcf65 100644 --- a/Signal/src/view controllers/MessageComposeTableViewController.m +++ b/Signal/src/view controllers/MessageComposeTableViewController.m @@ -730,6 +730,7 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie } - (IBAction)closeAction:(id)sender { + [self.searchController setActive:NO]; [self dismissViewControllerAnimated:YES completion:nil]; } From b8a7204cd1c0457bf0dd5dd4e945ac827d7f49f5 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 16 Feb 2017 22:22:37 -0500 Subject: [PATCH 2/5] Remove "refresh contacts" button; always show "new group conversation" button. // FREEBIE --- .../MessageComposeTableViewController.m | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/Signal/src/view controllers/MessageComposeTableViewController.m b/Signal/src/view controllers/MessageComposeTableViewController.m index d78bbcf65..4cf22557c 100644 --- a/Signal/src/view controllers/MessageComposeTableViewController.m +++ b/Signal/src/view controllers/MessageComposeTableViewController.m @@ -25,7 +25,6 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic) UISearchController *searchController; @property (nonatomic) UIActivityIndicatorView *activityIndicator; -@property (nonatomic) UIBarButtonItem *addGroup; @property (nonatomic) UIView *loadingBackgroundView; @property (nonatomic, copy) NSArray *contacts; @@ -240,35 +239,20 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie - (void)showLoadingBackgroundView:(BOOL)show { if (show && !self.isBackgroundViewHidden) { - _addGroup = self.navigationItem.rightBarButtonItem != nil ? _addGroup : self.navigationItem.rightBarButtonItem; - self.navigationItem.rightBarButtonItem = nil; self.searchController.searchBar.hidden = YES; self.tableView.backgroundView = _loadingBackgroundView; self.refreshControl = nil; self.tableView.backgroundView.opaque = YES; } else { [self initializeRefreshControl]; - self.navigationItem.rightBarButtonItem = - self.navigationItem.rightBarButtonItem != nil ? self.navigationItem.rightBarButtonItem : _addGroup; self.searchController.searchBar.hidden = NO; self.tableView.backgroundView = nil; } } - - (void)showEmptyBackgroundView:(BOOL)show { if (show) { self.refreshControl = nil; - _addGroup = self.navigationItem.rightBarButtonItem != nil ? _addGroup : self.navigationItem.rightBarButtonItem; - self.navigationItem.rightBarButtonItem = - [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"btnRefresh--white"] - imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] - style:UIBarButtonItemStylePlain - target:self - action:@selector(refreshContacts)]; - self.navigationItem.rightBarButtonItem.imageInsets = UIEdgeInsetsMake(8, 8, 8, 8); - - self.inviteCell.hidden = YES; self.searchController.searchBar.hidden = YES; self.tableView.backgroundView = self.noSignalContactsView; @@ -276,8 +260,6 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie } else { [self initializeRefreshControl]; self.refreshControl.enabled = YES; - self.navigationItem.rightBarButtonItem = - self.navigationItem.rightBarButtonItem != nil ? self.navigationItem.rightBarButtonItem : _addGroup; self.searchController.searchBar.hidden = NO; self.tableView.backgroundView = nil; self.inviteCell.hidden = NO; @@ -331,7 +313,6 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie [self.tableView reloadData]; } - #pragma mark - UISearchBarDelegate - (void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope { From ff89d07ddb485a95260ae582a00d6bc20c8a074b Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 16 Feb 2017 22:34:20 -0500 Subject: [PATCH 3/5] Fix presentation animation of "no contacts" mode of new conversation view. // FREEBIE --- .../src/view controllers/MessageComposeTableViewController.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Signal/src/view controllers/MessageComposeTableViewController.m b/Signal/src/view controllers/MessageComposeTableViewController.m index 4cf22557c..3d47f9707 100644 --- a/Signal/src/view controllers/MessageComposeTableViewController.m +++ b/Signal/src/view controllers/MessageComposeTableViewController.m @@ -135,8 +135,8 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie self.title = NSLocalizedString(@"MESSAGE_COMPOSEVIEW_TITLE", @""); } -- (void)viewDidAppear:(BOOL)animated { - [super viewDidAppear:animated]; +- (void)viewWillAppear:(BOOL)animated { + [super viewWillAppear:animated]; if ([self.contacts count] == 0) { [self showEmptyBackgroundView:YES]; From 47ae6ccf76fdd9acc4a61fa93a6ffc322fafedd7 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 16 Feb 2017 22:47:12 -0500 Subject: [PATCH 4/5] Don't show the "no contacts" mode of new conversation view again after it has been dismissed. // FREEBIE --- .../src/environment/PropertyListPreferences.h | 3 ++ .../src/environment/PropertyListPreferences.m | 13 +++++ .../MessageComposeTableViewController.m | 47 ++++++++++--------- 3 files changed, 41 insertions(+), 22 deletions(-) diff --git a/Signal/src/environment/PropertyListPreferences.h b/Signal/src/environment/PropertyListPreferences.h index b5590634d..d43d84977 100644 --- a/Signal/src/environment/PropertyListPreferences.h +++ b/Signal/src/environment/PropertyListPreferences.h @@ -55,6 +55,9 @@ extern NSString *const PropertyListPreferencesKeyEnableDebugLog; + (nullable NSString *)lastRanVersion; + (NSString *)setAndGetCurrentVersion; +- (BOOL)hasDeclinedNoContactsView; +- (void)setHasDeclinedNoContactsView:(BOOL)value; + #pragma mark - Calling #pragma mark Callkit diff --git a/Signal/src/environment/PropertyListPreferences.m b/Signal/src/environment/PropertyListPreferences.m index fe5689286..e2f628bc7 100644 --- a/Signal/src/environment/PropertyListPreferences.m +++ b/Signal/src/environment/PropertyListPreferences.m @@ -25,6 +25,7 @@ NSString *const PropertyListPreferencesKeyLastRecordedVoipToken = @"LastRecorded NSString *const PropertyListPreferencesKeyCallKitEnabled = @"CallKitEnabled"; NSString *const PropertyListPreferencesKeyCallKitPrivacyEnabled = @"CallKitPrivacyEnabled"; NSString *const PropertyListPreferencesKeyCallsHideIPAddress = @"CallsHideIPAddress"; +NSString *const PropertyListPreferencesKeyHasDeclinedNoContactsView = @"hasDeclinedNoContactsView"; @implementation PropertyListPreferences @@ -166,6 +167,18 @@ NSString *const PropertyListPreferencesKeyCallsHideIPAddress = @"CallsHideIPAddr return currentVersion; } +- (BOOL)hasDeclinedNoContactsView +{ + NSNumber *preference = [self tryGetValueForKey:PropertyListPreferencesKeyHasDeclinedNoContactsView]; + // Default to NO. + return preference ? [preference boolValue] : NO; +} + +- (void)setHasDeclinedNoContactsView:(BOOL)value +{ + [self setValueForKey:PropertyListPreferencesKeyHasDeclinedNoContactsView toValue:@(value)]; +} + #pragma mark - Calling #pragma mark CallKit diff --git a/Signal/src/view controllers/MessageComposeTableViewController.m b/Signal/src/view controllers/MessageComposeTableViewController.m index 3d47f9707..65d7bddd3 100644 --- a/Signal/src/view controllers/MessageComposeTableViewController.m +++ b/Signal/src/view controllers/MessageComposeTableViewController.m @@ -41,7 +41,7 @@ NS_ASSUME_NONNULL_BEGIN // which are known to correspond to Signal accounts. @property (nonatomic, nonnull, readonly) NSMutableSet *phoneNumberAccountSet; -@property (nonatomic) BOOL isBackgroundViewHidden; +@property (nonatomic) BOOL isNoContactsViewVisible; @end @@ -138,9 +138,7 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; - if ([self.contacts count] == 0) { - [self showEmptyBackgroundView:YES]; - } + [self showEmptyBackgroundViewIfNecessary]; } - (UILabel *)createLabelWithFirstLine:(NSString *)firstLine andSecondLine:(NSString *)secondLine { @@ -225,9 +223,10 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie } - (void)hideBackgroundView { - self.isBackgroundViewHidden = YES; + [[Environment preferences] setHasDeclinedNoContactsView:YES]; - [self showEmptyBackgroundView:NO]; +// [self showEmptyBackgroundView:NO]; + [self showEmptyBackgroundViewIfNecessary]; } - (void)presentInviteFlow @@ -238,7 +237,7 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie } - (void)showLoadingBackgroundView:(BOOL)show { - if (show && !self.isBackgroundViewHidden) { + if (show) { self.searchController.searchBar.hidden = YES; self.tableView.backgroundView = _loadingBackgroundView; self.refreshControl = nil; @@ -250,10 +249,20 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie } } -- (void)showEmptyBackgroundView:(BOOL)show { - if (show) { +- (void)showEmptyBackgroundViewIfNecessary { + self.isNoContactsViewVisible = ([self.contacts count] == 0 && + ![[Environment preferences] hasDeclinedNoContactsView]); +} + +- (void)setIsNoContactsViewVisible:(BOOL)isNoContactsViewVisible { + if (isNoContactsViewVisible == _isNoContactsViewVisible) { + return; + } + + _isNoContactsViewVisible = isNoContactsViewVisible; + + if (isNoContactsViewVisible) { self.refreshControl = nil; - self.inviteCell.hidden = YES; self.searchController.searchBar.hidden = YES; self.tableView.backgroundView = self.noSignalContactsView; self.tableView.backgroundView.opaque = YES; @@ -262,12 +271,9 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie self.refreshControl.enabled = YES; self.searchController.searchBar.hidden = NO; self.tableView.backgroundView = nil; - self.inviteCell.hidden = NO; } - for (UITableViewCell *cell in self.tableView.visibleCells) { - cell.hidden = show; - } + [self.tableView reloadData]; } #pragma mark - Initializers @@ -514,7 +520,9 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie #pragma mark - Table View Data Source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { - return MessageComposeTableViewControllerSection_Count; + return (self.isNoContactsViewVisible + ? 0 + : MessageComposeTableViewControllerSection_Count); } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { @@ -577,14 +585,12 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie phoneNumber]; return inviteViaSMSCell; } else if (indexPath.section == MessageComposeTableViewControllerSectionInviteFlow) { - self.inviteCell.hidden = NO; return self.inviteCell; } else { OWSAssert(indexPath.section == MessageComposeTableViewControllerSectionContacts) ContactTableViewCell *cell = (ContactTableViewCell *)[tableView dequeueReusableCellWithIdentifier:MessageComposeTableViewControllerCellContact]; - cell.hidden = NO; [cell configureWithContact:[self contactForIndexPath:indexPath] contactsManager:self.contactsManager]; @@ -664,11 +670,8 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie [self.refreshControl endRefreshing]; [self showLoadingBackgroundView:NO]; - if ([self.contacts count] == 0) { - [self showEmptyBackgroundView:YES]; - } else { - [self showEmptyBackgroundView:NO]; - } + + [self showEmptyBackgroundViewIfNecessary]; } - (void)refreshContacts { From 0dfe020997fdd736cae84f5d07a7e09083a11689 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 28 Mar 2017 16:40:00 -0400 Subject: [PATCH 5/5] Hide new group button if user has no contacts. // FREEBIE --- .../view controllers/MessageComposeTableViewController.m | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Signal/src/view controllers/MessageComposeTableViewController.m b/Signal/src/view controllers/MessageComposeTableViewController.m index 65d7bddd3..26f87ef0d 100644 --- a/Signal/src/view controllers/MessageComposeTableViewController.m +++ b/Signal/src/view controllers/MessageComposeTableViewController.m @@ -42,6 +42,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, nonnull, readonly) NSMutableSet *phoneNumberAccountSet; @property (nonatomic) BOOL isNoContactsViewVisible; +@property (nonatomic) UIBarButtonItem *createGroupBarButtonItem; @end @@ -114,7 +115,8 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie - (void)viewDidLoad { [super viewDidLoad]; [self.navigationController.navigationBar setTranslucent:NO]; - + + self.createGroupBarButtonItem = self.navigationItem.rightBarButtonItem; self.navigationItem.rightBarButtonItem.accessibilityLabel = NSLocalizedString( @"CREATE_NEW_GROUP", @"Accessibility label for the create group new group button"); @@ -225,7 +227,6 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie - (void)hideBackgroundView { [[Environment preferences] setHasDeclinedNoContactsView:YES]; -// [self showEmptyBackgroundView:NO]; [self showEmptyBackgroundViewIfNecessary]; } @@ -266,13 +267,15 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie self.searchController.searchBar.hidden = YES; self.tableView.backgroundView = self.noSignalContactsView; self.tableView.backgroundView.opaque = YES; + self.navigationItem.rightBarButtonItem = nil; } else { [self initializeRefreshControl]; self.refreshControl.enabled = YES; self.searchController.searchBar.hidden = NO; self.tableView.backgroundView = nil; + self.navigationItem.rightBarButtonItem = self.createGroupBarButtonItem; } - + [self.tableView reloadData]; }