fix a million retain cycles in conversation settings

pull/1/head
Michael Kirk 7 years ago
parent 8eff8966b4
commit 542d5826de

@ -347,30 +347,40 @@ const CGFloat kIconViewLength = 24;
} }
if ([OWSProfileManager.sharedManager isThreadInProfileWhitelist:self.thread]) { if ([OWSProfileManager.sharedManager isThreadInProfileWhitelist:self.thread]) {
[mainSection addItem:[OWSTableItem itemWithCustomCellBlock:^{ [mainSection
return [weakSelf addItem:[OWSTableItem
labelCellWithName:(self.isGroupThread itemWithCustomCellBlock:^{
? NSLocalizedString( OWSConversationSettingsViewController *strongSelf = weakSelf;
@"CONVERSATION_SETTINGS_VIEW_PROFILE_IS_SHARED_WITH_GROUP", OWSCAssertDebug(strongSelf);
@"Indicates that user's profile has been shared with a group.")
: NSLocalizedString(@"CONVERSATION_SETTINGS_VIEW_PROFILE_IS_SHARED_WITH_USER", return [strongSelf
@"Indicates that user's profile has been shared with a user."))iconName labelCellWithName:
:@"table_ic_share_profile"]; (strongSelf.isGroupThread
} ? NSLocalizedString(
actionBlock:nil]]; @"CONVERSATION_SETTINGS_VIEW_PROFILE_IS_SHARED_WITH_GROUP",
@"Indicates that user's profile has been shared with a group.")
: NSLocalizedString(
@"CONVERSATION_SETTINGS_VIEW_PROFILE_IS_SHARED_WITH_USER",
@"Indicates that user's profile has been shared with a user."))
iconName:@"table_ic_share_profile"];
}
actionBlock:nil]];
} else { } else {
[mainSection [mainSection
addItem:[OWSTableItem addItem:[OWSTableItem
itemWithCustomCellBlock:^{ itemWithCustomCellBlock:^{
UITableViewCell *cell = [weakSelf OWSConversationSettingsViewController *strongSelf = weakSelf;
OWSCAssertDebug(strongSelf);
UITableViewCell *cell = [strongSelf
disclosureCellWithName: disclosureCellWithName:
(self.isGroupThread (strongSelf.isGroupThread
? NSLocalizedString(@"CONVERSATION_SETTINGS_VIEW_SHARE_PROFILE_WITH_GROUP", ? NSLocalizedString(@"CONVERSATION_SETTINGS_VIEW_SHARE_PROFILE_WITH_GROUP",
@"Action that shares user profile with a group.") @"Action that shares user profile with a group.")
: NSLocalizedString(@"CONVERSATION_SETTINGS_VIEW_SHARE_PROFILE_WITH_USER", : NSLocalizedString(@"CONVERSATION_SETTINGS_VIEW_SHARE_PROFILE_WITH_USER",
@"Action that shares user profile with a user.")) @"Action that shares user profile with a user."))
iconName:@"table_ic_share_profile"]; iconName:@"table_ic_share_profile"];
cell.userInteractionEnabled = !weakSelf.hasLeftGroup; cell.userInteractionEnabled = !strongSelf.hasLeftGroup;
return cell; return cell;
} }
@ -408,7 +418,7 @@ const CGFloat kIconViewLength = 24;
UIStackView *topRow = UIStackView *topRow =
[[UIStackView alloc] initWithArrangedSubviews:@[ iconView, rowLabel, switchView ]]; [[UIStackView alloc] initWithArrangedSubviews:@[ iconView, rowLabel, switchView ]];
topRow.spacing = self.iconSpacing; topRow.spacing = strongSelf.iconSpacing;
topRow.alignment = UIStackViewAlignmentCenter; topRow.alignment = UIStackViewAlignmentCenter;
[cell.contentView addSubview:topRow]; [cell.contentView addSubview:topRow];
[topRow autoPinEdgesToSuperviewMarginsExcludingEdge:ALEdgeBottom]; [topRow autoPinEdgesToSuperviewMarginsExcludingEdge:ALEdgeBottom];
@ -455,7 +465,7 @@ const CGFloat kIconViewLength = 24;
UIStackView *topRow = UIStackView *topRow =
[[UIStackView alloc] initWithArrangedSubviews:@[ iconView, rowLabel ]]; [[UIStackView alloc] initWithArrangedSubviews:@[ iconView, rowLabel ]];
topRow.spacing = self.iconSpacing; topRow.spacing = strongSelf.iconSpacing;
topRow.alignment = UIStackViewAlignmentCenter; topRow.alignment = UIStackViewAlignmentCenter;
[cell.contentView addSubview:topRow]; [cell.contentView addSubview:topRow];
[topRow autoPinEdgesToSuperviewMarginsExcludingEdge:ALEdgeBottom]; [topRow autoPinEdgesToSuperviewMarginsExcludingEdge:ALEdgeBottom];
@ -485,13 +495,17 @@ const CGFloat kIconViewLength = 24;
[mainSection [mainSection
addItem:[OWSTableItem addItem:[OWSTableItem
itemWithCustomCellBlock:^{ itemWithCustomCellBlock:^{
ConversationColorName colorName = self.thread.conversationColorName; OWSConversationSettingsViewController *strongSelf = weakSelf;
OWSCAssertDebug(strongSelf);
ConversationColorName colorName = strongSelf.thread.conversationColorName;
UIColor *currentColor = UIColor *currentColor =
[OWSConversationColor conversationColorOrDefaultForColorName:colorName].themeColor; [OWSConversationColor conversationColorOrDefaultForColorName:colorName].themeColor;
NSString *title = NSLocalizedString(@"CONVERSATION_SETTINGS_CONVERSATION_COLOR", NSString *title = NSLocalizedString(@"CONVERSATION_SETTINGS_CONVERSATION_COLOR",
@"Label for table cell which leads to picking a new conversation color"); @"Label for table cell which leads to picking a new conversation color");
return return [strongSelf cellWithName:title
[weakSelf cellWithName:title iconName:@"ic_color_palette" disclosureIconColor:currentColor]; iconName:@"ic_color_palette"
disclosureIconColor:currentColor];
} }
actionBlock:^{ actionBlock:^{
[weakSelf showColorPicker]; [weakSelf showColorPicker];
@ -578,12 +592,12 @@ const CGFloat kIconViewLength = 24;
UIStackView *contentRow = UIStackView *contentRow =
[[UIStackView alloc] initWithArrangedSubviews:@[ iconView, rowLabel ]]; [[UIStackView alloc] initWithArrangedSubviews:@[ iconView, rowLabel ]];
contentRow.spacing = self.iconSpacing; contentRow.spacing = strongSelf.iconSpacing;
contentRow.alignment = UIStackViewAlignmentCenter; contentRow.alignment = UIStackViewAlignmentCenter;
[cell.contentView addSubview:contentRow]; [cell.contentView addSubview:contentRow];
[contentRow autoPinEdgesToSuperviewMargins]; [contentRow autoPinEdgesToSuperviewMargins];
OWSSound sound = [OWSSounds notificationSoundForThread:self.thread]; OWSSound sound = [OWSSounds notificationSoundForThread:strongSelf.thread];
cell.detailTextLabel.text = [OWSSounds displayNameForSound:sound]; cell.detailTextLabel.text = [OWSSounds displayNameForSound:sound];
return cell; return cell;
} }
@ -646,7 +660,7 @@ const CGFloat kIconViewLength = 24;
UIStackView *contentRow = UIStackView *contentRow =
[[UIStackView alloc] initWithArrangedSubviews:@[ iconView, rowLabel ]]; [[UIStackView alloc] initWithArrangedSubviews:@[ iconView, rowLabel ]];
contentRow.spacing = self.iconSpacing; contentRow.spacing = strongSelf.iconSpacing;
contentRow.alignment = UIStackViewAlignmentCenter; contentRow.alignment = UIStackViewAlignmentCenter;
[cell.contentView addSubview:contentRow]; [cell.contentView addSubview:contentRow];
[contentRow autoPinEdgesToSuperviewMargins]; [contentRow autoPinEdgesToSuperviewMargins];
@ -681,7 +695,7 @@ const CGFloat kIconViewLength = 24;
} }
NSString *cellTitle; NSString *cellTitle;
if (self.thread.isGroupThread) { if (strongSelf.thread.isGroupThread) {
cellTitle = NSLocalizedString(@"CONVERSATION_SETTINGS_BLOCK_THIS_GROUP", cellTitle = NSLocalizedString(@"CONVERSATION_SETTINGS_BLOCK_THIS_GROUP",
@"table cell label in conversation settings"); @"table cell label in conversation settings");
} else { } else {
@ -694,7 +708,8 @@ const CGFloat kIconViewLength = 24;
cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.selectionStyle = UITableViewCellSelectionStyleNone;
UISwitch *blockConversationSwitch = [UISwitch new]; UISwitch *blockConversationSwitch = [UISwitch new];
blockConversationSwitch.on = [strongSelf.blockingManager isThreadBlocked:self.thread]; blockConversationSwitch.on =
[strongSelf.blockingManager isThreadBlocked:strongSelf.thread];
[blockConversationSwitch addTarget:strongSelf [blockConversationSwitch addTarget:strongSelf
action:@selector(blockConversationSwitchDidChange:) action:@selector(blockConversationSwitchDidChange:)
forControlEvents:UIControlEventValueChanged]; forControlEvents:UIControlEventValueChanged];

Loading…
Cancel
Save