From b5c5d1c3ef2c6ee91a7721d6aedd9d166c90c28a Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Mon, 24 Sep 2018 16:11:53 -0400 Subject: [PATCH] Use local avatar as app settings button. --- .../HomeView/HomeViewController.m | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/Signal/src/ViewControllers/HomeView/HomeViewController.m b/Signal/src/ViewControllers/HomeView/HomeViewController.m index fb480f738..5b104ed6f 100644 --- a/Signal/src/ViewControllers/HomeView/HomeViewController.m +++ b/Signal/src/ViewControllers/HomeView/HomeViewController.m @@ -197,6 +197,10 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations selector:@selector(themeDidChange:) name:ThemeDidChangeNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(localProfileDidChange:) + name:kNSNotificationName_LocalProfileDidChange + object:nil]; } - (void)dealloc @@ -227,6 +231,13 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations [self updateReminderViews]; } +- (void)localProfileDidChange:(id)notification +{ + OWSAssertIsOnMainThread(); + + [self updateBarButtonItems]; +} + #pragma mark - Theme - (void)themeDidChange:(NSNotification *)notification @@ -485,10 +496,24 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations } // Settings button. - // - // TODO: Theme - UIImage *image = [UIImage imageNamed:@"button_settings_white"]; - UIBarButtonItem *settingsButton = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(settingsButtonPressed:)]; + const NSUInteger kAvatarSize = 28; + // TODO: Replace this icon. + UIImage *_Nullable localProfileAvatarImage = [OWSProfileManager.sharedManager localProfileAvatarImage]; + UIImage *avatarImage = (localProfileAvatarImage + ?: [[UIImage imageNamed:@"profile_avatar_default"] + imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]); + OWSAssertDebug(avatarImage); + + AvatarImageView *avatarView = [[AvatarImageView alloc] initWithImage:avatarImage]; + if (!localProfileAvatarImage) { + avatarView.tintColor = Theme.middleGrayColor; + } + [avatarView autoSetDimension:ALDimensionWidth toSize:kAvatarSize]; + [avatarView autoSetDimension:ALDimensionHeight toSize:kAvatarSize]; + UIBarButtonItem *settingsButton = [[UIBarButtonItem alloc] initWithCustomView:avatarView]; + avatarView.userInteractionEnabled = YES; + [avatarView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self + action:@selector(settingsButtonPressed:)]]; settingsButton.accessibilityLabel = CommonStrings.openSettingsButton; self.navigationItem.leftBarButtonItem = settingsButton;