Don't show the "no contacts" mode of new conversation view again after it has been dismissed.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent ff89d07ddb
commit 47ae6ccf76

@ -55,6 +55,9 @@ extern NSString *const PropertyListPreferencesKeyEnableDebugLog;
+ (nullable NSString *)lastRanVersion; + (nullable NSString *)lastRanVersion;
+ (NSString *)setAndGetCurrentVersion; + (NSString *)setAndGetCurrentVersion;
- (BOOL)hasDeclinedNoContactsView;
- (void)setHasDeclinedNoContactsView:(BOOL)value;
#pragma mark - Calling #pragma mark - Calling
#pragma mark Callkit #pragma mark Callkit

@ -25,6 +25,7 @@ NSString *const PropertyListPreferencesKeyLastRecordedVoipToken = @"LastRecorded
NSString *const PropertyListPreferencesKeyCallKitEnabled = @"CallKitEnabled"; NSString *const PropertyListPreferencesKeyCallKitEnabled = @"CallKitEnabled";
NSString *const PropertyListPreferencesKeyCallKitPrivacyEnabled = @"CallKitPrivacyEnabled"; NSString *const PropertyListPreferencesKeyCallKitPrivacyEnabled = @"CallKitPrivacyEnabled";
NSString *const PropertyListPreferencesKeyCallsHideIPAddress = @"CallsHideIPAddress"; NSString *const PropertyListPreferencesKeyCallsHideIPAddress = @"CallsHideIPAddress";
NSString *const PropertyListPreferencesKeyHasDeclinedNoContactsView = @"hasDeclinedNoContactsView";
@implementation PropertyListPreferences @implementation PropertyListPreferences
@ -166,6 +167,18 @@ NSString *const PropertyListPreferencesKeyCallsHideIPAddress = @"CallsHideIPAddr
return currentVersion; 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 - Calling
#pragma mark CallKit #pragma mark CallKit

@ -41,7 +41,7 @@ NS_ASSUME_NONNULL_BEGIN
// which are known to correspond to Signal accounts. // which are known to correspond to Signal accounts.
@property (nonatomic, nonnull, readonly) NSMutableSet *phoneNumberAccountSet; @property (nonatomic, nonnull, readonly) NSMutableSet *phoneNumberAccountSet;
@property (nonatomic) BOOL isBackgroundViewHidden; @property (nonatomic) BOOL isNoContactsViewVisible;
@end @end
@ -138,9 +138,7 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie
- (void)viewWillAppear:(BOOL)animated { - (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated]; [super viewWillAppear:animated];
if ([self.contacts count] == 0) { [self showEmptyBackgroundViewIfNecessary];
[self showEmptyBackgroundView:YES];
}
} }
- (UILabel *)createLabelWithFirstLine:(NSString *)firstLine andSecondLine:(NSString *)secondLine { - (UILabel *)createLabelWithFirstLine:(NSString *)firstLine andSecondLine:(NSString *)secondLine {
@ -225,9 +223,10 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie
} }
- (void)hideBackgroundView { - (void)hideBackgroundView {
self.isBackgroundViewHidden = YES; [[Environment preferences] setHasDeclinedNoContactsView:YES];
[self showEmptyBackgroundView:NO]; // [self showEmptyBackgroundView:NO];
[self showEmptyBackgroundViewIfNecessary];
} }
- (void)presentInviteFlow - (void)presentInviteFlow
@ -238,7 +237,7 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie
} }
- (void)showLoadingBackgroundView:(BOOL)show { - (void)showLoadingBackgroundView:(BOOL)show {
if (show && !self.isBackgroundViewHidden) { if (show) {
self.searchController.searchBar.hidden = YES; self.searchController.searchBar.hidden = YES;
self.tableView.backgroundView = _loadingBackgroundView; self.tableView.backgroundView = _loadingBackgroundView;
self.refreshControl = nil; self.refreshControl = nil;
@ -250,10 +249,20 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie
} }
} }
- (void)showEmptyBackgroundView:(BOOL)show { - (void)showEmptyBackgroundViewIfNecessary {
if (show) { 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.refreshControl = nil;
self.inviteCell.hidden = YES;
self.searchController.searchBar.hidden = YES; self.searchController.searchBar.hidden = YES;
self.tableView.backgroundView = self.noSignalContactsView; self.tableView.backgroundView = self.noSignalContactsView;
self.tableView.backgroundView.opaque = YES; self.tableView.backgroundView.opaque = YES;
@ -262,12 +271,9 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie
self.refreshControl.enabled = YES; self.refreshControl.enabled = YES;
self.searchController.searchBar.hidden = NO; self.searchController.searchBar.hidden = NO;
self.tableView.backgroundView = nil; self.tableView.backgroundView = nil;
self.inviteCell.hidden = NO;
} }
for (UITableViewCell *cell in self.tableView.visibleCells) { [self.tableView reloadData];
cell.hidden = show;
}
} }
#pragma mark - Initializers #pragma mark - Initializers
@ -514,7 +520,9 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie
#pragma mark - Table View Data Source #pragma mark - Table View Data Source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return MessageComposeTableViewControllerSection_Count; return (self.isNoContactsViewVisible
? 0
: MessageComposeTableViewControllerSection_Count);
} }
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
@ -577,14 +585,12 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie
phoneNumber]; phoneNumber];
return inviteViaSMSCell; return inviteViaSMSCell;
} else if (indexPath.section == MessageComposeTableViewControllerSectionInviteFlow) { } else if (indexPath.section == MessageComposeTableViewControllerSectionInviteFlow) {
self.inviteCell.hidden = NO;
return self.inviteCell; return self.inviteCell;
} else { } else {
OWSAssert(indexPath.section == MessageComposeTableViewControllerSectionContacts) OWSAssert(indexPath.section == MessageComposeTableViewControllerSectionContacts)
ContactTableViewCell *cell = (ContactTableViewCell *)[tableView ContactTableViewCell *cell = (ContactTableViewCell *)[tableView
dequeueReusableCellWithIdentifier:MessageComposeTableViewControllerCellContact]; dequeueReusableCellWithIdentifier:MessageComposeTableViewControllerCellContact];
cell.hidden = NO;
[cell configureWithContact:[self contactForIndexPath:indexPath] contactsManager:self.contactsManager]; [cell configureWithContact:[self contactForIndexPath:indexPath] contactsManager:self.contactsManager];
@ -664,11 +670,8 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie
[self.refreshControl endRefreshing]; [self.refreshControl endRefreshing];
[self showLoadingBackgroundView:NO]; [self showLoadingBackgroundView:NO];
if ([self.contacts count] == 0) {
[self showEmptyBackgroundView:YES]; [self showEmptyBackgroundViewIfNecessary];
} else {
[self showEmptyBackgroundView:NO];
}
} }
- (void)refreshContacts { - (void)refreshContacts {

Loading…
Cancel
Save