diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index 492969682..5dc3e4d92 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -51,7 +51,6 @@ 34B3F87C1E8DF1700035BE1A /* FingerprintViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B3F8461E8DF1700035BE1A /* FingerprintViewController.m */; }; 34B3F87D1E8DF1700035BE1A /* FullImageViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B3F8481E8DF1700035BE1A /* FullImageViewController.m */; }; 34B3F87E1E8DF1700035BE1A /* InboxTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B3F84A1E8DF1700035BE1A /* InboxTableViewCell.m */; }; - 34B3F87F1E8DF1700035BE1A /* InboxTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 34B3F84B1E8DF1700035BE1A /* InboxTableViewCell.xib */; }; 34B3F8801E8DF1700035BE1A /* InviteFlow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34B3F84C1E8DF1700035BE1A /* InviteFlow.swift */; }; 34B3F8811E8DF1700035BE1A /* LockInteractionController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B3F84E1E8DF1700035BE1A /* LockInteractionController.m */; }; 34B3F8821E8DF1700035BE1A /* MessageComposeTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B3F8501E8DF1700035BE1A /* MessageComposeTableViewController.m */; }; @@ -451,7 +450,6 @@ 34B3F8481E8DF1700035BE1A /* FullImageViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FullImageViewController.m; sourceTree = ""; }; 34B3F8491E8DF1700035BE1A /* InboxTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InboxTableViewCell.h; sourceTree = ""; }; 34B3F84A1E8DF1700035BE1A /* InboxTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = InboxTableViewCell.m; sourceTree = ""; }; - 34B3F84B1E8DF1700035BE1A /* InboxTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = InboxTableViewCell.xib; sourceTree = ""; }; 34B3F84C1E8DF1700035BE1A /* InviteFlow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InviteFlow.swift; sourceTree = ""; }; 34B3F84D1E8DF1700035BE1A /* LockInteractionController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LockInteractionController.h; sourceTree = ""; }; 34B3F84E1E8DF1700035BE1A /* LockInteractionController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LockInteractionController.m; sourceTree = ""; }; @@ -966,7 +964,6 @@ 34D5CCA81EAE3D30005515DB /* GroupViewHelper.m */, 34B3F8491E8DF1700035BE1A /* InboxTableViewCell.h */, 34B3F84A1E8DF1700035BE1A /* InboxTableViewCell.m */, - 34B3F84B1E8DF1700035BE1A /* InboxTableViewCell.xib */, 34B3F84C1E8DF1700035BE1A /* InviteFlow.swift */, 34B3F84D1E8DF1700035BE1A /* LockInteractionController.h */, 34B3F84E1E8DF1700035BE1A /* LockInteractionController.m */, @@ -1909,7 +1906,6 @@ AD83FF401A73426500B5C81A /* audio_pause_button_blue@2x.png in Resources */, B66DBF4A19D5BBC8006EA940 /* Images.xcassets in Resources */, 70B8FEE21909FE360042E3F0 /* 171756__nenadsimic__picked-coin-echo-2.wav in Resources */, - 34B3F87F1E8DF1700035BE1A /* InboxTableViewCell.xib in Resources */, 4517642A1DE939FD00EDB8B9 /* ContactCell.xib in Resources */, AD83FF431A73426500B5C81A /* audio_play_button@2x.png in Resources */, 45CB2FA81CB7146C00E1B343 /* Launch Screen.storyboard in Resources */, diff --git a/Signal/src/UIView+OWS.h b/Signal/src/UIView+OWS.h index c571bc986..7fb7d1d44 100644 --- a/Signal/src/UIView+OWS.h +++ b/Signal/src/UIView+OWS.h @@ -85,6 +85,10 @@ CGFloat ScaleFromIPhone5(CGFloat iPhone5Value); + (UIView *)containerView; - (void)setHLayoutMargins:(CGFloat)value; +#pragma mark - Formatting + ++ (NSString *)formatInt:(int)value; + #pragma mark - Debugging - (void)addBorderWithColor:(UIColor *)color; diff --git a/Signal/src/UIView+OWS.m b/Signal/src/UIView+OWS.m index 726c32f25..654b8f136 100644 --- a/Signal/src/UIView+OWS.m +++ b/Signal/src/UIView+OWS.m @@ -257,7 +257,7 @@ CGFloat ScaleFromIPhone5(CGFloat iPhone5Value) { OWSAssert(view); - NSLayoutConstraint *constraint = [self autoPinLeadingToTrailingOfView:view margin:0]; + return [self autoPinLeadingToTrailingOfView:view margin:0]; } - (NSLayoutConstraint *)autoPinLeadingToTrailingOfView:(UIView *)view margin:(CGFloat)margin @@ -325,6 +325,19 @@ CGFloat ScaleFromIPhone5(CGFloat iPhone5Value) self.layoutMargins = layoutMargins; } +#pragma mark - Formatting + ++ (NSString *)formatInt:(int)value +{ + static NSNumberFormatter *formatter = nil; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + formatter = [NSNumberFormatter new]; + formatter.numberStyle = NSNumberFormatterNoStyle; + }); + return [formatter stringFromNumber:@(value)]; +} + #pragma mark - Debugging - (void)addBorderWithColor:(UIColor *)color diff --git a/Signal/src/ViewControllers/InboxTableViewCell.h b/Signal/src/ViewControllers/InboxTableViewCell.h index c56e286bc..0ed13e554 100644 --- a/Signal/src/ViewControllers/InboxTableViewCell.h +++ b/Signal/src/ViewControllers/InboxTableViewCell.h @@ -2,35 +2,21 @@ // Copyright (c) 2017 Open Whisper Systems. All rights reserved. // -#import "TSThread.h" - NS_ASSUME_NONNULL_BEGIN -@class Contact; +@class TSThread; @class OWSContactsManager; -@class AvatarImageView; - -@interface InboxTableViewCell : UITableViewCell - -@property (nonatomic) IBOutlet UILabel *nameLabel; -@property (nonatomic) IBOutlet UILabel *snippetLabel; -@property (nonatomic) IBOutlet AvatarImageView *contactPictureView; -@property (nonatomic) IBOutlet UILabel *timeLabel; -@property (nonatomic) IBOutlet UIView *contentContainerView; -@property (nonatomic) IBOutlet UIView *messageCounter; -@property (nonatomic) NSString *threadId; -@property (nonatomic) NSString *contactId; -+ (instancetype)inboxTableViewCell; +@interface InboxTableViewCell : UITableViewCell + (CGFloat)rowHeight; ++ (NSString *)cellReuseIdentifier; + - (void)configureWithThread:(TSThread *)thread contactsManager:(OWSContactsManager *)contactsManager blockedPhoneNumberSet:(NSSet *)blockedPhoneNumberSet; -- (void)animateDisappear; - @end NS_ASSUME_NONNULL_END diff --git a/Signal/src/ViewControllers/InboxTableViewCell.m b/Signal/src/ViewControllers/InboxTableViewCell.m index e20b1619c..4dbb2c326 100644 --- a/Signal/src/ViewControllers/InboxTableViewCell.m +++ b/Signal/src/ViewControllers/InboxTableViewCell.m @@ -3,18 +3,13 @@ // #import "InboxTableViewCell.h" -#import "Environment.h" #import "OWSAvatarBuilder.h" -#import "OWSContactAvatarBuilder.h" -#import "PropertyListPreferences.h" #import "Signal-Swift.h" -#import "TSContactThread.h" -#import "TSGroupThread.h" -#import "TSMessagesManager.h" #import "Util.h" -#import -#import -#import +#import +#import +#import +#import NS_ASSUME_NONNULL_BEGIN @@ -24,26 +19,113 @@ NS_ASSUME_NONNULL_BEGIN #define DATE_LABEL_SIZE 13 #define SWIPE_ARCHIVE_OFFSET -50 -const NSUInteger kContactPictureViewDiameter = 52; +const NSUInteger kavatarViewDiameter = 52; @interface InboxTableViewCell () -@property (nonatomic) NSUInteger unreadMessages; -@property (nonatomic) UIView *messagesBadge; +@property (nonatomic) AvatarImageView *avatarView; +@property (nonatomic) UILabel *nameLabel; +@property (nonatomic) UILabel *snippetLabel; +@property (nonatomic) UILabel *timeLabel; +@property (nonatomic) UIView *unreadBadge; @property (nonatomic) UILabel *unreadLabel; +@property (nonatomic) NSString *threadId; + @end #pragma mark - @implementation InboxTableViewCell -+ (instancetype)inboxTableViewCell { - InboxTableViewCell *cell = - [NSBundle.mainBundle loadNibNamed:NSStringFromClass(self.class) owner:self options:nil][0]; +- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(nullable NSString *)reuseIdentifier +{ + if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { + [self commontInit]; + } + return self; +} + +// `[UIView init]` invokes `[self initWithFrame:...]`. +- (instancetype)initWithFrame:(CGRect)frame +{ + if (self = [super initWithFrame:frame]) { + [self commontInit]; + } - [cell initializeLayout]; - return cell; + return self; +} + +- (void)commontInit +{ + OWSAssert(!self.avatarView); + + [self setTranslatesAutoresizingMaskIntoConstraints:NO]; + self.preservesSuperviewLayoutMargins = YES; + self.contentView.preservesSuperviewLayoutMargins = YES; + + self.backgroundColor = [UIColor whiteColor]; + + self.avatarView = [[AvatarImageView alloc] init]; + [self.contentView addSubview:self.avatarView]; + [self.avatarView autoSetDimension:ALDimensionWidth toSize:52.f]; + [self.avatarView autoSetDimension:ALDimensionHeight toSize:52.f]; + [self.avatarView autoPinLeadingToSuperView]; + [self.avatarView autoVCenterInSuperview]; + + self.nameLabel = [UILabel new]; + self.nameLabel.lineBreakMode = NSLineBreakByTruncatingTail; + [self.contentView addSubview:self.nameLabel]; + [self.nameLabel autoPinLeadingToTrailingOfView:self.avatarView margin:13.f]; + [self.nameLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:self.avatarView]; + [self.nameLabel setContentHuggingHorizontalLow]; + + self.snippetLabel = [UILabel new]; + self.snippetLabel.font = [UIFont ows_regularFontWithSize:14.f]; + self.snippetLabel.lineBreakMode = NSLineBreakByTruncatingTail; + self.snippetLabel.textColor = [UIColor colorWithWhite:2 / 3.f alpha:1.f]; + self.snippetLabel.numberOfLines = 2; + self.snippetLabel.lineBreakMode = NSLineBreakByTruncatingTail; + [self.contentView addSubview:self.snippetLabel]; + [self.snippetLabel autoPinLeadingToTrailingOfView:self.avatarView margin:13.f]; + [self.snippetLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.nameLabel withOffset:5.f]; + [self.snippetLabel autoPinEdge:ALEdgeTrailing toEdge:ALEdgeTrailing ofView:self.nameLabel]; + [self.snippetLabel setContentHuggingHorizontalLow]; + + self.timeLabel = [UILabel new]; + self.timeLabel.font = [UIFont ows_lightFontWithSize:14.f]; + [self.contentView addSubview:self.timeLabel]; + [self.timeLabel autoPinTrailingToSuperView]; + [self.timeLabel autoAlignAxis:ALAxisHorizontal toSameAxisOfView:self.nameLabel]; + [self.timeLabel autoPinLeadingToTrailingOfView:self.nameLabel margin:10.f]; + [self.timeLabel setContentHuggingHorizontalHigh]; + [self.timeLabel setCompressionResistanceHigh]; + + const int kunreadBadgeSize = 24; + self.unreadBadge = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kunreadBadgeSize, kunreadBadgeSize)]; + self.unreadBadge.layer.cornerRadius = kunreadBadgeSize / 2; + self.unreadBadge.backgroundColor = [UIColor ows_materialBlueColor]; + [self.contentView addSubview:self.unreadBadge]; + [self.unreadBadge autoSetDimension:ALDimensionWidth toSize:kunreadBadgeSize]; + [self.unreadBadge autoSetDimension:ALDimensionHeight toSize:kunreadBadgeSize]; + [self.unreadBadge autoPinTrailingToSuperView]; + [self.unreadBadge autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:self.avatarView]; + [self.unreadBadge setContentHuggingHorizontalHigh]; + [self.unreadBadge setCompressionResistanceHigh]; + + self.unreadLabel = [UILabel new]; + self.unreadLabel.font = [UIFont ows_regularFontWithSize:12.f]; + self.unreadLabel.textColor = [UIColor whiteColor]; + self.unreadLabel.lineBreakMode = NSLineBreakByTruncatingTail; + self.unreadLabel.textAlignment = NSTextAlignmentCenter; + [self.unreadBadge addSubview:self.unreadLabel]; + [self.unreadLabel autoVCenterInSuperview]; + [self.unreadLabel autoPinWidthToSuperview]; +} + ++ (NSString *)cellReuseIdentifier +{ + return NSStringFromClass([self class]); } + (CGFloat)rowHeight @@ -121,31 +203,36 @@ const NSUInteger kContactPictureViewDiameter = 52; self.nameLabel.text = name; self.snippetLabel.attributedText = snippetText; self.timeLabel.attributedText = attributedDate; - self.contactPictureView.image = nil; + self.avatarView.image = nil; - self.separatorInset = UIEdgeInsetsMake(0, _contactPictureView.frame.size.width * 1.5f, 0, 0); + self.separatorInset = UIEdgeInsetsMake(0, _avatarView.frame.size.width * 1.5f, 0, 0); if (thread.hasUnreadMessages) { [self updateCellForUnreadMessage]; } else { [self updateCellForReadMessage]; } - [self setUnreadMsgCount:unreadCount]; + if (unreadCount > 0) { + self.unreadBadge.hidden = NO; + self.unreadLabel.hidden = NO; + self.unreadLabel.text = [UIView formatInt:MIN(99, (int)unreadCount)]; + } else { + self.unreadBadge.hidden = YES; + self.unreadLabel.hidden = YES; + } NSString *threadIdCopy = thread.uniqueId; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - UIImage *avatar = [OWSAvatarBuilder buildImageForThread:thread - contactsManager:contactsManager - diameter:kContactPictureViewDiameter]; + UIImage *avatar = + [OWSAvatarBuilder buildImageForThread:thread contactsManager:contactsManager diameter:kavatarViewDiameter]; dispatch_async(dispatch_get_main_queue(), ^{ if ([_threadId isEqualToString:threadIdCopy]) { - self.contactPictureView.image = avatar; + self.avatarView.image = avatar; } }); }); } - - (void)updateCellForUnreadMessage { _nameLabel.font = [UIFont ows_boldFontWithSize:14.0f]; _nameLabel.textColor = [UIColor ows_blackColor]; @@ -184,68 +271,11 @@ const NSUInteger kContactPictureViewDiameter = 52; return attributedString; } -- (void)setUnreadMsgCount:(NSUInteger)unreadMessages { - if (_unreadMessages != unreadMessages) { - _unreadMessages = unreadMessages; - - if (_unreadMessages > 0) { - if (_messagesBadge == nil) { - static UIImage *backgroundImage = nil; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - UIGraphicsBeginImageContextWithOptions(CGSizeMake(25.0f, 25.0f), false, 0.0f); - CGContextRef context = UIGraphicsGetCurrentContext(); - CGContextSetFillColorWithColor(context, [UIColor ows_materialBlueColor].CGColor); - CGContextFillEllipseInRect(context, CGRectMake(0.0f, 0.0f, 25.0f, 25.0f)); - backgroundImage = - [UIGraphicsGetImageFromCurrentImageContext() stretchableImageWithLeftCapWidth:8 topCapHeight:8]; - UIGraphicsEndImageContext(); - }); - - _messagesBadge = [[UIImageView alloc] - initWithFrame:CGRectMake( - 0.0f, 0.0f, _messageCounter.frame.size.height, _messageCounter.frame.size.width)]; - _messagesBadge.userInteractionEnabled = NO; - _messagesBadge.layer.zPosition = 2000; - - UIImageView *unreadBackground = [[UIImageView alloc] initWithImage:backgroundImage]; - [_messageCounter addSubview:unreadBackground]; - - _unreadLabel = [[UILabel alloc] init]; - _unreadLabel.backgroundColor = [UIColor clearColor]; - _unreadLabel.textColor = [UIColor whiteColor]; - _unreadLabel.font = [UIFont systemFontOfSize:12]; - [_messageCounter addSubview:_unreadLabel]; - } - - // Max out the unread count at 99+. - const NSUInteger kMaxUnreadCount = 99; - _unreadLabel.text = [@(MIN(kMaxUnreadCount, unreadMessages)) stringValue]; - [_unreadLabel sizeToFit]; - - CGPoint offset = CGPointMake(0.0f, 5.0f); - _unreadLabel.frame - = CGRectMake(offset.x + (CGFloat)floor((2.0f * (25.0f - _unreadLabel.frame.size.width) / 2.0f) / 2.0f), - offset.y, - _unreadLabel.frame.size.width, - _unreadLabel.frame.size.height); - _messageCounter.hidden = NO; - } else { - _messageCounter.hidden = YES; - } - } -} - -#pragma mark - Animation - -- (void)animateDisappear { - [UIView animateWithDuration:1.0f - animations:^() { - self.alpha = 0; - }]; +- (void)prepareForReuse +{ + [super prepareForReuse]; } - @end NS_ASSUME_NONNULL_END diff --git a/Signal/src/ViewControllers/InboxTableViewCell.xib b/Signal/src/ViewControllers/InboxTableViewCell.xib deleted file mode 100644 index 024b2eb45..000000000 --- a/Signal/src/ViewControllers/InboxTableViewCell.xib +++ /dev/null @@ -1,108 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Signal/src/ViewControllers/SelectRecipientViewController.m b/Signal/src/ViewControllers/SelectRecipientViewController.m index 560bcf7a3..9fbe046be 100644 --- a/Signal/src/ViewControllers/SelectRecipientViewController.m +++ b/Signal/src/ViewControllers/SelectRecipientViewController.m @@ -223,8 +223,8 @@ NSString *const kSelectRecipientViewControllerCellIdentifier = @"kSelectRecipien callingCode = [localNumber getCountryCode]; OWSAssert(callingCode); if (callingCode) { - countryCode = [[PhoneNumberUtil sharedUtil] - probableCountryCodeForCallingCode:[@"+" stringByAppendingString:[callingCode description]]]; + NSString *prefix = [NSString stringWithFormat:@"+%d", callingCode.intValue]; + countryCode = [[PhoneNumberUtil sharedUtil] probableCountryCodeForCallingCode:prefix]; } } diff --git a/Signal/src/ViewControllers/SignalsViewController.m b/Signal/src/ViewControllers/SignalsViewController.m index 52493574e..bf940b95b 100644 --- a/Signal/src/ViewControllers/SignalsViewController.m +++ b/Signal/src/ViewControllers/SignalsViewController.m @@ -201,6 +201,8 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState }; self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]; self.tableView.delegate = self; self.tableView.dataSource = self; + [self.tableView registerClass:[InboxTableViewCell class] + forCellReuseIdentifier:InboxTableViewCell.cellReuseIdentifier]; [self.view addSubview:self.tableView]; [self.tableView autoPinWidthToSuperview]; [self.tableView autoPinToBottomLayoutGuideOfViewController:self withInset:0]; @@ -270,34 +272,37 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState }; - (void)updateBarButtonItems { const CGFloat kBarButtonSize = 44; - if (YES) { - // We use UIButtons with [UIBarButtonItem initWithCustomView:...] instead of - // UIBarButtonItem in order to ensure that these buttons are spaced tightly. - // The contents of the navigation bar are cramped in this view. - UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; - UIImage *image = [UIImage imageNamed:@"button_settings_white"]; - [button setImage:image - forState:UIControlStateNormal]; - UIEdgeInsets imageEdgeInsets = UIEdgeInsetsZero; - // We normally would want to use left and right insets that ensure the button - // is square and the icon is centered. However UINavigationBar doesn't offer us - // control over the margins and spacing of its content, and the buttons end up - // too far apart and too far from the edge of the screen. So we use a smaller - // left inset tighten up the layout. - imageEdgeInsets.right = round((kBarButtonSize - image.size.width) * 0.5f); - imageEdgeInsets.left = round((kBarButtonSize - (image.size.width + imageEdgeInsets.right)) * 0.5f); - imageEdgeInsets.top = round((kBarButtonSize - image.size.height) * 0.5f); - imageEdgeInsets.bottom = round(kBarButtonSize - (image.size.height + imageEdgeInsets.top)); - button.imageEdgeInsets = imageEdgeInsets; - button.accessibilityLabel = NSLocalizedString(@"OPEN_SETTINGS_BUTTON", "Label for button which opens the settings UI"); - [button addTarget:self - action:@selector(settingsButtonPressed:) - forControlEvents:UIControlEventTouchUpInside]; - button.frame = CGRectMake(0, 0, - round(image.size.width + imageEdgeInsets.left + imageEdgeInsets.right), - round(image.size.height + imageEdgeInsets.top + imageEdgeInsets.bottom)); - self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button]; - } + // We use UIButtons with [UIBarButtonItem initWithCustomView:...] instead of + // UIBarButtonItem in order to ensure that these buttons are spaced tightly. + // The contents of the navigation bar are cramped in this view. + UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; + UIImage *image = [UIImage imageNamed:@"button_settings_white"]; + [button setImage:image forState:UIControlStateNormal]; + UIEdgeInsets imageEdgeInsets = UIEdgeInsetsZero; + // We normally would want to use left and right insets that ensure the button + // is square and the icon is centered. However UINavigationBar doesn't offer us + // control over the margins and spacing of its content, and the buttons end up + // too far apart and too far from the edge of the screen. So we use a smaller + // leading inset tighten up the layout. + CGFloat hInset = round((kBarButtonSize - image.size.width) * 0.5f); + if (self.view.isRTL) { + imageEdgeInsets.right = hInset; + imageEdgeInsets.left = round((kBarButtonSize - (image.size.width + hInset)) * 0.5f); + } else { + imageEdgeInsets.left = hInset; + imageEdgeInsets.right = round((kBarButtonSize - (image.size.width + hInset)) * 0.5f); + } + imageEdgeInsets.top = round((kBarButtonSize - image.size.height) * 0.5f); + imageEdgeInsets.bottom = round(kBarButtonSize - (image.size.height + imageEdgeInsets.top)); + button.imageEdgeInsets = imageEdgeInsets; + button.accessibilityLabel + = NSLocalizedString(@"OPEN_SETTINGS_BUTTON", "Label for button which opens the settings UI"); + [button addTarget:self action:@selector(settingsButtonPressed:) forControlEvents:UIControlEventTouchUpInside]; + button.frame = CGRectMake(0, + 0, + round(image.size.width + imageEdgeInsets.left + imageEdgeInsets.right), + round(image.size.height + imageEdgeInsets.top + imageEdgeInsets.bottom)); + self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button]; } - (void)settingsButtonPressed:(id)sender { @@ -559,12 +564,10 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState }; - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { InboxTableViewCell *cell = - [self.tableView dequeueReusableCellWithIdentifier:NSStringFromClass([InboxTableViewCell class])]; - TSThread *thread = [self threadForIndexPath:indexPath]; + [self.tableView dequeueReusableCellWithIdentifier:InboxTableViewCell.cellReuseIdentifier]; + OWSAssert(cell); - if (!cell) { - cell = [InboxTableViewCell inboxTableViewCell]; - } + TSThread *thread = [self threadForIndexPath:indexPath]; [cell configureWithThread:thread contactsManager:self.contactsManager blockedPhoneNumberSet:_blockedPhoneNumberSet];