Start reworking the contact offers.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent a825fad47b
commit 265bdce0ba

@ -4253,7 +4253,8 @@ typedef enum : NSUInteger {
// Show any top/bottom labels for all but the unread indicator // Show any top/bottom labels for all but the unread indicator
// //
// TODO: What about the contact offers? // TODO: What about the contact offers?
return ![interaction isKindOfClass:[TSUnreadIndicatorInteraction class]]; return !([interaction isKindOfClass:[TSUnreadIndicatorInteraction class]] ||
[interaction isKindOfClass:[OWSContactOffersInteraction class]]);
} }
#pragma mark - Database Observation #pragma mark - Database Observation

@ -16,13 +16,16 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, nullable) OWSContactOffersInteraction *interaction; @property (nonatomic, nullable) OWSContactOffersInteraction *interaction;
@property (nonatomic) UILabel *messageLabel;
@property (nonatomic) UIView *bannerView;
@property (nonatomic) UIView *bannerTopHighlightView;
@property (nonatomic) UIView *bannerBottomHighlightView1;
@property (nonatomic) UIView *bannerBottomHighlightView2;
@property (nonatomic) UILabel *titleLabel; @property (nonatomic) UILabel *titleLabel;
@property (nonatomic) UILabel *subtitleLabel; @property (nonatomic) UIButton *addToContactsButton;
@property (nonatomic) UIButton *addToProfileWhitelistButton;
@property (nonatomic) UIButton *blockButton;
//@property (nonatomic) UIView *bannerView;
//@property (nonatomic) UIView *bannerTopHighlightView;
//@property (nonatomic) UIView *bannerBottomHighlightView1;
//@property (nonatomic) UIView *bannerBottomHighlightView2;
//@property (nonatomic) UILabel *titleLabel;
//@property (nonatomic) UILabel *subtitleLabel;
@end @end
@ -42,47 +45,82 @@ NS_ASSUME_NONNULL_BEGIN
- (void)commontInit - (void)commontInit
{ {
OWSAssert(!self.bannerView); OWSAssert(!self.titleLabel);
[self setTranslatesAutoresizingMaskIntoConstraints:NO]; [self setTranslatesAutoresizingMaskIntoConstraints:NO];
self.backgroundColor = [UIColor whiteColor]; // self.backgroundColor = [UIColor whiteColor];
self.bannerView = [UIView new];
self.bannerView.backgroundColor = [UIColor colorWithRGBHex:0xf6eee3];
[self.contentView addSubview:self.bannerView];
self.bannerTopHighlightView = [UIView new];
self.bannerTopHighlightView.backgroundColor = [UIColor colorWithRGBHex:0xf9f3eb];
[self.bannerView addSubview:self.bannerTopHighlightView];
self.bannerBottomHighlightView1 = [UIView new];
self.bannerBottomHighlightView1.backgroundColor = [UIColor colorWithRGBHex:0xd1c6b8];
[self.bannerView addSubview:self.bannerBottomHighlightView1];
self.bannerBottomHighlightView2 = [UIView new];
self.bannerBottomHighlightView2.backgroundColor = [UIColor colorWithRGBHex:0xdbcfc0];
[self.bannerView addSubview:self.bannerBottomHighlightView2];
self.titleLabel = [UILabel new]; self.titleLabel = [UILabel new];
self.titleLabel.textColor = [UIColor colorWithRGBHex:0x403e3b]; self.titleLabel.textColor = [UIColor blackColor];
self.titleLabel.font = [self titleFont]; self.titleLabel.font = [self titleFont];
[self.bannerView addSubview:self.titleLabel]; self.titleLabel.text = NSLocalizedString(@"CONVERSATION_VIEW_CONTACTS_OFFER_TITLE",
@"Title for the group of buttons show for unknown contacts offering to add them to contacts, etc.");
self.subtitleLabel = [UILabel new];
self.subtitleLabel.textColor = [UIColor ows_infoMessageBorderColor];
self.subtitleLabel.font = [self subtitleFont];
// The subtitle may wrap to a second line. // The subtitle may wrap to a second line.
self.subtitleLabel.numberOfLines = 0; self.titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
self.subtitleLabel.lineBreakMode = NSLineBreakByWordWrapping; self.titleLabel.textAlignment = NSTextAlignmentCenter;
self.subtitleLabel.textAlignment = NSTextAlignmentCenter; [self.contentView addSubview:self.titleLabel];
[self.contentView addSubview:self.subtitleLabel];
self.addToContactsButton = [self
createButtonWithTitle:
NSLocalizedString(@"CONVERSATION_VIEW_ADD_TO_CONTACTS_OFFER",
@"Message shown in conversation view that offers to add an unknown user to your phone's contacts.")];
self.addToProfileWhitelistButton =
[self createButtonWithTitle:
NSLocalizedString(@"CONVERSATION_VIEW_ADD_USER_TO_PROFILE_WHITELIST_OFFER",
@"Message shown in conversation view that offers to share your profile with a user.")];
self.blockButton =
[self createButtonWithTitle:NSLocalizedString(@"CONVERSATION_VIEW_UNKNOWN_CONTACT_BLOCK_OFFER",
@"Message shown in conversation view that offers to block an unknown user.")];
// self.bannerView = [UIView new];
// self.bannerView.backgroundColor = [UIColor colorWithRGBHex:0xf6eee3];
// [self.contentView addSubview:self.bannerView];
//
// self.bannerTopHighlightView = [UIView new];
// self.bannerTopHighlightView.backgroundColor = [UIColor colorWithRGBHex:0xf9f3eb];
// [self.bannerView addSubview:self.bannerTopHighlightView];
//
// self.bannerBottomHighlightView1 = [UIView new];
// self.bannerBottomHighlightView1.backgroundColor = [UIColor colorWithRGBHex:0xd1c6b8];
// [self.bannerView addSubview:self.bannerBottomHighlightView1];
//
// self.bannerBottomHighlightView2 = [UIView new];
// self.bannerBottomHighlightView2.backgroundColor = [UIColor colorWithRGBHex:0xdbcfc0];
// [self.bannerView addSubview:self.bannerBottomHighlightView2];
//
// self.titleLabel = [UILabel new];
// self.titleLabel.textColor = [UIColor colorWithRGBHex:0x403e3b];
// self.titleLabel.font = [self titleFont];
// [self.bannerView addSubview:self.titleLabel];
//
// self.subtitleLabel = [UILabel new];
// self.subtitleLabel.textColor = [UIColor ows_infoMessageBorderColor];
// self.subtitleLabel.font = [self subtitleFont];
// // The subtitle may wrap to a second line.
// self.subtitleLabel.numberOfLines = 0;
// self.subtitleLabel.lineBreakMode = NSLineBreakByWordWrapping;
// self.subtitleLabel.textAlignment = NSTextAlignmentCenter;
// [self.contentView addSubview:self.subtitleLabel];
UITapGestureRecognizer *tap = UITapGestureRecognizer *tap =
[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)]; [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
[self addGestureRecognizer:tap]; [self addGestureRecognizer:tap];
} }
- (UIButton *)createButtonWithTitle:(NSString *)title
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setTitle:title forState:UIControlStateNormal];
[button setTitleColor:[UIColor ows_materialBlueColor] forState:UIControlStateNormal];
button.titleLabel.font = self.buttonFont;
button.titleLabel.textAlignment = NSTextAlignmentCenter;
[button setBackgroundColor:[UIColor colorWithRGBHex:0xf5f5f5]];
button.layer.cornerRadius = 5.f;
[self.contentView addSubview:button];
return button;
}
+ (NSString *)cellReuseIdentifier + (NSString *)cellReuseIdentifier
{ {
return NSStringFromClass([self class]); return NSStringFromClass([self class]);
@ -94,143 +132,122 @@ NS_ASSUME_NONNULL_BEGIN
_interaction = interaction; _interaction = interaction;
self.titleLabel.text = [self titleForInteraction:self.interaction]; OWSAssert(
self.subtitleLabel.text = [self subtitleForInteraction:self.interaction]; interaction.hasBlockOffer || interaction.hasAddToContactsOffer || interaction.hasAddToProfileWhitelistOffer);
self.backgroundColor = [UIColor whiteColor];
[self setNeedsLayout]; [self setNeedsLayout];
} }
- (UIFont *)titleFont - (UIFont *)titleFont
{ {
return [UIFont ows_regularFontWithSize:16.f]; return [UIFont ows_mediumFontWithSize:16.f];
} }
- (UIFont *)subtitleFont - (UIFont *)buttonFont
{ {
return [UIFont ows_regularFontWithSize:12.f]; return [UIFont ows_regularFontWithSize:14.f];
} }
- (NSString *)titleForInteraction:(OWSContactOffersInteraction *)interaction - (CGFloat)hMargin
{ {
return NSLocalizedString(@"MESSAGES_VIEW_UNREAD_INDICATOR", @"Indicator that separates read from unread messages.") return 10.f;
.uppercaseString;
} }
- (NSString *)subtitleForInteraction:(OWSContactOffersInteraction *)interaction - (CGFloat)topVMargin
{ {
return nil; return 5.f;
// if (!interaction.hasMoreUnseenMessages) {
// return nil;
// }
// NSString *subtitleFormat = (interaction.missingUnseenSafetyNumberChangeCount > 0
// ? NSLocalizedString(@"MESSAGES_VIEW_UNREAD_INDICATOR_HAS_MORE_UNSEEN_MESSAGES_FORMAT",
// @"Messages that indicates that there are more unseen messages that be revealed by tapping the
// 'load "
// @"earlier messages' button. Embeds {{the name of the 'load earlier messages' button}}")
// : NSLocalizedString(
// @"MESSAGES_VIEW_UNREAD_INDICATOR_HAS_MORE_UNSEEN_MESSAGES_AND_SAFETY_NUMBER_CHANGES_FORMAT",
// @"Messages that indicates that there are more unseen messages including safety number changes
// that "
// @"be revealed by tapping the 'load earlier messages' button. Embeds {{the name of the 'load
// earlier "
// @"messages' button}}."));
// NSString *loadMoreButtonName = [NSBundle jsq_localizedStringForKey:@"load_earlier_messages"];
// return [NSString stringWithFormat:subtitleFormat, loadMoreButtonName];
} }
- (CGFloat)subtitleHMargin - (CGFloat)bottomVMargin
{ {
return 20.f; return 5.f;
} }
- (CGFloat)subtitleVSpacing - (CGFloat)buttonVPadding
{ {
return 3.f; return 5.f;
} }
- (CGFloat)titleInnerHMargin - (CGFloat)buttonVSpacing
{ {
return 10.f; return 5.f;
} }
- (CGFloat)titleVMargin - (void)setFrame:(CGRect)frame
{ {
return 5.5f; BOOL needsLayout = !CGSizeEqualToSize(frame.size, self.frame.size);
} [super setFrame:frame];
- (CGFloat)topVMargin if (needsLayout) {
{ [self layoutSubviews];
return 5.f; }
} }
- (CGFloat)bottomVMargin - (void)setBounds:(CGRect)bounds
{ {
return 5.f; BOOL needsLayout = !CGSizeEqualToSize(bounds.size, self.bounds.size);
[super setBounds:bounds];
if (needsLayout) {
[self layoutSubviews];
}
} }
- (void)layoutSubviews - (void)layoutSubviews
{ {
[super layoutSubviews]; [super layoutSubviews];
[self.titleLabel sizeToFit]; // JSQ won't
CGFloat contentWidth = floor(MIN(self.contentView.width, self.width - 2 * self.contentView.left));
// It's a bit of a hack, but we use a view that extends _outside_ the cell's bounds
// to draw its background, since we want the background to extend to the edges of the DDLogError(@"---- %f %f %f %f", self.width, self.contentView.width, contentWidth, self.contentView.left);
// collection view.
// CGRect titleFrame = self.contentView.bounds;
// This layout logic assumes that the cell insets are symmetrical and can be deduced titleFrame.origin = CGPointMake(self.hMargin, self.topVMargin);
// from the cell frame. titleFrame.size.width = contentWidth - 2 * self.hMargin;
CGRect bannerViewFrame = CGRectMake(-self.left, titleFrame.size.height = ceil([self.titleLabel sizeThatFits:CGSizeZero].height);
round(self.topVMargin), self.titleLabel.frame = titleFrame;
round(self.width + self.left * 2.f),
round(self.titleLabel.height + self.titleVMargin * 2.f)); __block CGFloat y = round(self.titleLabel.bottom + self.buttonVSpacing);
self.bannerView.frame = [self convertRect:bannerViewFrame toView:self.contentView]; DDLogError(@"first y: %f", y);
void (^layoutButton)(UIButton *, BOOL) = ^(UIButton *button, bool isVisible) {
// The highlights should be 1px (not 1pt), so adapt their thickness to if (isVisible) {
// the device resolution. button.hidden = NO;
CGFloat kHighlightThickness = 1.f / [UIScreen mainScreen].scale;
self.bannerTopHighlightView.frame = CGRectMake(0, 0, self.bannerView.width, kHighlightThickness); button.frame = CGRectMake(round(self.hMargin),
self.bannerBottomHighlightView1.frame round(y),
= CGRectMake(0, self.bannerView.height - kHighlightThickness * 2.f, self.bannerView.width, kHighlightThickness); floor(contentWidth - 2 * self.hMargin),
self.bannerBottomHighlightView2.frame ceil([button sizeThatFits:CGSizeZero].height + self.buttonVPadding));
= CGRectMake(0, self.bannerView.height - kHighlightThickness * 1.f, self.bannerView.width, kHighlightThickness); y = round(button.bottom + self.buttonVSpacing);
} else {
[self.titleLabel centerOnSuperview]; button.hidden = YES;
}
if (self.subtitleLabel.text.length > 0) { };
CGSize subtitleSize = [self.subtitleLabel
sizeThatFits:CGSizeMake(self.contentView.width - [self subtitleHMargin] * 2.f, CGFLOAT_MAX)]; layoutButton(self.addToContactsButton, self.interaction.hasAddToContactsOffer);
self.subtitleLabel.frame = CGRectMake(round((self.contentView.width - subtitleSize.width) * 0.5f), layoutButton(self.addToProfileWhitelistButton, self.interaction.hasAddToProfileWhitelistOffer);
round(self.bannerView.bottom + self.subtitleVSpacing), layoutButton(self.blockButton, self.interaction.hasBlockOffer);
ceil(subtitleSize.width),
ceil(subtitleSize.height)); [self.contentView addRedBorder];
} [self.titleLabel addRedBorder];
[self.addToContactsButton addRedBorder];
[self.addToProfileWhitelistButton addRedBorder];
[self.blockButton addRedBorder];
} }
- (CGSize)bubbleSizeForInteraction:(OWSContactOffersInteraction *)interaction - (CGSize)bubbleSizeForInteraction:(OWSContactOffersInteraction *)interaction
collectionViewWidth:(CGFloat)collectionViewWidth collectionViewWidth:(CGFloat)collectionViewWidth
{ {
CGSize result = CGSizeMake(collectionViewWidth, 0); CGSize result = CGSizeMake(collectionViewWidth, 0);
result.height += self.titleVMargin * 2.f;
result.height += self.topVMargin; result.height += self.topVMargin;
result.height += self.bottomVMargin; result.height += self.bottomVMargin;
NSString *title = [self titleForInteraction:interaction];
NSString *subtitle = [self subtitleForInteraction:interaction];
self.titleLabel.text = title;
result.height += ceil([self.titleLabel sizeThatFits:CGSizeZero].height); result.height += ceil([self.titleLabel sizeThatFits:CGSizeZero].height);
if (subtitle.length > 0) { int buttonCount = ((interaction.hasBlockOffer ? 1 : 0) + (interaction.hasAddToContactsOffer ? 1 : 0)
result.height += self.subtitleVSpacing; + (interaction.hasAddToProfileWhitelistOffer ? 1 : 0));
result.height += buttonCount
self.subtitleLabel.text = subtitle; * (self.buttonVPadding + self.buttonVSpacing + ceil([self.addToContactsButton sizeThatFits:CGSizeZero].height));
result.height += ceil(
[self.subtitleLabel sizeThatFits:CGSizeMake(collectionViewWidth - self.subtitleHMargin * 2.f, CGFLOAT_MAX)]
.height);
}
return result; return result;
} }
@ -244,11 +261,13 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Gesture recognizers #pragma mark - Gesture recognizers
- (void)handleTapGesture:(UITapGestureRecognizer *)tap - (void)handleTapGesture:(UITapGestureRecognizer *)sender
{ {
OWSAssert(self.interaction); OWSAssert(self.interaction);
// [self.systemMessageCellDelegate didTapSystemMessageWithInteraction:self.interaction]; if (sender.state == UIGestureRecognizerStateRecognized) {
// [self.systemMessageCellDelegate didTapSystemMessageWithInteraction:self.interaction];
}
} }
#pragma mark - Logging #pragma mark - Logging

@ -314,11 +314,13 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Gesture recognizers #pragma mark - Gesture recognizers
- (void)handleTapGesture:(UITapGestureRecognizer *)tap - (void)handleTapGesture:(UITapGestureRecognizer *)sender
{ {
OWSAssert(self.interaction); OWSAssert(self.interaction);
[self.systemMessageCellDelegate didTapSystemMessageWithInteraction:self.interaction]; if (sender.state == UIGestureRecognizerStateRecognized) {
[self.systemMessageCellDelegate didTapSystemMessageWithInteraction:self.interaction];
}
} }
- (void)handleLongPressGesture:(UILongPressGestureRecognizer *)longPress - (void)handleLongPressGesture:(UILongPressGestureRecognizer *)longPress

@ -364,6 +364,18 @@
/* Action that shares user profile with a user. */ /* Action that shares user profile with a user. */
"CONVERSATION_SETTINGS_VIEW_SHARE_PROFILE_WITH_USER" = "Share Your Profile"; "CONVERSATION_SETTINGS_VIEW_SHARE_PROFILE_WITH_USER" = "Share Your Profile";
/* Message shown in conversation view that offers to add an unknown user to your phone's contacts. */
"CONVERSATION_VIEW_ADD_TO_CONTACTS_OFFER" = "Add to Contacts";
/* Message shown in conversation view that offers to share your profile with a user. */
"CONVERSATION_VIEW_ADD_USER_TO_PROFILE_WHITELIST_OFFER" = "Share Your Profile With This User";
/* Title for the group of buttons show for unknown contacts offering to add them to contacts, etc. */
"CONVERSATION_VIEW_CONTACTS_OFFER_TITLE" = "This user is not in your contacts.";
/* Message shown in conversation view that offers to block an unknown user. */
"CONVERSATION_VIEW_UNKNOWN_CONTACT_BLOCK_OFFER" = "Block This User";
/* ActionSheet title */ /* ActionSheet title */
"CORRUPTED_SESSION_DESCRIPTION" = "Resetting your session will allow you to receive future messages from %@, but it will not recover any already corrupted messages."; "CORRUPTED_SESSION_DESCRIPTION" = "Resetting your session will allow you to receive future messages from %@, but it will not recover any already corrupted messages.";
@ -808,13 +820,20 @@
/* The subtitle for the messages view title indicates that the title can be tapped to access settings for this conversation. */ /* The subtitle for the messages view title indicates that the title can be tapped to access settings for this conversation. */
"MESSAGES_VIEW_TITLE_SUBTITLE" = "Tap here for settings"; "MESSAGES_VIEW_TITLE_SUBTITLE" = "Tap here for settings";
/* Indicator that separates read from unread messages. */ /* Indicator that separates read from unread
// messages.
Indicator that separates read from unread messages. */
"MESSAGES_VIEW_UNREAD_INDICATOR" = "Unread Messages"; "MESSAGES_VIEW_UNREAD_INDICATOR" = "Unread Messages";
/* Messages that indicates that there are more unseen messages including safety number changes that be revealed by tapping the 'load earlier messages' button. Embeds {{the name of the 'load earlier messages' button}}. */ /* Messages that indicates that there are more unseen messages including safety number changes
// // that be revealed by tapping the 'load earlier messages' button. Embeds {{the name of the 'load
// // earlier messages' button}}.
Messages that indicates that there are more unseen messages including safety number changes that be revealed by tapping the 'load earlier messages' button. Embeds {{the name of the 'load earlier messages' button}}. */
"MESSAGES_VIEW_UNREAD_INDICATOR_HAS_MORE_UNSEEN_MESSAGES_AND_SAFETY_NUMBER_CHANGES_FORMAT" = "There are more unread messages (including safety number changes) above. Tap \"%@\" to see them."; "MESSAGES_VIEW_UNREAD_INDICATOR_HAS_MORE_UNSEEN_MESSAGES_AND_SAFETY_NUMBER_CHANGES_FORMAT" = "There are more unread messages (including safety number changes) above. Tap \"%@\" to see them.";
/* Messages that indicates that there are more unseen messages that be revealed by tapping the 'load earlier messages' button. Embeds {{the name of the 'load earlier messages' button}} */ /* Messages that indicates that there are more unseen messages that be revealed by tapping the
// // 'load earlier messages' button. Embeds {{the name of the 'load earlier messages' button}}
Messages that indicates that there are more unseen messages that be revealed by tapping the 'load earlier messages' button. Embeds {{the name of the 'load earlier messages' button}} */
"MESSAGES_VIEW_UNREAD_INDICATOR_HAS_MORE_UNSEEN_MESSAGES_FORMAT" = "There are more unread messages above. Tap \"%@\" to see them."; "MESSAGES_VIEW_UNREAD_INDICATOR_HAS_MORE_UNSEEN_MESSAGES_FORMAT" = "There are more unread messages above. Tap \"%@\" to see them.";
/* notification title */ /* notification title */

Loading…
Cancel
Save