session-ios/Signal/src/view controllers/MessageComposeTableViewCont...

570 lines
24 KiB
Mathematica
Raw Normal View History

2014-10-29 21:58:58 +01:00
//
// MessageComposeTableViewController.m
2015-04-30 15:03:57 +02:00
//
2014-10-29 21:58:58 +01:00
//
// Created by Dylan Bourgeois on 02/11/14.
//
//
#import "MessageComposeTableViewController.h"
#import <MessageUI/MessageUI.h>
2014-10-29 21:58:58 +01:00
#import "ContactTableViewCell.h"
#import "ContactsUpdater.h"
#import "Environment.h"
#import "OWSContactsSearcher.h"
#import "Signal-Swift.h"
#import "UIColor+OWS.h"
#import "UIUtil.h"
2014-10-29 21:58:58 +01:00
NS_ASSUME_NONNULL_BEGIN
@interface MessageComposeTableViewController () <UISearchBarDelegate,
UISearchResultsUpdating,
2016-06-28 06:36:42 +02:00
MFMessageComposeViewControllerDelegate>
2014-10-29 21:58:58 +01:00
@property (nonatomic, strong) IBOutlet UITableViewCell *inviteCell;
2016-06-28 06:36:42 +02:00
@property (nonatomic) UIButton *sendTextButton;
2014-10-29 21:58:58 +01:00
@property (nonatomic, strong) UISearchController *searchController;
@property (nonatomic, strong) UIActivityIndicatorView *activityIndicator;
@property (nonatomic, strong) UIBarButtonItem *addGroup;
@property (nonatomic, strong) UIView *loadingBackgroundView;
@property (nonatomic, strong) UIView *emptyBackgroundView;
2016-06-28 06:36:42 +02:00
@property (nonatomic) NSString *currentSearchTerm;
@property (copy) NSArray<Contact *> *contacts;
2016-06-28 06:36:42 +02:00
@property (copy) NSArray<Contact *> *searchResults;
@property (nonatomic, readonly) OWSContactsManager *contactsManager;
2014-10-29 21:58:58 +01:00
@end
NSInteger const MessageComposeTableViewControllerSectionInvite = 0;
NSInteger const MessageComposeTableViewControllerSectionContacts = 1;
NSString *const MessageComposeTableViewControllerCellInvite = @"ContactTableInviteCell";
NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableViewCell";
2014-10-29 21:58:58 +01:00
@implementation MessageComposeTableViewController
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (!self) {
return self;
}
_contactsManager = [Environment getCurrent].contactsManager;
return self;
}
- (instancetype)init
{
self = [super init];
if (!self) {
return self;
}
_contactsManager = [Environment getCurrent].contactsManager;
return self;
}
2014-10-29 21:58:58 +01:00
- (void)viewDidLoad {
[super viewDidLoad];
2015-04-30 15:03:57 +02:00
[self.navigationController.navigationBar setTranslucent:NO];
self.tableView.estimatedRowHeight = (CGFloat)60.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.contacts = self.contactsManager.signalContacts;
2016-06-28 06:36:42 +02:00
self.searchResults = self.contacts;
[self initializeSearch];
self.searchController.searchBar.hidden = NO;
2015-02-12 23:52:49 +01:00
self.searchController.searchBar.backgroundColor = [UIColor whiteColor];
self.inviteCell.textLabel.text = NSLocalizedString(
@"INVITE_FRIENDS_CONTACT_TABLE_BUTTON", @"Text for button at the top of the contact picker");
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
[self createLoadingAndBackgroundViews];
self.title = NSLocalizedString(@"MESSAGE_COMPOSEVIEW_TITLE", @"");
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
2016-06-28 06:36:42 +02:00
if ([self.contacts count] == 0) {
[self showEmptyBackgroundView:YES];
}
}
- (UILabel *)createLabelWithFirstLine:(NSString *)firstLine andSecondLine:(NSString *)secondLine {
UILabel *label = [[UILabel alloc] init];
label.textColor = [UIColor grayColor];
label.font = [UIFont ows_regularFontWithSize:18.f];
label.textAlignment = NSTextAlignmentCenter;
label.numberOfLines = 4;
NSMutableAttributedString *fullLabelString =
[[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@\n%@", firstLine, secondLine]];
[fullLabelString addAttribute:NSFontAttributeName
value:[UIFont ows_boldFontWithSize:15.f]
range:NSMakeRange(0, firstLine.length)];
[fullLabelString addAttribute:NSFontAttributeName
value:[UIFont ows_regularFontWithSize:14.f]
range:NSMakeRange(firstLine.length + 1, secondLine.length)];
[fullLabelString addAttribute:NSForegroundColorAttributeName
value:[UIColor blackColor]
range:NSMakeRange(0, firstLine.length)];
[fullLabelString addAttribute:NSForegroundColorAttributeName
value:[UIColor ows_darkGrayColor]
range:NSMakeRange(firstLine.length + 1, secondLine.length)];
label.attributedText = fullLabelString;
// 250, 66, 140
[label setFrame:CGRectMake([self marginSize], 100 + 140, [self contentWidth], 66)];
return label;
}
2014-10-29 21:58:58 +01:00
- (UIButton *)createButtonWithTitle:(NSString *)title {
NSDictionary *buttonTextAttributes = @{
NSFontAttributeName : [UIFont ows_regularFontWithSize:15.0f],
NSForegroundColorAttributeName : [UIColor ows_materialBlueColor]
};
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 65, 24)];
NSMutableAttributedString *attributedTitle = [[NSMutableAttributedString alloc] initWithString:title];
[attributedTitle setAttributes:buttonTextAttributes range:NSMakeRange(0, [attributedTitle length])];
[button setAttributedTitle:attributedTitle forState:UIControlStateNormal];
[button.titleLabel setTextAlignment:NSTextAlignmentCenter];
return button;
}
- (void)createLoadingAndBackgroundViews {
// This will be further tweaked per design recs. It must currently be hardcoded (or we can place in separate .xib I
// suppose) as the controller must be a TableViewController to have access to the native pull to refresh
// capabilities. That means we can't do a UIView in the storyboard
_loadingBackgroundView = [[UIView alloc] initWithFrame:self.tableView.frame];
UIImageView *loadingImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"uiEmpty"]];
[loadingImageView setBackgroundColor:[UIColor whiteColor]];
[loadingImageView setContentMode:UIViewContentModeCenter];
[loadingImageView setFrame:CGRectMake(self.tableView.frame.size.width / 2.0f - 115.0f / 2.0f, 100, 115, 110)];
loadingImageView.contentMode = UIViewContentModeCenter;
loadingImageView.contentMode = UIViewContentModeScaleAspectFit;
UIActivityIndicatorView *loadingProgressView =
[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[loadingProgressView
setFrame:CGRectMake(self.tableView.frame.size.width / 2.0f - loadingProgressView.frame.size.width / 2.0f,
100 + 110 / 2.0f - loadingProgressView.frame.size.height / 2.0f,
loadingProgressView.frame.size.width,
loadingProgressView.frame.size.height)];
[loadingProgressView setHidesWhenStopped:NO];
[loadingProgressView startAnimating];
UILabel *loadingLabel = [self createLabelWithFirstLine:NSLocalizedString(@"LOADING_CONTACTS_LABEL_LINE1", @"")
andSecondLine:NSLocalizedString(@"LOADING_CONTACTS_LABEL_LINE2", @"")];
[_loadingBackgroundView addSubview:loadingImageView];
[_loadingBackgroundView addSubview:loadingProgressView];
[_loadingBackgroundView addSubview:loadingLabel];
_emptyBackgroundView = [[UIView alloc] initWithFrame:self.tableView.frame];
UIImageView *emptyImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"uiEmptyContact"]];
[emptyImageView setBackgroundColor:[UIColor whiteColor]];
[emptyImageView setContentMode:UIViewContentModeCenter];
[emptyImageView setFrame:CGRectMake(self.tableView.frame.size.width / 2.0f - 115.0f / 2.0f, 100, 115, 110)];
emptyImageView.contentMode = UIViewContentModeCenter;
emptyImageView.contentMode = UIViewContentModeScaleAspectFit;
UILabel *emptyLabel = [self createLabelWithFirstLine:NSLocalizedString(@"EMPTY_CONTACTS_LABEL_LINE1", @"")
andSecondLine:NSLocalizedString(@"EMPTY_CONTACTS_LABEL_LINE2", @"")];
UIButton *inviteContactButton =
[self createButtonWithTitle:NSLocalizedString(@"EMPTY_CONTACTS_INVITE_BUTTON", @"")];
[inviteContactButton addTarget:self action:@selector(sendText) forControlEvents:UIControlEventTouchUpInside];
[inviteContactButton
setFrame:CGRectMake([self marginSize], self.tableView.frame.size.height - 200, [self contentWidth], 60)];
[inviteContactButton.titleLabel setTextAlignment:NSTextAlignmentCenter];
[_emptyBackgroundView addSubview:emptyImageView];
[_emptyBackgroundView addSubview:emptyLabel];
[_emptyBackgroundView addSubview:inviteContactButton];
2014-10-29 21:58:58 +01:00
}
- (void)showLoadingBackgroundView:(BOOL)show {
if (show) {
_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.searchController.searchBar.hidden = YES;
self.tableView.backgroundView = _emptyBackgroundView;
self.tableView.backgroundView.opaque = YES;
} 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;
}
2014-10-29 21:58:58 +01:00
}
#pragma mark - Initializers
- (void)initializeSearch {
2014-10-29 21:58:58 +01:00
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
2014-10-29 21:58:58 +01:00
self.searchController.searchResultsUpdater = self;
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.hidesNavigationBarDuringPresentation = NO;
self.searchController.searchBar.frame = CGRectMake(self.searchController.searchBar.frame.origin.x,
self.searchController.searchBar.frame.origin.y,
self.searchController.searchBar.frame.size.width,
44.0);
2014-10-29 21:58:58 +01:00
self.tableView.tableHeaderView = self.searchController.searchBar;
2014-10-29 21:58:58 +01:00
self.searchController.searchBar.searchBarStyle = UISearchBarStyleMinimal;
self.searchController.searchBar.delegate = self;
self.searchController.searchBar.placeholder = NSLocalizedString(@"SEARCH_BYNAMEORNUMBER_PLACEHOLDER_TEXT", @"");
2016-06-28 06:36:42 +02:00
self.sendTextButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[self.sendTextButton setBackgroundColor:[UIColor ows_materialBlueColor]];
[self.sendTextButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
self.sendTextButton.frame = CGRectMake(self.searchController.searchBar.frame.origin.x,
Disappearing Messages * Per thread settings menu accessed by tapping on thread title This removed the toggle-phone behavior. You'll be able to see the phone number in the settings table view. This removed the "add contact" functionality, although it was already broken for ios>=9 (which is basically everybody). The group actions menu was absorbed into this screen * Added a confirm alert to leave group (fixes #938) * New Translation Strings * Extend "Add People" label to fit translations. * resolved issues with translations not fitting in group menu * Fix the long standing type warning where TSCalls were assigned to a TSMessageAdapter. * Can delete info messages Follow the JSQMVC pattern and put UIResponder-able content in the messageBubbleContainer. This gives us more functionality *and* allows us to delete some code. yay! It's still not yet possible to delete phone messages. =( * Fixed some compiler warnings. * xcode8 touching storyboard. So long xcode7! * Fixup multiline info messages. We were seeing info messages like "You set disappearing message timer to 10" instead of "You set disappearing message timer to 10 seconds." Admittedly this isn't a very good fix, as now one liners feel like they have too much padding. If the message is well over one line, we were wrapping properly, but there's a problem when the message is *just barely* two lines, the cell height grows, but the label still thinks it's just one line (as evinced by the one line appearing in the center of the label frame. The result being that the last word of the label is cropped. * Disable group actions after leaving group. // FREEBIE
2016-09-21 14:37:51 +02:00
self.searchController.searchBar.frame.origin.y + 44.0f,
self.searchController.searchBar.frame.size.width,
44.0);
2016-06-28 06:36:42 +02:00
[self.view addSubview:self.sendTextButton];
self.sendTextButton.hidden = YES;
[self.sendTextButton addTarget:self action:@selector(sendText) forControlEvents:UIControlEventTouchUpInside];
[self initializeRefreshControl];
}
- (void)initializeRefreshControl {
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:@selector(refreshContacts) forControlEvents:UIControlEventValueChanged];
self.refreshControl = refreshControl;
[self.tableView addSubview:self.refreshControl];
2014-10-29 21:58:58 +01:00
}
#pragma mark - UISearchResultsUpdating
- (void)updateSearchResultsForSearchController:(UISearchController *)searchController {
2014-10-29 21:58:58 +01:00
NSString *searchString = [self.searchController.searchBar text];
[self filterContentForSearchText:searchString];
2014-10-29 21:58:58 +01:00
[self.tableView reloadData];
}
#pragma mark - UISearchBarDelegate
- (void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope {
[self updateSearchResultsForSearchController:self.searchController];
}
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
2016-06-28 06:36:42 +02:00
self.sendTextButton.hidden = YES;
2014-10-29 21:58:58 +01:00
}
#pragma mark - Filter
- (void)filterContentForSearchText:(NSString *)searchText
{
OWSContactsSearcher *contactsSearcher = [[OWSContactsSearcher alloc] initWithContacts: self.contacts];
self.searchResults = [contactsSearcher filterWithString:searchText];
NSString *formattedNumber = [PhoneNumber tryParsePhoneNumberFromUserSpecifiedText:searchText].toE164;
// text to a non-signal number if we have no results and a valid phone #
2016-06-28 06:36:42 +02:00
if (self.searchResults.count == 0 && searchText.length > 8 && formattedNumber) {
NSString *sendTextTo = NSLocalizedString(@"SEND_SMS_BUTTON", @"");
sendTextTo = [sendTextTo stringByAppendingString:formattedNumber];
2016-06-28 06:36:42 +02:00
[self.sendTextButton setTitle:sendTextTo forState:UIControlStateNormal];
self.sendTextButton.hidden = NO;
self.currentSearchTerm = formattedNumber;
} else {
2016-06-28 06:36:42 +02:00
self.sendTextButton.hidden = YES;
}
2014-10-29 21:58:58 +01:00
}
#pragma mark - Send Normal Text to Unknown Contact
- (void)sendText {
NSString *confirmMessage = NSLocalizedString(@"SEND_SMS_CONFIRM_TITLE", @"");
2016-06-28 06:36:42 +02:00
if ([self.currentSearchTerm length] > 0) {
confirmMessage = NSLocalizedString(@"SEND_SMS_INVITE_TITLE", @"");
2016-06-28 06:36:42 +02:00
confirmMessage = [confirmMessage stringByAppendingString:self.currentSearchTerm];
confirmMessage = [confirmMessage stringByAppendingString:NSLocalizedString(@"QUESTIONMARK_PUNCTUATION", @"")];
}
UIAlertController *alertController =
[UIAlertController alertControllerWithTitle:NSLocalizedString(@"CONFIRMATION_TITLE", @"")
message:confirmMessage
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"TXT_CANCEL_TITLE", @"")
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *action) {
DDLogDebug(@"Cancel action");
}];
UIAlertAction *okAction = [UIAlertAction
actionWithTitle:NSLocalizedString(@"OK", @"")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
[self.searchController setActive:NO];
if ([MFMessageComposeViewController canSendText]) {
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = self;
picker.recipients =
2016-06-28 06:36:42 +02:00
[self.currentSearchTerm length] > 0 ? [NSArray arrayWithObject:self.currentSearchTerm] : nil;
picker.body = [NSLocalizedString(@"SMS_INVITE_BODY", @"")
stringByAppendingString:
@" https://itunes.apple.com/us/app/signal-private-messenger/id874139669?mt=8"];
[self presentViewController:picker animated:YES completion:[UIUtil modalCompletionBlock]];
} else {
UIAlertView *notPermitted =
[[UIAlertView alloc] initWithTitle:@""
message:NSLocalizedString(@"UNSUPPORTED_FEATURE_ERROR", @"")
delegate:nil
cancelButtonTitle:NSLocalizedString(@"OK", @"")
otherButtonTitles:nil];
[notPermitted show];
}
}];
[alertController addAction:cancelAction];
[alertController addAction:okAction];
2016-06-28 06:36:42 +02:00
self.sendTextButton.hidden = YES;
self.searchController.searchBar.text = @"";
//must dismiss search controller before presenting alert.
if ([self presentedViewController]) {
[self dismissViewControllerAnimated:YES completion:^{
[self presentViewController:alertController animated:YES completion:[UIUtil modalCompletionBlock]];
}];
} else {
[self presentViewController:alertController animated:YES completion:[UIUtil modalCompletionBlock]];
}
}
#pragma mark - SMS Composer Delegate
// called on completion of message screen
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller
didFinishWithResult:(MessageComposeResult)result {
switch (result) {
case MessageComposeResultCancelled:
break;
case MessageComposeResultFailed: {
UIAlertView *warningAlert =
[[UIAlertView alloc] initWithTitle:@""
message:NSLocalizedString(@"SEND_INVITE_FAILURE", @"")
delegate:nil
cancelButtonTitle:NSLocalizedString(@"OK", @"")
otherButtonTitles:nil];
[warningAlert show];
break;
}
case MessageComposeResultSent: {
[self dismissViewControllerAnimated:NO
completion:^{
DDLogDebug(@"view controller dismissed");
}];
UIAlertView *successAlert =
[[UIAlertView alloc] initWithTitle:@""
message:NSLocalizedString(@"SEND_INVITE_SUCCESS", @"Alert body after invite succeeded")
delegate:nil
cancelButtonTitle:NSLocalizedString(@"OK", @"")
otherButtonTitles:nil];
[successAlert show];
break;
}
default:
break;
}
[self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - Table View Data Source
2014-10-29 21:58:58 +01:00
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
2014-10-29 21:58:58 +01:00
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == MessageComposeTableViewControllerSectionInvite) {
if (floor(NSFoundationVersionNumber) < NSFoundationVersionNumber_iOS_9_0) {
// Invite flow not supported on iOS8
return 0;
}
return 1;
2014-10-29 21:58:58 +01:00
} else {
if (self.searchController.active) {
return (NSInteger)[self.searchResults count];
} else {
return (NSInteger)[self.contacts count];
}
2014-10-29 21:58:58 +01:00
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == MessageComposeTableViewControllerSectionInvite) {
return self.inviteCell;
} else {
ContactTableViewCell *cell = (ContactTableViewCell *)[tableView
dequeueReusableCellWithIdentifier:MessageComposeTableViewControllerCellContact];
2014-10-29 21:58:58 +01:00
[cell configureWithContact:[self contactForIndexPath:indexPath] contactsManager:self.contactsManager];
return cell;
2014-10-29 21:58:58 +01:00
}
}
#pragma mark - Table View delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == MessageComposeTableViewControllerSectionInvite) {
void (^showInvite)() = ^{
OWSInviteFlow *inviteFlow =
[[OWSInviteFlow alloc] initWithPresentingViewController:self contactsManager:self.contactsManager];
[self presentViewController:inviteFlow.actionSheetController
animated:YES
completion:^{
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}];
};
2015-04-30 15:03:57 +02:00
if (self.presentedViewController) {
// If search controller is active, dismiss it first.
[self dismissViewControllerAnimated:YES completion:showInvite];
} else {
showInvite();
}
} else {
NSString *identifier = [[[self contactForIndexPath:indexPath] textSecureIdentifiers] firstObject];
[self dismissViewControllerAnimated:YES
completion:^() {
[Environment messageIdentifier:identifier withCompose:YES];
}];
}
2014-10-29 21:58:58 +01:00
}
- (Contact *)contactForIndexPath:(NSIndexPath *)indexPath {
2014-10-29 21:58:58 +01:00
Contact *contact = nil;
2014-10-29 21:58:58 +01:00
if (self.searchController.active) {
2016-06-28 06:36:42 +02:00
contact = [self.searchResults objectAtIndex:(NSUInteger)indexPath.row];
2014-10-29 21:58:58 +01:00
} else {
2016-06-28 06:36:42 +02:00
contact = [self.contacts objectAtIndex:(NSUInteger)indexPath.row];
2014-10-29 21:58:58 +01:00
}
2014-10-29 21:58:58 +01:00
return contact;
}
#pragma mark Refresh controls
- (void)updateAfterRefreshTry {
[self.refreshControl endRefreshing];
[self showLoadingBackgroundView:NO];
2016-06-28 06:36:42 +02:00
if ([self.contacts count] == 0) {
[self showEmptyBackgroundView:YES];
} else {
[self showEmptyBackgroundView:NO];
}
}
- (void)refreshContacts {
[[ContactsUpdater sharedUpdater] updateSignalContactIntersectionWithABContacts:self.contactsManager.allContacts
success:^{
self.contacts = self.contactsManager.signalContacts;
dispatch_async(dispatch_get_main_queue(), ^{
[self updateSearchResultsForSearchController:self.searchController];
[self.tableView reloadData];
[self updateAfterRefreshTry];
});
}
failure:^(NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *alert =
[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"ERROR_WAS_DETECTED_TITLE", @"")
message:NSLocalizedString(@"TIMEOUT_CONTACTS_DETAIL", @"")
delegate:nil
cancelButtonTitle:NSLocalizedString(@"OK", @"")
otherButtonTitles:nil];
[alert show];
[self updateAfterRefreshTry];
});
}];
2016-06-28 06:36:42 +02:00
if ([self.contacts count] == 0) {
[self showLoadingBackgroundView:YES];
}
}
2014-10-29 21:58:58 +01:00
#pragma mark - Navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(nullable id)sender
{
self.searchController.active = NO;
2014-10-29 21:58:58 +01:00
}
- (IBAction)closeAction:(id)sender {
2014-10-29 21:58:58 +01:00
[self dismissViewControllerAnimated:YES completion:nil];
}
2015-03-20 14:01:28 +01:00
- (CGFloat)contentWidth {
return [UIScreen mainScreen].bounds.size.width - 2 * [self marginSize];
2015-03-20 14:01:28 +01:00
}
- (CGFloat)marginSize {
return 20;
}
2014-10-29 21:58:58 +01:00
@end
NS_ASSUME_NONNULL_END