DRY up common table cell patterns.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent 96fd5e11e5
commit eaacac9d8b

@ -179,22 +179,15 @@ NS_ASSUME_NONNULL_BEGIN
selector:@selector(didToggleEnableCensorshipCircumventionSwitch:)]]; selector:@selector(didToggleEnableCensorshipCircumventionSwitch:)]];
if (OWSSignalService.sharedInstance.isCensorshipCircumventionManuallyActivated) { if (OWSSignalService.sharedInstance.isCensorshipCircumventionManuallyActivated) {
[censorshipSection addItem:[OWSTableItem itemWithCustomCellBlock:^{
OWSCountryMetadata *manualCensorshipCircumventionCountry = OWSCountryMetadata *manualCensorshipCircumventionCountry =
[weakSelf ensureManualCensorshipCircumventionCountry]; [weakSelf ensureManualCensorshipCircumventionCountry];
OWSAssert(manualCensorshipCircumventionCountry); OWSAssert(manualCensorshipCircumventionCountry);
NSString *text = [NSString
UITableViewCell *cell = [UITableViewCell new];
cell.textLabel.text = [NSString
stringWithFormat:NSLocalizedString(@"SETTINGS_ADVANCED_CENSORSHIP_CIRCUMVENTION_COUNTRY_FORMAT", stringWithFormat:NSLocalizedString(@"SETTINGS_ADVANCED_CENSORSHIP_CIRCUMVENTION_COUNTRY_FORMAT",
@"Label for the 'manual censorship circumvention' country. Embeds {{the manual " @"Label for the 'manual censorship circumvention' country. Embeds {{the manual "
@"censorship circumvention country}}."), @"censorship circumvention country}}."),
manualCensorshipCircumventionCountry.localizedCountryName]; manualCensorshipCircumventionCountry.localizedCountryName];
cell.textLabel.font = [UIFont ows_regularFontWithSize:18.f]; [censorshipSection addItem:[OWSTableItem disclosureItemWithText:text
cell.textLabel.textColor = [UIColor blackColor];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
actionBlock:^{ actionBlock:^{
[weakSelf showDomainFrontingCountryView]; [weakSelf showDomainFrontingCountryView];
}]]; }]];

@ -68,15 +68,10 @@ NS_ASSUME_NONNULL_BEGIN
addSection.footerTitle = NSLocalizedString( addSection.footerTitle = NSLocalizedString(
@"BLOCK_BEHAVIOR_EXPLANATION", @"An explanation of the consequences of blocking another user."); @"BLOCK_BEHAVIOR_EXPLANATION", @"An explanation of the consequences of blocking another user.");
[addSection addItem:[OWSTableItem itemWithCustomCellBlock:^{ [addSection
UITableViewCell *cell = [UITableViewCell new]; addItem:[OWSTableItem
cell.textLabel.text = NSLocalizedString( disclosureItemWithText:NSLocalizedString(@"SETTINGS_BLOCK_LIST_ADD_BUTTON",
@"SETTINGS_BLOCK_LIST_ADD_BUTTON", @"A label for the 'add phone number' button in the block list table."); @"A label for the 'add phone number' button in the block list table.")
cell.textLabel.font = [UIFont ows_regularFontWithSize:18.f];
cell.textLabel.textColor = [UIColor blackColor];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
actionBlock:^{ actionBlock:^{
AddToBlockListViewController *vc = [[AddToBlockListViewController alloc] init]; AddToBlockListViewController *vc = [[AddToBlockListViewController alloc] init];
NSAssert(self.navigationController != nil, @"Navigation controller must not be nil"); NSAssert(self.navigationController != nil, @"Navigation controller must not be nil");

@ -287,15 +287,9 @@ NS_ASSUME_NONNULL_BEGIN
[ContactTableViewCell rowHeight]); [ContactTableViewCell rowHeight]);
// Find Non-Contacts by Phone Number // Find Non-Contacts by Phone Number
[section addItem:[OWSTableItem itemWithCustomCellBlock:^{ [section addItem:[OWSTableItem
UITableViewCell *cell = [UITableViewCell new]; disclosureItemWithText:NSLocalizedString(@"NEW_CONVERSATION_FIND_BY_PHONE_NUMBER",
cell.textLabel.text = NSLocalizedString( @"A label the cell that lets you add a new member to a group.")
@"NEW_CONVERSATION_FIND_BY_PHONE_NUMBER", @"A label the cell that lets you add a new member to a group.");
cell.textLabel.font = [UIFont ows_regularFontWithSize:18.f];
cell.textLabel.textColor = [UIColor blackColor];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
customRowHeight:kActionCellHeight customRowHeight:kActionCellHeight
actionBlock:^{ actionBlock:^{
NewNonContactConversationViewController *viewController = NewNonContactConversationViewController *viewController =
@ -306,15 +300,10 @@ NS_ASSUME_NONNULL_BEGIN
if (self.contactsViewHelper.contactsManager.isSystemContactsAuthorized) { if (self.contactsViewHelper.contactsManager.isSystemContactsAuthorized) {
// Invite Contacts // Invite Contacts
[section addItem:[OWSTableItem itemWithCustomCellBlock:^{ [section
UITableViewCell *cell = [UITableViewCell new]; addItem:[OWSTableItem
cell.textLabel.text = NSLocalizedString(@"INVITE_FRIENDS_CONTACT_TABLE_BUTTON", disclosureItemWithText:NSLocalizedString(@"INVITE_FRIENDS_CONTACT_TABLE_BUTTON",
@"Label for the cell that presents the 'invite contacts' workflow."); @"Label for the cell that presents the 'invite contacts' workflow.")
cell.textLabel.font = [UIFont ows_regularFontWithSize:18.f];
cell.textLabel.textColor = [UIColor blackColor];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
customRowHeight:kActionCellHeight customRowHeight:kActionCellHeight
actionBlock:^{ actionBlock:^{
[weakSelf presentInviteFlow]; [weakSelf presentInviteFlow];
@ -350,18 +339,11 @@ NS_ASSUME_NONNULL_BEGIN
[weakSelf newConversationWith:phoneNumber]; [weakSelf newConversationWith:phoneNumber];
}]]; }]];
} else { } else {
[section addItem:[OWSTableItem itemWithCustomCellBlock:^{ NSString *text = [NSString stringWithFormat:NSLocalizedString(@"SEND_INVITE_VIA_SMS_BUTTON_FORMAT",
UITableViewCell *cell = [UITableViewCell new];
cell.textLabel.text =
[NSString stringWithFormat:NSLocalizedString(@"SEND_INVITE_VIA_SMS_BUTTON_FORMAT",
@"Text for button to send a Signal invite via SMS. %@ is " @"Text for button to send a Signal invite via SMS. %@ is "
@"placeholder for the receipient's phone number."), @"placeholder for the receipient's phone number."),
phoneNumber]; phoneNumber];
cell.textLabel.font = [UIFont ows_regularFontWithSize:18.f]; [section addItem:[OWSTableItem disclosureItemWithText:text
cell.textLabel.textColor = [UIColor blackColor];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
customRowHeight:kActionCellHeight customRowHeight:kActionCellHeight
actionBlock:^{ actionBlock:^{
[weakSelf sendTextToPhoneNumber:phoneNumber]; [weakSelf sendTextToPhoneNumber:phoneNumber];
@ -411,18 +393,11 @@ NS_ASSUME_NONNULL_BEGIN
displayName = phoneNumber.toE164; displayName = phoneNumber.toE164;
} }
[section addItem:[OWSTableItem itemWithCustomCellBlock:^{ NSString *text = [NSString stringWithFormat:NSLocalizedString(@"SEND_INVITE_VIA_SMS_BUTTON_FORMAT",
UITableViewCell *cell = [UITableViewCell new];
cell.textLabel.text =
[NSString stringWithFormat:NSLocalizedString(@"SEND_INVITE_VIA_SMS_BUTTON_FORMAT",
@"Text for button to send a Signal invite via SMS. %@ is " @"Text for button to send a Signal invite via SMS. %@ is "
@"placeholder for the receipient's phone number."), @"placeholder for the receipient's phone number."),
displayName]; displayName];
cell.textLabel.font = [UIFont ows_regularFontWithSize:18.f]; [section addItem:[OWSTableItem disclosureItemWithText:text
cell.textLabel.textColor = [UIColor blackColor];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
customRowHeight:kActionCellHeight customRowHeight:kActionCellHeight
actionBlock:^{ actionBlock:^{
[weakSelf sendTextToPhoneNumber:phoneNumber.toE164]; [weakSelf sendTextToPhoneNumber:phoneNumber.toE164];
@ -435,36 +410,22 @@ NS_ASSUME_NONNULL_BEGIN
if (self.contactsViewHelper.contactsManager.isSystemContactsAuthorized if (self.contactsViewHelper.contactsManager.isSystemContactsAuthorized
&& self.contactsViewHelper.hasUpdatedContactsAtLeastOnce) { && self.contactsViewHelper.hasUpdatedContactsAtLeastOnce) {
[section addItem:[OWSTableItem itemWithCustomCellBlock:^{
UITableViewCell *cell = [UITableViewCell new]; [section
cell.textLabel.text = NSLocalizedString( addItem:[OWSTableItem
@"SETTINGS_BLOCK_LIST_NO_CONTACTS", @"A label that indicates the user has no Signal contacts."); softCenterLabelItemWithText:NSLocalizedString(@"SETTINGS_BLOCK_LIST_NO_CONTACTS",
cell.textLabel.font = [UIFont ows_regularFontWithSize:15.f]; @"A label that indicates the user has no Signal contacts.")
cell.textLabel.textColor = [UIColor colorWithWhite:0.5f alpha:1.f]; customRowHeight:kActionCellHeight]];
cell.textLabel.textAlignment = NSTextAlignmentCenter;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
customRowHeight:kActionCellHeight
actionBlock:nil]];
} }
} }
if (hasSearchText && !hasSearchResults) { if (hasSearchText && !hasSearchResults) {
// No Search Results // No Search Results
[section addItem:[OWSTableItem itemWithCustomCellBlock:^{ [section addItem:[OWSTableItem softCenterLabelItemWithText:
UITableViewCell *cell = [UITableViewCell new]; NSLocalizedString(@"SETTINGS_BLOCK_LIST_NO_SEARCH_RESULTS",
cell.textLabel.text = NSLocalizedString(@"SETTINGS_BLOCK_LIST_NO_SEARCH_RESULTS", @"A label that indicates the user's search has no matching results.")
@"A label that indicates the user's search has no matching results."); customRowHeight:kActionCellHeight]];
cell.textLabel.font = [UIFont ows_regularFontWithSize:15.f];
cell.textLabel.textColor = [UIColor colorWithWhite:0.5f alpha:1.f];
cell.textLabel.textAlignment = NSTextAlignmentCenter;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
customRowHeight:kActionCellHeight
actionBlock:nil]];
} }
[contents addSection:section]; [contents addSection:section];

@ -364,16 +364,10 @@ const NSUInteger kNewGroupViewControllerAvatarWidth = 68;
}]]; }]];
} }
} else { } else {
[signalAccountSection addItem:[OWSTableItem itemWithCustomCellBlock:^{ [signalAccountSection
UITableViewCell *cell = [UITableViewCell new]; addItem:[OWSTableItem
cell.textLabel.text = NSLocalizedString( softCenterLabelItemWithText:NSLocalizedString(@"SETTINGS_BLOCK_LIST_NO_CONTACTS",
@"SETTINGS_BLOCK_LIST_NO_CONTACTS", @"A label that indicates the user has no Signal contacts."); @"A label that indicates the user has no Signal contacts.")]];
cell.textLabel.font = [UIFont ows_regularFontWithSize:15.f];
cell.textLabel.textColor = [UIColor colorWithWhite:0.5f alpha:1.f];
cell.textLabel.textAlignment = NSTextAlignmentCenter;
return cell;
}
actionBlock:nil]];
} }
[contents addSection:signalAccountSection]; [contents addSection:signalAccountSection];
@ -383,15 +377,9 @@ const NSUInteger kNewGroupViewControllerAvatarWidth = 68;
- (OWSTableItem *)createAddNonContactItem - (OWSTableItem *)createAddNonContactItem
{ {
__weak NewGroupViewController *weakSelf = self; __weak NewGroupViewController *weakSelf = self;
return [OWSTableItem itemWithCustomCellBlock:^{ return [OWSTableItem
UITableViewCell *cell = [UITableViewCell new]; disclosureItemWithText:NSLocalizedString(@"NEW_GROUP_ADD_NON_CONTACT",
cell.textLabel.text = NSLocalizedString(@"NEW_GROUP_ADD_NON_CONTACT", @"A label for the cell that lets you add a new non-contact member to a group.")
@"A label for the cell that lets you add a new non-contact member to a group.");
cell.textLabel.font = [UIFont ows_regularFontWithSize:18.f];
cell.textLabel.textColor = [UIColor blackColor];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
customRowHeight:[ContactTableViewCell rowHeight] customRowHeight:[ContactTableViewCell rowHeight]
actionBlock:^{ actionBlock:^{
AddToGroupViewController *viewController = [AddToGroupViewController new]; AddToGroupViewController *viewController = [AddToGroupViewController new];

@ -72,6 +72,10 @@ typedef UITableViewCell *_Nonnull (^OWSTableCustomCellBlock)();
+ (OWSTableItem *)actionItemWithText:(NSString *)text actionBlock:(nullable OWSTableActionBlock)actionBlock; + (OWSTableItem *)actionItemWithText:(NSString *)text actionBlock:(nullable OWSTableActionBlock)actionBlock;
+ (OWSTableItem *)softCenterLabelItemWithText:(NSString *)text;
+ (OWSTableItem *)softCenterLabelItemWithText:(NSString *)text customRowHeight:(CGFloat)customRowHeight;
+ (OWSTableItem *)labelItemWithText:(NSString *)text; + (OWSTableItem *)labelItemWithText:(NSString *)text;
+ (OWSTableItem *)labelItemWithText:(NSString *)text accessoryText:(NSString *)accessoryText; + (OWSTableItem *)labelItemWithText:(NSString *)text accessoryText:(NSString *)accessoryText;

@ -127,13 +127,9 @@ const CGFloat kOWSTable_DefaultCellHeight = 45.f;
customRowHeight:(CGFloat)customRowHeight customRowHeight:(CGFloat)customRowHeight
actionBlock:(nullable OWSTableActionBlock)actionBlock actionBlock:(nullable OWSTableActionBlock)actionBlock
{ {
OWSAssert(customCellBlock);
OWSAssert(customRowHeight > 0); OWSAssert(customRowHeight > 0);
OWSTableItem *item = [OWSTableItem new]; OWSTableItem *item = [self itemWithCustomCellBlock:customCellBlock actionBlock:actionBlock];
item.itemType = (actionBlock != nil ? OWSTableItemTypeAction : OWSTableItemTypeDefault);
item.actionBlock = actionBlock;
item.customCellBlock = customCellBlock;
item.customRowHeight = @(customRowHeight); item.customRowHeight = @(customRowHeight);
return item; return item;
} }
@ -173,6 +169,8 @@ const CGFloat kOWSTable_DefaultCellHeight = 45.f;
customRowHeight:(CGFloat)customRowHeight customRowHeight:(CGFloat)customRowHeight
actionBlock:(nullable OWSTableActionBlock)actionBlock actionBlock:(nullable OWSTableActionBlock)actionBlock
{ {
OWSAssert(customRowHeight > 0);
OWSTableItem *item = [self disclosureItemWithText:text actionBlock:actionBlock]; OWSTableItem *item = [self disclosureItemWithText:text actionBlock:actionBlock];
item.customRowHeight = @(customRowHeight); item.customRowHeight = @(customRowHeight);
return item; return item;
@ -196,6 +194,38 @@ const CGFloat kOWSTable_DefaultCellHeight = 45.f;
return item; return item;
} }
+ (OWSTableItem *)softCenterLabelItemWithText:(NSString *)text
{
OWSAssert(text.length > 0);
OWSTableItem *item = [OWSTableItem new];
item.itemType = OWSTableItemTypeAction;
item.customCellBlock = ^{
UITableViewCell *cell = [UITableViewCell new];
cell.textLabel.text = text;
// These cells look quite different.
//
// Smaller font.
cell.textLabel.font = [UIFont ows_regularFontWithSize:15.f];
// Soft color.
cell.textLabel.textColor = [UIColor colorWithWhite:0.5f alpha:1.f];
// Centered.
cell.textLabel.textAlignment = NSTextAlignmentCenter;
cell.userInteractionEnabled = NO;
return cell;
};
return item;
}
+ (OWSTableItem *)softCenterLabelItemWithText:(NSString *)text customRowHeight:(CGFloat)customRowHeight
{
OWSAssert(customRowHeight > 0);
OWSTableItem *item = [self softCenterLabelItemWithText:text];
item.customRowHeight = @(customRowHeight);
return item;
}
+ (OWSTableItem *)labelItemWithText:(NSString *)text + (OWSTableItem *)labelItemWithText:(NSString *)text
{ {
OWSAssert(text.length > 0); OWSAssert(text.length > 0);

@ -522,17 +522,10 @@ NSString *const kSelectRecipientViewControllerCellIdentifier = @"kSelectRecipien
if (signalAccounts.count == 0) { if (signalAccounts.count == 0) {
// No Contacts // No Contacts
[contactsSection addItem:[OWSTableItem itemWithCustomCellBlock:^{ [contactsSection
UITableViewCell *cell = [UITableViewCell new]; addItem:[OWSTableItem softCenterLabelItemWithText:
cell.textLabel.text = NSLocalizedString( NSLocalizedString(@"SETTINGS_BLOCK_LIST_NO_CONTACTS",
@"SETTINGS_BLOCK_LIST_NO_CONTACTS", @"A label that indicates the user has no Signal contacts."); @"A label that indicates the user has no Signal contacts.")]];
cell.textLabel.font = [UIFont ows_regularFontWithSize:15.f];
cell.textLabel.textColor = [UIColor colorWithWhite:0.5f alpha:1.f];
cell.textLabel.textAlignment = NSTextAlignmentCenter;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
actionBlock:nil]];
} else { } else {
// Contacts // Contacts

@ -175,16 +175,10 @@ NS_ASSUME_NONNULL_BEGIN
} }
if (section.itemCount < 1) { if (section.itemCount < 1) {
[section addItem:[OWSTableItem itemWithCustomCellBlock:^{ [section
UITableViewCell *cell = [UITableViewCell new]; addItem:[OWSTableItem
cell.textLabel.text = NSLocalizedString( softCenterLabelItemWithText:NSLocalizedString(@"SETTINGS_BLOCK_LIST_NO_CONTACTS",
@"SETTINGS_BLOCK_LIST_NO_CONTACTS", @"A label that indicates the user has no Signal contacts."); @"A label that indicates the user has no Signal contacts.")]];
cell.textLabel.font = [UIFont ows_regularFontWithSize:15.f];
cell.textLabel.textColor = [UIColor colorWithWhite:0.5f alpha:1.f];
cell.textLabel.textAlignment = NSTextAlignmentCenter;
return cell;
}
actionBlock:nil]];
} }
[contents addSection:section]; [contents addSection:section];

@ -97,6 +97,8 @@
__weak SettingsTableViewController *weakSelf = self; __weak SettingsTableViewController *weakSelf = self;
[section addItem:[OWSTableItem itemWithCustomCellBlock:^{ [section addItem:[OWSTableItem itemWithCustomCellBlock:^{
UITableViewCell *cell = [UITableViewCell new]; UITableViewCell *cell = [UITableViewCell new];
cell.preservesSuperviewLayoutMargins = YES;
cell.contentView.preservesSuperviewLayoutMargins = YES;
UILabel *titleLabel = [UILabel new]; UILabel *titleLabel = [UILabel new];
titleLabel.font = [UIFont ows_mediumFontWithSize:20.f]; titleLabel.font = [UIFont ows_mediumFontWithSize:20.f];
@ -112,7 +114,7 @@
subtitleLabel.textAlignment = NSTextAlignmentCenter; subtitleLabel.textAlignment = NSTextAlignmentCenter;
UIView *stack = [UIView new]; UIView *stack = [UIView new];
[cell addSubview:stack]; [cell.contentView addSubview:stack];
[stack autoCenterInSuperview]; [stack autoCenterInSuperview];
[stack addSubview:titleLabel]; [stack addSubview:titleLabel];
@ -214,8 +216,7 @@
[cell.contentView addSubview:button]; [cell.contentView addSubview:button];
[button autoSetDimension:ALDimensionHeight toSize:50.f]; [button autoSetDimension:ALDimensionHeight toSize:50.f];
[button autoVCenterInSuperview]; [button autoVCenterInSuperview];
[button autoPinLeadingToSuperView]; [button autoPinLeadingAndTrailingToSuperview];
[button autoPinTrailingToSuperView];
[button addTarget:self action:@selector(unregisterUser) forControlEvents:UIControlEventTouchUpInside]; [button addTarget:self action:@selector(unregisterUser) forControlEvents:UIControlEventTouchUpInside];
cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell; return cell;

@ -239,15 +239,9 @@ NS_ASSUME_NONNULL_BEGIN
section.headerTitle = NSLocalizedString( section.headerTitle = NSLocalizedString(
@"EDIT_GROUP_MEMBERS_SECTION_TITLE", @"a title for the members section of the 'new/update group' view."); @"EDIT_GROUP_MEMBERS_SECTION_TITLE", @"a title for the members section of the 'new/update group' view.");
[section addItem:[OWSTableItem itemWithCustomCellBlock:^{ [section addItem:[OWSTableItem
UITableViewCell *cell = [UITableViewCell new]; disclosureItemWithText:NSLocalizedString(@"EDIT_GROUP_MEMBERS_ADD_MEMBER",
cell.textLabel.text = NSLocalizedString( @"Label for the cell that lets you add a new member to a group.")
@"EDIT_GROUP_MEMBERS_ADD_MEMBER", @"Label for the cell that lets you add a new member to a group.");
cell.textLabel.font = [UIFont ows_regularFontWithSize:18.f];
cell.textLabel.textColor = [UIColor blackColor];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
customRowHeight:[ContactTableViewCell rowHeight] customRowHeight:[ContactTableViewCell rowHeight]
actionBlock:^{ actionBlock:^{
AddToGroupViewController *viewController = [AddToGroupViewController new]; AddToGroupViewController *viewController = [AddToGroupViewController new];

Loading…
Cancel
Save