Rework the profile view.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent d27708497e
commit 3181ee7882

@ -38,8 +38,6 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
@property (nonatomic) UIImageView *cameraImageView; @property (nonatomic) UIImageView *cameraImageView;
@property (nonatomic) UILabel *avatarLabel;
@property (nonatomic, nullable) UIImage *avatar; @property (nonatomic, nullable) UIImage *avatar;
@property (nonatomic) BOOL hasUnsavedChanges; @property (nonatomic) BOOL hasUnsavedChanges;
@ -105,14 +103,6 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
_cameraImageView = [[UIImageView alloc] initWithImage:cameraImage]; _cameraImageView = [[UIImageView alloc] initWithImage:cameraImage];
_cameraImageView.tintColor = [UIColor ows_materialBlueColor]; _cameraImageView.tintColor = [UIColor ows_materialBlueColor];
_avatarLabel = [UILabel new];
_avatarLabel.font = [UIFont ows_regularFontWithSize:14.f];
_avatarLabel.textColor = [UIColor ows_materialBlueColor];
// TODO: Copy.
_avatarLabel.text
= NSLocalizedString(@"PROFILE_VIEW_AVATAR_INSTRUCTIONS", @"Instructions for how to change the profile avatar.");
[_avatarLabel sizeToFit];
[self updateTableContents]; [self updateTableContents];
} }
@ -125,71 +115,115 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
__weak ProfileViewController *weakSelf = self; __weak ProfileViewController *weakSelf = self;
// Profile Avatar // Profile Avatar
OWSTableSection *avatarSection = [OWSTableSection new]; OWSTableSection *section = [OWSTableSection new];
avatarSection.headerTitle = NSLocalizedString( const CGFloat fontSizePoints = ScaleFromIPhone5To7Plus(16.f, 20.f);
@"PROFILE_VIEW_AVATAR_SECTION_HEADER", @"Header title for the profile avatar field of the profile view."); [section addItem:[OWSTableItem itemWithCustomCellBlock:^{
const CGFloat kAvatarSizePoints = 100.f; UITableViewCell *cell = [UITableViewCell new];
const CGFloat kAvatarTopMargin = 10.f; cell.preservesSuperviewLayoutMargins = YES;
const CGFloat kAvatarBottomMargin = 10.f; cell.contentView.preservesSuperviewLayoutMargins = YES;
const CGFloat kAvatarVSpacing = 10.f; cell.selectionStyle = UITableViewCellSelectionStyleNone;
CGFloat avatarCellHeight
= round(kAvatarSizePoints + kAvatarTopMargin + kAvatarBottomMargin + kAvatarVSpacing + self.avatarLabel.height); UILabel *fieldLabel = [UILabel new];
[avatarSection addItem:[OWSTableItem itemWithCustomCellBlock:^{ fieldLabel.text = NSLocalizedString(
@"PROFILE_VIEW_PROFILE_NAME_FIELD", @"Label for the profile name field of the profile view.");
fieldLabel.textColor = [UIColor blackColor];
fieldLabel.font = [UIFont ows_mediumFontWithSize:fontSizePoints];
[cell.contentView addSubview:fieldLabel];
[fieldLabel autoPinLeadingToSuperView];
[fieldLabel autoVCenterInSuperview];
UITextField *nameTextField = weakSelf.nameTextField;
nameTextField.textAlignment = NSTextAlignmentRight;
nameTextField.font = [UIFont ows_mediumFontWithSize:fontSizePoints];
[cell.contentView addSubview:nameTextField];
[nameTextField autoPinLeadingToTrailingOfView:fieldLabel margin:10.f];
[nameTextField autoPinTrailingToSuperView];
[nameTextField autoVCenterInSuperview];
return cell;
}
actionBlock:^{
[weakSelf.nameTextField becomeFirstResponder];
}]];
const CGFloat kAvatarSizePoints = 50.f;
const CGFloat kAvatarVMargin = 4.f;
CGFloat avatarCellHeight = round(kAvatarSizePoints + kAvatarVMargin * 2);
[section addItem:[OWSTableItem itemWithCustomCellBlock:^{
UITableViewCell *cell = [UITableViewCell new]; UITableViewCell *cell = [UITableViewCell new];
cell.preservesSuperviewLayoutMargins = YES; cell.preservesSuperviewLayoutMargins = YES;
cell.contentView.preservesSuperviewLayoutMargins = YES; cell.contentView.preservesSuperviewLayoutMargins = YES;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
UILabel *fieldLabel = [UILabel new];
fieldLabel.text = NSLocalizedString(
@"PROFILE_VIEW_PROFILE_AVATAR_FIELD", @"Label for the profile avatar field of the profile view.");
fieldLabel.textColor = [UIColor blackColor];
fieldLabel.font = [UIFont ows_mediumFontWithSize:fontSizePoints];
[cell.contentView addSubview:fieldLabel];
[fieldLabel autoPinLeadingToSuperView];
[fieldLabel autoVCenterInSuperview];
AvatarImageView *avatarView = weakSelf.avatarView; AvatarImageView *avatarView = weakSelf.avatarView;
UIImageView *cameraImageView = weakSelf.cameraImageView; UIImageView *cameraImageView = weakSelf.cameraImageView;
[cell.contentView addSubview:avatarView]; [cell.contentView addSubview:avatarView];
[cell.contentView addSubview:cameraImageView]; [cell.contentView addSubview:cameraImageView];
[weakSelf updateAvatarView]; [weakSelf updateAvatarView];
[avatarView autoHCenterInSuperview]; [avatarView autoPinTrailingToSuperView];
[avatarView autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:kAvatarTopMargin]; [avatarView autoPinLeadingToTrailingOfView:fieldLabel margin:10.f];
[avatarView autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:kAvatarVMargin];
[avatarView autoSetDimension:ALDimensionWidth toSize:kAvatarSizePoints]; [avatarView autoSetDimension:ALDimensionWidth toSize:kAvatarSizePoints];
[avatarView autoSetDimension:ALDimensionHeight toSize:kAvatarSizePoints]; [avatarView autoSetDimension:ALDimensionHeight toSize:kAvatarSizePoints];
[cameraImageView autoPinTrailingToView:avatarView]; [cameraImageView autoPinTrailingToView:avatarView];
[cameraImageView autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:avatarView]; [cameraImageView autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:avatarView];
UILabel *avatarLabel = weakSelf.avatarLabel; return cell;
[cell.contentView addSubview:avatarLabel]; }
[avatarLabel autoHCenterInSuperview]; customRowHeight:avatarCellHeight
[avatarLabel autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:kAvatarBottomMargin]; actionBlock:^{
[weakSelf avatarTapped];
}]];
UIFont *footnoteFont = [UIFont ows_footnoteFont];
[section addItem:[OWSTableItem itemWithCustomCellBlock:^{
UITableViewCell *cell = [UITableViewCell new];
cell.preservesSuperviewLayoutMargins = YES;
cell.contentView.preservesSuperviewLayoutMargins = YES;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.userInteractionEnabled = YES; UILabel *label = [UILabel new];
[cell label.textColor = [UIColor ows_darkGrayColor];
addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(avatarTapped:)]]; label.font = footnoteFont;
label.textAlignment = NSTextAlignmentCenter;
NSMutableAttributedString *text = [NSMutableAttributedString new];
[text appendAttributedString:[[NSAttributedString alloc]
initWithString:NSLocalizedString(@"PROFILE_VIEW_PROFILE_DESCRIPTION",
@"Description of the user profile.")
attributes:@{}]];
[text appendAttributedString:[[NSAttributedString alloc] initWithString:@" " attributes:@{}]];
[text appendAttributedString:[[NSAttributedString alloc]
initWithString:NSLocalizedString(@"PROFILE_VIEW_PROFILE_DESCRIPTION_LINK",
@"Link to more information about the user profile.")
attributes:@{
NSUnderlineStyleAttributeName :
@(NSUnderlineStyleSingle | NSUnderlinePatternSolid),
NSForegroundColorAttributeName : [UIColor ows_materialBlueColor],
}]];
label.attributedText = text;
label.numberOfLines = 0;
label.lineBreakMode = NSLineBreakByWordWrapping;
[cell.contentView addSubview:label];
[label autoPinLeadingToSuperView];
[label autoPinTrailingToSuperView];
[label autoVCenterInSuperview];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell; return cell;
} }
customRowHeight:avatarCellHeight customRowHeight:footnoteFont.lineHeight * 5
actionBlock:nil]]; actionBlock:^{
[contents addSection:avatarSection]; [weakSelf openProfileInfoURL];
}]];
// Profile Name [contents addSection:section];
OWSTableSection *nameSection = [OWSTableSection new];
nameSection.headerTitle = NSLocalizedString(
@"PROFILE_VIEW_NAME_SECTION_HEADER", @"Label for the profile name field of the profile view.");
[nameSection
addItem:
[OWSTableItem
itemWithCustomCellBlock:^{
UITableViewCell *cell = [UITableViewCell new];
cell.preservesSuperviewLayoutMargins = YES;
cell.contentView.preservesSuperviewLayoutMargins = YES;
UITextField *nameTextField = weakSelf.nameTextField;
[cell.contentView addSubview:nameTextField];
[nameTextField autoPinLeadingToSuperView];
[nameTextField autoPinTrailingToSuperView];
[nameTextField autoVCenterInSuperview];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
actionBlock:nil]];
[contents addSection:nameSection];
self.contents = contents; self.contents = contents;
} }
@ -232,11 +266,9 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
[self presentViewController:controller animated:YES completion:nil]; [self presentViewController:controller animated:YES completion:nil];
} }
- (void)avatarTapped:(UIGestureRecognizer *)sender - (void)avatarTapped
{ {
if (sender.state == UIGestureRecognizerStateRecognized) { [self.avatarViewHelper showChangeAvatarUI];
[self.avatarViewHelper showChangeAvatarUI];
}
} }
- (void)setHasUnsavedChanges:(BOOL)hasUnsavedChanges - (void)setHasUnsavedChanges:(BOOL)hasUnsavedChanges
@ -363,6 +395,12 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
OWSAssert([navigationController.topViewController isKindOfClass:[SignalsViewController class]]); OWSAssert([navigationController.topViewController isKindOfClass:[SignalsViewController class]]);
} }
- (void)openProfileInfoURL
{
[UIApplication.sharedApplication
openURL:[NSURL URLWithString:@"https://support.whispersystems.org/hc/en-us/articles/115001110511"]];
}
#pragma mark - UITextFieldDelegate #pragma mark - UITextFieldDelegate
- (BOOL)textField:(UITextField *)textField - (BOOL)textField:(UITextField *)textField

@ -1084,12 +1084,6 @@
/* Action Sheet title prompting the user for a profile avatar */ /* Action Sheet title prompting the user for a profile avatar */
"PROFILE_VIEW_AVATAR_ACTIONSHEET_TITLE" = "Set Profile Avatar"; "PROFILE_VIEW_AVATAR_ACTIONSHEET_TITLE" = "Set Profile Avatar";
/* Instructions for how to change the profile avatar. */
"PROFILE_VIEW_AVATAR_INSTRUCTIONS" = "Tap to Select Avatar";
/* Header title for the profile avatar field of the profile view. */
"PROFILE_VIEW_AVATAR_SECTION_HEADER" = "Avatar";
/* Label for action that clear's the user's profile avatar */ /* Label for action that clear's the user's profile avatar */
"PROFILE_VIEW_CLEAR_AVATAR" = "Clear Avatar"; "PROFILE_VIEW_CLEAR_AVATAR" = "Clear Avatar";
@ -1097,10 +1091,19 @@
"PROFILE_VIEW_ERROR_UPDATE_FAILED" = "Profile update failed."; "PROFILE_VIEW_ERROR_UPDATE_FAILED" = "Profile update failed.";
/* Default text for the profile name field of the profile view. */ /* Default text for the profile name field of the profile view. */
"PROFILE_VIEW_NAME_DEFAULT_TEXT" = "Enter your name."; "PROFILE_VIEW_NAME_DEFAULT_TEXT" = "Enter your name";
/* Label for the profile avatar field of the profile view. */
"PROFILE_VIEW_PROFILE_AVATAR_FIELD" = "Avatar";
/* Description of the user profile. */
"PROFILE_VIEW_PROFILE_DESCRIPTION" = "Your profile affects how you will appear to other users if you are not in their contacts.";
/* Link to more information about the user profile. */
"PROFILE_VIEW_PROFILE_DESCRIPTION_LINK" = "Click here to learn more.";
/* Label for the profile name field of the profile view. */ /* Label for the profile name field of the profile view. */
"PROFILE_VIEW_NAME_SECTION_HEADER" = "Profile Name"; "PROFILE_VIEW_PROFILE_NAME_FIELD" = "Profile Name";
/* Alert title that indicates the user's profile view is being saved. */ /* Alert title that indicates the user's profile view is being saved. */
"PROFILE_VIEW_SAVING" = "Saving..."; "PROFILE_VIEW_SAVING" = "Saving...";

Loading…
Cancel
Save