diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index 20f36a041..21e816027 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -78,7 +78,7 @@ 34CCAF3B1F0C2748004084F4 /* OWSAddToContactViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34CCAF3A1F0C2748004084F4 /* OWSAddToContactViewController.m */; }; 34CE88E71F2FB9A10098030F /* ProfileViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34CE88E61F2FB9A10098030F /* ProfileViewController.m */; }; 34D5CC961EA6AFAD005515DB /* OWSContactsSyncing.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D5CC951EA6AFAD005515DB /* OWSContactsSyncing.m */; }; - 34D5CCA91EAE3D30005515DB /* GroupViewHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D5CCA81EAE3D30005515DB /* GroupViewHelper.m */; }; + 34D5CCA91EAE3D30005515DB /* AvatarViewHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D5CCA81EAE3D30005515DB /* AvatarViewHelper.m */; }; 34D5CCB11EAE7E7F005515DB /* SelectRecipientViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D5CCB01EAE7E7F005515DB /* SelectRecipientViewController.m */; }; 34D8C0271ED3673300188D7C /* DebugUIMessages.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D8C0241ED3673300188D7C /* DebugUIMessages.m */; }; 34D8C0281ED3673300188D7C /* DebugUITableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D8C0261ED3673300188D7C /* DebugUITableViewController.m */; }; @@ -510,8 +510,8 @@ 34D5CC951EA6AFAD005515DB /* OWSContactsSyncing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSContactsSyncing.m; sourceTree = ""; }; 34D5CC981EA6EB79005515DB /* OWSMessageCollectionViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSMessageCollectionViewCell.h; sourceTree = ""; }; 34D5CC9B1EA6ED17005515DB /* OWSMessageMediaAdapter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSMessageMediaAdapter.h; sourceTree = ""; }; - 34D5CCA71EAE3D30005515DB /* GroupViewHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GroupViewHelper.h; sourceTree = ""; }; - 34D5CCA81EAE3D30005515DB /* GroupViewHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GroupViewHelper.m; sourceTree = ""; }; + 34D5CCA71EAE3D30005515DB /* AvatarViewHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AvatarViewHelper.h; sourceTree = ""; }; + 34D5CCA81EAE3D30005515DB /* AvatarViewHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AvatarViewHelper.m; sourceTree = ""; }; 34D5CCAB1EAE7136005515DB /* OWSConversationSettingsViewDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSConversationSettingsViewDelegate.h; sourceTree = ""; }; 34D5CCAF1EAE7E7F005515DB /* SelectRecipientViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SelectRecipientViewController.h; sourceTree = ""; }; 34D5CCB01EAE7E7F005515DB /* SelectRecipientViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SelectRecipientViewController.m; sourceTree = ""; }; @@ -958,6 +958,8 @@ 34B3F8381E8DF1700035BE1A /* AttachmentApprovalViewController.swift */, 34B3F8391E8DF1700035BE1A /* AttachmentSharing.h */, 34B3F83A1E8DF1700035BE1A /* AttachmentSharing.m */, + 34D5CCA71EAE3D30005515DB /* AvatarViewHelper.h */, + 34D5CCA81EAE3D30005515DB /* AvatarViewHelper.m */, 343D3D991E9283F100165CA4 /* BlockListUIUtils.h */, 343D3D9A1E9283F100165CA4 /* BlockListUIUtils.m */, 34B3F89A1E8DF3270035BE1A /* BlockListViewController.h */, @@ -982,8 +984,6 @@ 34E8BF371EE9E2FD00F5F4CA /* FingerprintViewScanController.m */, 34B3F8471E8DF1700035BE1A /* FullImageViewController.h */, 34B3F8481E8DF1700035BE1A /* FullImageViewController.m */, - 34D5CCA71EAE3D30005515DB /* GroupViewHelper.h */, - 34D5CCA81EAE3D30005515DB /* GroupViewHelper.m */, 34B3F8491E8DF1700035BE1A /* InboxTableViewCell.h */, 34B3F84A1E8DF1700035BE1A /* InboxTableViewCell.m */, 34B3F84C1E8DF1700035BE1A /* InviteFlow.swift */, @@ -2222,7 +2222,7 @@ 34B3F8881E8DF1700035BE1A /* OversizeTextMessageViewController.swift in Sources */, 34330AA31E79686200DF2FB9 /* OWSProgressView.m in Sources */, 34B3F8A21E8EA6040035BE1A /* ViewControllerUtils.m in Sources */, - 34D5CCA91EAE3D30005515DB /* GroupViewHelper.m in Sources */, + 34D5CCA91EAE3D30005515DB /* AvatarViewHelper.m in Sources */, 453D28BA1D332DB100D523F0 /* OWSMessagesBubblesSizeCalculator.m in Sources */, 45F170AC1E2F0351003FC1F2 /* CallAudioSession.swift in Sources */, 34B3F8801E8DF1700035BE1A /* InviteFlow.swift in Sources */, diff --git a/Signal/src/ViewControllers/AvatarViewHelper.h b/Signal/src/ViewControllers/AvatarViewHelper.h new file mode 100644 index 000000000..38dda3f92 --- /dev/null +++ b/Signal/src/ViewControllers/AvatarViewHelper.h @@ -0,0 +1,34 @@ +// +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@class SignalAccount; +@class AvatarViewHelper; +@class OWSContactsManager; +@class TSThread; + +@protocol AvatarViewHelperDelegate + +- (void)avatarDidChange:(UIImage *)image; + +- (UIViewController *)fromViewController; + +@end + +#pragma mark - + +typedef void (^AvatarViewSuccessBlock)(); + +@interface AvatarViewHelper : NSObject + +@property (nonatomic, weak) id delegate; + +- (void)showChangeAvatarUI; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Signal/src/ViewControllers/GroupViewHelper.m b/Signal/src/ViewControllers/AvatarViewHelper.m similarity index 92% rename from Signal/src/ViewControllers/GroupViewHelper.m rename to Signal/src/ViewControllers/AvatarViewHelper.m index d980e1f70..5ea311301 100644 --- a/Signal/src/ViewControllers/GroupViewHelper.m +++ b/Signal/src/ViewControllers/AvatarViewHelper.m @@ -2,7 +2,7 @@ // Copyright (c) 2017 Open Whisper Systems. All rights reserved. // -#import "GroupViewHelper.h" +#import "AvatarViewHelper.h" #import "OWSContactsManager.h" #import "UIUtil.h" #import @@ -13,17 +13,17 @@ NS_ASSUME_NONNULL_BEGIN -@interface GroupViewHelper () +@interface AvatarViewHelper () @end #pragma mark - -@implementation GroupViewHelper +@implementation AvatarViewHelper -#pragma mark - Group Avatar +#pragma mark - Avatar Avatar -- (void)showChangeGroupAvatarUI +- (void)showChangeAvatarUI { OWSAssert([NSThread isMainThread]); OWSAssert(self.delegate); @@ -117,9 +117,9 @@ NS_ASSUME_NONNULL_BEGIN if (rawAvatar) { // We resize the avatar to fill a 210x210 square. // - // See: GroupCreateActivity.java in Signal-Android.java. + // See: AvatarCreateActivity.java in Signal-Android.java. UIImage *resizedAvatar = [rawAvatar resizedImageToFillPixelSize:CGSizeMake(210, 210)]; - [self.delegate groupAvatarDidChange:resizedAvatar]; + [self.delegate avatarDidChange:resizedAvatar]; } [self.delegate.fromViewController dismissViewControllerAnimated:YES completion:nil]; diff --git a/Signal/src/ViewControllers/GroupViewHelper.h b/Signal/src/ViewControllers/GroupViewHelper.h deleted file mode 100644 index 932f6d543..000000000 --- a/Signal/src/ViewControllers/GroupViewHelper.h +++ /dev/null @@ -1,34 +0,0 @@ -// -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. -// - -#import - -NS_ASSUME_NONNULL_BEGIN - -@class SignalAccount; -@class GroupViewHelper; -@class OWSContactsManager; -@class TSThread; - -@protocol GroupViewHelperDelegate - -- (void)groupAvatarDidChange:(UIImage *)image; - -- (UIViewController *)fromViewController; - -@end - -#pragma mark - - -typedef void (^GroupViewSuccessBlock)(); - -@interface GroupViewHelper : NSObject - -@property (nonatomic, weak) id delegate; - -- (void)showChangeGroupAvatarUI; - -@end - -NS_ASSUME_NONNULL_END diff --git a/Signal/src/ViewControllers/NewGroupViewController.m b/Signal/src/ViewControllers/NewGroupViewController.m index ab6236dab..395a3654b 100644 --- a/Signal/src/ViewControllers/NewGroupViewController.m +++ b/Signal/src/ViewControllers/NewGroupViewController.m @@ -4,11 +4,11 @@ #import "NewGroupViewController.h" #import "AddToGroupViewController.h" +#import "AvatarViewHelper.h" #import "BlockListUIUtils.h" #import "ContactTableViewCell.h" #import "ContactsViewHelper.h" #import "Environment.h" -#import "GroupViewHelper.h" #import "OWSContactsManager.h" #import "OWSTableViewController.h" #import "Signal-Swift.h" @@ -31,14 +31,14 @@ const NSUInteger kNewGroupViewControllerAvatarWidth = 68; @interface NewGroupViewController () @property (nonatomic, readonly) OWSMessageSender *messageSender; @property (nonatomic, readonly) ContactsViewHelper *contactsViewHelper; -@property (nonatomic, readonly) GroupViewHelper *groupViewHelper; +@property (nonatomic, readonly) AvatarViewHelper *avatarViewHelper; @property (nonatomic, readonly) OWSTableViewController *tableViewController; @property (nonatomic, readonly) AvatarImageView *avatarView; @@ -84,8 +84,8 @@ const NSUInteger kNewGroupViewControllerAvatarWidth = 68; { _messageSender = [Environment getCurrent].messageSender; _contactsViewHelper = [[ContactsViewHelper alloc] initWithDelegate:self]; - _groupViewHelper = [GroupViewHelper new]; - _groupViewHelper.delegate = self; + _avatarViewHelper = [AvatarViewHelper new]; + _avatarViewHelper.delegate = self; self.memberRecipientIds = [NSMutableSet new]; } @@ -181,7 +181,7 @@ const NSUInteger kNewGroupViewControllerAvatarWidth = 68; - (void)avatarTouched:(UIGestureRecognizer *)sender { if (sender.state == UIGestureRecognizerStateRecognized) { - [self showChangeGroupAvatarUI]; + [self showChangeAvatarUI]; } } @@ -520,9 +520,9 @@ const NSUInteger kNewGroupViewControllerAvatarWidth = 68; #pragma mark - Group Avatar -- (void)showChangeGroupAvatarUI +- (void)showChangeAvatarUI { - [self.groupViewHelper showChangeGroupAvatarUI]; + [self.avatarViewHelper showChangeAvatarUI]; } - (void)setGroupAvatar:(nullable UIImage *)groupAvatar @@ -606,9 +606,9 @@ const NSUInteger kNewGroupViewControllerAvatarWidth = 68; return YES; } -#pragma mark - GroupViewHelperDelegate +#pragma mark - AvatarViewHelperDelegate -- (void)groupAvatarDidChange:(UIImage *)image +- (void)avatarDidChange:(UIImage *)image { OWSAssert(image); diff --git a/Signal/src/ViewControllers/ProfileViewController.h b/Signal/src/ViewControllers/ProfileViewController.h index a786eb689..16471c80f 100644 --- a/Signal/src/ViewControllers/ProfileViewController.h +++ b/Signal/src/ViewControllers/ProfileViewController.h @@ -6,23 +6,8 @@ NS_ASSUME_NONNULL_BEGIN -//@class ProfileViewController; -// -//@protocol ProfileViewControllerDelegate -// -//- (void)ProfileViewController:(ProfileViewController *)vc -// didSelectCountryCode:(NSString *)countryCode -// countryName:(NSString *)countryName -// callingCode:(NSString *)callingCode; -// -//@end -// -//#pragma mark - - @interface ProfileViewController : OWSTableViewController -//@property (nonatomic, weak) id countryCodeDelegate; - @end NS_ASSUME_NONNULL_END diff --git a/Signal/src/ViewControllers/ProfileViewController.m b/Signal/src/ViewControllers/ProfileViewController.m index 4adb39ec6..12d822bd1 100644 --- a/Signal/src/ViewControllers/ProfileViewController.m +++ b/Signal/src/ViewControllers/ProfileViewController.m @@ -3,22 +3,18 @@ // #import "ProfileViewController.h" +#import "AvatarViewHelper.h" #import "Signal-Swift.h" #import "UIColor+OWS.h" #import "UIFont+OWS.h" #import "UIView+OWS.h" +#import "UIViewController+OWS.h" NS_ASSUME_NONNULL_BEGIN -@interface ProfileViewController () -//< -// OWSTableViewControllerDelegate -//// , UISearchBarDelegate -//> +@interface ProfileViewController () -//@property (nonatomic, readonly) UISearchBar *searchBar; -// -//@property (nonatomic) NSArray *countryCodes; +@property (nonatomic, readonly) AvatarViewHelper *avatarViewHelper; @property (nonatomic) UITextField *nameTextField; @@ -26,6 +22,10 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic) UILabel *avatarLabel; +@property (nonatomic, nullable) UIImage *avatar; + +@property (nonatomic) BOOL hasUnsavedChanges; + @end #pragma mark - @@ -39,13 +39,11 @@ NS_ASSUME_NONNULL_BEGIN self.view.backgroundColor = [UIColor whiteColor]; [self.navigationController.navigationBar setTranslucent:NO]; self.title = NSLocalizedString(@"PROFILE_VIEW_TITLE", @"Title for the profile view."); + self.navigationItem.leftBarButtonItem = + [self createOWSBackButtonWithTarget:self selector:@selector(backButtonPressed:)]; - // self.countryCodes = [PhoneNumberUtil countryCodesForSearchTerm:nil]; - - // self.navigationItem.leftBarButtonItem = - // [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemStop - // target:self - // action:@selector(dismissWasPressed:)]; + _avatarViewHelper = [AvatarViewHelper new]; + _avatarViewHelper.delegate = self; [self createViews]; } @@ -54,7 +52,6 @@ NS_ASSUME_NONNULL_BEGIN { _nameTextField = [UITextField new]; _nameTextField.font = [UIFont ows_mediumFontWithSize:18.f]; - // _nameTextField.textAlignment = _nameTextField.textAlignmentUnnatural; _nameTextField.textColor = [UIColor ows_materialBlueColor]; // TODO: Copy. _nameTextField.placeholder = NSLocalizedString( @@ -87,34 +84,26 @@ NS_ASSUME_NONNULL_BEGIN OWSTableSection *avatarSection = [OWSTableSection new]; avatarSection.headerTitle = NSLocalizedString( @"PROFILE_VIEW_AVATAR_SECTION_HEADER", @"Header title for the profile avatar field of the profile view."); - const CGFloat kAvatarHeightPoints = 100.f; + const CGFloat kAvatarSizePoints = 100.f; const CGFloat kAvatarTopMargin = 10.f; const CGFloat kAvatarBottomMargin = 10.f; const CGFloat kAvatarVSpacing = 10.f; - CGFloat avatarCellHeight = round( - kAvatarHeightPoints + kAvatarTopMargin + kAvatarBottomMargin + kAvatarVSpacing + self.avatarLabel.height); - // const CGFloat kCountryRowHeight = 50; - // const CGFloat kPhoneNumberRowHeight = 50; - // const CGFloat examplePhoneNumberRowHeight = self.examplePhoneNumberFont.lineHeight + 3.f; - // const CGFloat kButtonRowHeight = 60; + CGFloat avatarCellHeight + = round(kAvatarSizePoints + kAvatarTopMargin + kAvatarBottomMargin + kAvatarVSpacing + self.avatarLabel.height); [avatarSection addItem:[OWSTableItem itemWithCustomCellBlock:^{ - // SelectRecipientViewController *strongSelf = weakSelf; - // OWSCAssert(strongSelf); - UITableViewCell *cell = [UITableViewCell new]; cell.preservesSuperviewLayoutMargins = YES; cell.contentView.preservesSuperviewLayoutMargins = YES; // TODO: Use the current avatar. - UIImage *defaultAvatarImage = [UIImage imageNamed:@"profile_avatar_default"]; - OWSAssert(defaultAvatarImage.size.width == kAvatarHeightPoints); - OWSAssert(defaultAvatarImage.size.height == kAvatarHeightPoints); AvatarImageView *avatarView = weakSelf.avatarView; - avatarView.image = defaultAvatarImage; + [weakSelf updateAvatarView]; [cell.contentView addSubview:avatarView]; [avatarView autoHCenterInSuperview]; [avatarView autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:kAvatarTopMargin]; + [avatarView autoSetDimension:ALDimensionWidth toSize:kAvatarSizePoints]; + [avatarView autoSetDimension:ALDimensionHeight toSize:kAvatarSizePoints]; UILabel *avatarLabel = weakSelf.avatarLabel; [cell.contentView addSubview:avatarLabel]; @@ -136,22 +125,16 @@ NS_ASSUME_NONNULL_BEGIN OWSTableSection *nameSection = [OWSTableSection new]; nameSection.headerTitle = NSLocalizedString( @"PROFILE_VIEW_NAME_SECTION_HEADER", @"Label for the profile name field of the profile view."); - // const CGFloat kCountryRowHeight = 50; - // const CGFloat kPhoneNumberRowHeight = 50; - // const CGFloat examplePhoneNumberRowHeight = self.examplePhoneNumberFont.lineHeight + 3.f; - // const CGFloat kButtonRowHeight = 60; [nameSection addItem: [OWSTableItem itemWithCustomCellBlock:^{ - // SelectRecipientViewController *strongSelf = weakSelf; - // OWSCAssert(strongSelf); - UITableViewCell *cell = [UITableViewCell new]; cell.preservesSuperviewLayoutMargins = YES; cell.contentView.preservesSuperviewLayoutMargins = YES; UITextField *nameTextField = weakSelf.nameTextField; + // TODO: Use the current profile name. [cell.contentView addSubview:nameTextField]; [nameTextField autoPinLeadingToSuperView]; [nameTextField autoPinTrailingToSuperView]; @@ -160,41 +143,82 @@ NS_ASSUME_NONNULL_BEGIN cell.selectionStyle = UITableViewCellSelectionStyleNone; return cell; } - // customRowHeight:kCountryRowHeight + - // kPhoneNumberRowHeight - // + examplePhoneNumberRowHeight - // + kButtonRowHeight actionBlock:nil]]; [contents addSection:nameSection]; self.contents = contents; } -//- (void)countryCodeWasSelected:(NSString *)countryCode -//{ -// OWSAssert(countryCode.length > 0); -// -// NSString *callingCodeSelected = [PhoneNumberUtil callingCodeFromCountryCode:countryCode]; -// NSString *countryNameSelected = [PhoneNumberUtil countryNameFromCountryCode:countryCode]; -// NSString *countryCodeSelected = countryCode; -// [self.countryCodeDelegate ProfileViewController:self -// didSelectCountryCode:countryCodeSelected -// countryName:countryNameSelected -// callingCode:callingCodeSelected]; -// [self.searchBar resignFirstResponder]; -// [self dismissViewControllerAnimated:YES completion:nil]; -//} -// -//- (void)dismissWasPressed:(id)sender { -// [self dismissViewControllerAnimated:YES completion:nil]; -//} +#pragma mark - Event Handling + +- (void)backButtonPressed:(id)sender +{ + [self.nameTextField resignFirstResponder]; + + if (!self.hasUnsavedChanges) { + // If user made no changes, return to conversation settings view. + [self.navigationController popViewControllerAnimated:YES]; + return; + } + + UIAlertController *controller = [UIAlertController + alertControllerWithTitle: + NSLocalizedString(@"NEW_GROUP_VIEW_UNSAVED_CHANGES_TITLE", + @"The alert title if user tries to exit the new group view without saving changes.") + message: + NSLocalizedString(@"NEW_GROUP_VIEW_UNSAVED_CHANGES_MESSAGE", + @"The alert message if user tries to exit the new group view without saving changes.") + preferredStyle:UIAlertControllerStyleAlert]; + [controller + addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"ALERT_DISCARD_BUTTON", + @"The label for the 'discard' button in alerts and action sheets.") + style:UIAlertActionStyleDestructive + handler:^(UIAlertAction *action) { + [self.navigationController popViewControllerAnimated:YES]; + }]]; + [controller addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"TXT_CANCEL_TITLE", nil) + style:UIAlertActionStyleCancel + handler:nil]]; + [self presentViewController:controller animated:YES completion:nil]; +} - (void)avatarTapped:(UIGestureRecognizer *)sender { if (sender.state == UIGestureRecognizerStateRecognized) { + [self.avatarViewHelper showChangeAvatarUI]; } } +- (void)setHasUnsavedChanges:(BOOL)hasUnsavedChanges +{ + _hasUnsavedChanges = hasUnsavedChanges; + + if (hasUnsavedChanges) { + self.navigationItem.rightBarButtonItem = (self.hasUnsavedChanges + ? [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"EDIT_GROUP_UPDATE_BUTTON", + @"The title for the 'update group' button.") + style:UIBarButtonItemStylePlain + target:self + action:@selector(updatePressed)] + : nil); + } +} + +- (void)updatePressed +{ + [self updateProfile]; +} + +- (void)updateProfile +{ + // OWSAssert(self.conversationSettingsViewDelegate); + // + // [self updateGroup]; + // + // [self.conversationSettingsViewDelegate popAllConversationSettingsViews]; + // [self.navigationController popViewControllerAnimated:YES]; +} + #pragma mark - UITextFieldDelegate // TODO: This logic resides in both RegistrationViewController and here. @@ -228,9 +252,44 @@ NS_ASSUME_NONNULL_BEGIN - (void)textFieldDidChange:(id)sender { + self.hasUnsavedChanges = YES; // [self updatePhoneNumberButtonEnabling]; } +#pragma mark - Avatar + +- (void)setAvatar:(nullable UIImage *)avatar +{ + OWSAssert([NSThread isMainThread]); + + _avatar = avatar; + + self.hasUnsavedChanges = YES; + + [self updateAvatarView]; +} + +- (void)updateAvatarView +{ + self.avatarView.image = (self.avatar ?: [UIImage imageNamed:@"profile_avatar_default"]); +} + +#pragma mark - AvatarViewHelperDelegate + +- (void)avatarDidChange:(UIImage *)image +{ + OWSAssert(image); + + // TODO: Crop to square and possible resize. + + self.avatar = image; +} + +- (UIViewController *)fromViewController +{ + return self; +} + #pragma mark - Logging + (NSString *)tag diff --git a/Signal/src/ViewControllers/UpdateGroupViewController.m b/Signal/src/ViewControllers/UpdateGroupViewController.m index 0c4d67ced..ea6f6ea15 100644 --- a/Signal/src/ViewControllers/UpdateGroupViewController.m +++ b/Signal/src/ViewControllers/UpdateGroupViewController.m @@ -4,11 +4,11 @@ #import "UpdateGroupViewController.h" #import "AddToGroupViewController.h" +#import "AvatarViewHelper.h" #import "BlockListUIUtils.h" #import "ContactTableViewCell.h" #import "ContactsViewHelper.h" #import "Environment.h" -#import "GroupViewHelper.h" #import "OWSContactsManager.h" #import "OWSTableViewController.h" #import "Signal-Swift.h" @@ -30,14 +30,14 @@ NS_ASSUME_NONNULL_BEGIN @interface UpdateGroupViewController () @property (nonatomic, readonly) OWSMessageSender *messageSender; @property (nonatomic, readonly) ContactsViewHelper *contactsViewHelper; -@property (nonatomic, readonly) GroupViewHelper *groupViewHelper; +@property (nonatomic, readonly) AvatarViewHelper *avatarViewHelper; @property (nonatomic, readonly) OWSTableViewController *tableViewController; @property (nonatomic, readonly) AvatarImageView *avatarView; @@ -83,8 +83,8 @@ NS_ASSUME_NONNULL_BEGIN { _messageSender = [Environment getCurrent].messageSender; _contactsViewHelper = [[ContactsViewHelper alloc] initWithDelegate:self]; - _groupViewHelper = [GroupViewHelper new]; - _groupViewHelper.delegate = self; + _avatarViewHelper = [AvatarViewHelper new]; + _avatarViewHelper.delegate = self; self.memberRecipientIds = [NSMutableSet new]; } @@ -158,7 +158,7 @@ NS_ASSUME_NONNULL_BEGIN [self.groupNameTextField becomeFirstResponder]; break; case UpdateGroupMode_EditGroupAvatar: - [self showChangeGroupAvatarUI]; + [self showChangeAvatarUI]; break; default: break; @@ -228,7 +228,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)avatarTouched:(UIGestureRecognizer *)sender { if (sender.state == UIGestureRecognizerStateRecognized) { - [self showChangeGroupAvatarUI]; + [self showChangeAvatarUI]; } } @@ -384,11 +384,11 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - Group Avatar -- (void)showChangeGroupAvatarUI +- (void)showChangeAvatarUI { [self.groupNameTextField resignFirstResponder]; - [self.groupViewHelper showChangeGroupAvatarUI]; + [self.avatarViewHelper showChangeAvatarUI]; } - (void)setGroupAvatar:(nullable UIImage *)groupAvatar @@ -487,9 +487,9 @@ NS_ASSUME_NONNULL_BEGIN return YES; } -#pragma mark - GroupViewHelperDelegate +#pragma mark - AvatarViewHelperDelegate -- (void)groupAvatarDidChange:(UIImage *)image +- (void)avatarDidChange:(UIImage *)image { OWSAssert(image);