Rework save/cancel buttons in profile view.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent afd530af1e
commit 68309eb00f

@ -437,6 +437,8 @@ typedef enum : NSUInteger {
// We'd like to include at least N seen messages, if possible, // We'd like to include at least N seen messages, if possible,
// to give the user the context of where they left off the conversation. // to give the user the context of where they left off the conversation.
//
// TODO: Is this still necessary?
const int kPreferredSeenMessageCount = 1; const int kPreferredSeenMessageCount = 1;
self.page = (NSUInteger)MAX(0, self.page = (NSUInteger)MAX(0,
MIN(kYapDatabaseMaxInitialPageCount - 1, MIN(kYapDatabaseMaxInitialPageCount - 1,

@ -38,7 +38,7 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
@property (nonatomic) UIImageView *cameraImageView; @property (nonatomic) UIImageView *cameraImageView;
@property (nonatomic) UIButton *skipOrSaveButton; @property (nonatomic) UIButton *saveButton;
@property (nonatomic, nullable) UIImage *avatar; @property (nonatomic, nullable) UIImage *avatar;
@ -207,24 +207,25 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
// Big Button // Big Button
if (self.profileViewMode == ProfileViewMode_Registration) { if (self.profileViewMode == ProfileViewMode_Registration || self.profileViewMode == ProfileViewMode_UpgradeOrNag) {
UIView *buttonRow = [UIView containerView]; UIView *buttonRow = [UIView containerView];
[rows addObject:buttonRow]; [rows addObject:buttonRow];
UIButton *skipOrSaveButton = [UIButton buttonWithType:UIButtonTypeCustom]; UIButton *saveButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.skipOrSaveButton = skipOrSaveButton; self.saveButton = saveButton;
skipOrSaveButton.backgroundColor = [UIColor ows_signalBrandBlueColor]; saveButton.backgroundColor = [UIColor ows_signalBrandBlueColor];
[skipOrSaveButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [saveButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
skipOrSaveButton.titleLabel.font = [UIFont ows_boldFontWithSize:fontSizePoints]; saveButton.titleLabel.font = [UIFont ows_boldFontWithSize:fontSizePoints];
[skipOrSaveButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter]; [saveButton setTitle:NSLocalizedString(
[skipOrSaveButton setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter]; @"PROFILE_VIEW_SAVE_BUTTON", @"Button to save the profile view in the profile view.")
[buttonRow addSubview:skipOrSaveButton]; forState:UIControlStateNormal];
[skipOrSaveButton autoPinLeadingAndTrailingToSuperview]; [saveButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
[skipOrSaveButton autoPinHeightToSuperview]; [saveButton setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
[skipOrSaveButton autoSetDimension:ALDimensionHeight toSize:47.f]; [buttonRow addSubview:saveButton];
[skipOrSaveButton addTarget:self [saveButton autoPinLeadingAndTrailingToSuperview];
action:@selector(skipOrSaveButtonPressed) [saveButton autoPinHeightToSuperview];
forControlEvents:UIControlEventTouchUpInside]; [saveButton autoSetDimension:ALDimensionHeight toSize:47.f];
[saveButton addTarget:self action:@selector(saveButtonPressed) forControlEvents:UIControlEventTouchUpInside];
} }
// Row Layout // Row Layout
@ -322,15 +323,24 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
// context. // context.
switch (self.profileViewMode) { switch (self.profileViewMode) {
case ProfileViewMode_AppSettings: case ProfileViewMode_AppSettings:
if (self.hasUnsavedChanges) {
// If we have a unsaved changes, right item should be a "save" button.
self.navigationItem.rightBarButtonItem =
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave
target:self
action:@selector(updatePressed)];
} else {
self.navigationItem.rightBarButtonItem = nil;
}
break; break;
case ProfileViewMode_UpgradeOrNag: case ProfileViewMode_UpgradeOrNag:
self.navigationItem.leftBarButtonItem = self.navigationItem.leftBarButtonItem =
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemStop
target:self target:self
action:@selector(backOrSkipButtonPressed)]; action:@selector(backOrSkipButtonPressed)];
break; break;
case ProfileViewMode_Registration: case ProfileViewMode_Registration:
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
initWithTitle:NSLocalizedString(@"NAVIGATION_ITEM_SKIP_BUTTON", @"A button to skip a view.") initWithTitle:NSLocalizedString(@"NAVIGATION_ITEM_SKIP_BUTTON", @"A button to skip a view.")
style:UIBarButtonItemStylePlain style:UIBarButtonItemStylePlain
target:self target:self
@ -338,22 +348,14 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
break; break;
} }
if (self.profileViewMode == ProfileViewMode_Registration) { // The save button is only used in "registration" and "upgrade or nag" modes.
[self.skipOrSaveButton if (self.hasUnsavedChanges) {
setTitle:(self.hasUnsavedChanges self.saveButton.enabled = YES;
? NSLocalizedString( self.saveButton.backgroundColor = [UIColor ows_signalBrandBlueColor];
@"PROFILE_VIEW_SAVE_BUTTON", @"Button to save the profile view in the profile view.")
: NSLocalizedString(@"PROFILE_VIEW_SKIP_BUTTON",
@"Button to skip the profile view in the registration workflow."))forState
:UIControlStateNormal];
} else { } else {
if (self.hasUnsavedChanges) { self.saveButton.enabled = NO;
// If we have a unsaved changes, right item should be a "save" button. self.saveButton.backgroundColor =
self.navigationItem.rightBarButtonItem = [[UIColor ows_signalBrandBlueColor] blendWithColor:[UIColor whiteColor] alpha:0.5f];
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave
target:self
action:@selector(updatePressed)];
}
} }
} }
@ -506,9 +508,9 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
} }
} }
- (void)skipOrSaveButtonPressed - (void)saveButtonPressed
{ {
[self leaveViewCheckingForUnsavedChanges]; [self updatePressed];
} }
#pragma mark - AvatarViewHelperDelegate #pragma mark - AvatarViewHelperDelegate

Loading…
Cancel
Save