From 20d1d11259ecdb2eb100167696558ac61e6d35d4 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 12 Jul 2018 17:45:29 -0400 Subject: [PATCH] Refine home view. --- .../ViewControllers/HomeView/HomeViewCell.m | 26 ++++++----- .../HomeView/HomeViewController.m | 44 ++++++++++++++++--- .../ViewControllers/OWSNavigationController.m | 2 +- SignalMessaging/categories/UIColor+OWS.h | 6 +++ SignalMessaging/categories/UIColor+OWS.m | 35 +++++++++++++-- .../src/Messages/OWSBlockingManager.m | 1 - 6 files changed, 91 insertions(+), 23 deletions(-) diff --git a/Signal/src/ViewControllers/HomeView/HomeViewCell.m b/Signal/src/ViewControllers/HomeView/HomeViewCell.m index 40f3f4545..e42e7bb3d 100644 --- a/Signal/src/ViewControllers/HomeView/HomeViewCell.m +++ b/Signal/src/ViewControllers/HomeView/HomeViewCell.m @@ -61,12 +61,13 @@ NS_ASSUME_NONNULL_BEGIN { OWSAssert(!self.avatarView); - self.backgroundColor = [UIColor whiteColor]; + self.backgroundColor = UIColor.ows_themeBackgroundColor; _viewConstraints = [NSMutableArray new]; UIView *selectedBackgroundView = [UIView new]; - selectedBackgroundView.backgroundColor = [[UIColor colorWithRGBHex:0x000000] colorWithAlphaComponent:0.08]; + selectedBackgroundView.backgroundColor = + [(UIColor.isThemeEnabled ? [UIColor ows_whiteColor] : [UIColor ows_blackColor]) colorWithAlphaComponent:0.08]; self.selectedBackgroundView = selectedBackgroundView; @@ -225,9 +226,9 @@ NS_ASSUME_NONNULL_BEGIN self.dateTimeLabel.text = (overrideDate ? [self stringForDate:overrideDate] : [self stringForDate:thread.lastMessageDate]); - UIColor *textColor = [UIColor ows_light60Color]; + UIColor *textColor = [UIColor ows_themeSecondaryColor]; if (hasUnreadMessages && overrideSnippet == nil) { - textColor = [UIColor ows_light90Color]; + textColor = [UIColor ows_themeForegroundColor]; self.dateTimeLabel.font = self.dateTimeFont.ows_mediumWeight; } else { self.dateTimeLabel.font = self.dateTimeFont; @@ -273,7 +274,9 @@ NS_ASSUME_NONNULL_BEGIN }]; } else { UIImage *_Nullable statusIndicatorImage = nil; - UIColor *messageStatusViewTintColor = [UIColor ows_light35Color]; + // TODO: Review with design. + UIColor *messageStatusViewTintColor + = (UIColor.isThemeEnabled ? [UIColor ows_dark30Color] : [UIColor ows_light35Color]); BOOL shouldAnimateStatusIcon = NO; if ([self.thread.lastMessageForInbox isKindOfClass:[TSOutgoingMessage class]]) { TSOutgoingMessage *outgoingMessage = (TSOutgoingMessage *)self.thread.lastMessageForInbox; @@ -363,7 +366,7 @@ NS_ASSUME_NONNULL_BEGIN @"A label for conversations with blocked users.") attributes:@{ NSFontAttributeName : self.snippetFont.ows_mediumWeight, - NSForegroundColorAttributeName : [UIColor ows_light90Color], + NSForegroundColorAttributeName : [UIColor ows_themeForegroundColor], }]]; } else { if ([thread isMuted]) { @@ -371,9 +374,9 @@ NS_ASSUME_NONNULL_BEGIN initWithString:@"\ue067 " attributes:@{ NSFontAttributeName : [UIFont ows_elegantIconsFont:9.f], - NSForegroundColorAttributeName : (hasUnreadMessages - ? [UIColor colorWithWhite:0.1f alpha:1.f] - : [UIColor ows_light60Color]), + NSForegroundColorAttributeName : + (hasUnreadMessages ? [UIColor ows_themeForegroundColor] + : [UIColor ows_themeSecondaryColor]), }]]; } NSString *displayableText = thread.lastMessageText; @@ -385,8 +388,8 @@ NS_ASSUME_NONNULL_BEGIN (hasUnreadMessages ? self.snippetFont.ows_mediumWeight : self.snippetFont), NSForegroundColorAttributeName : - (hasUnreadMessages ? [UIColor ows_light90Color] - : [UIColor ows_light60Color]), + (hasUnreadMessages ? [UIColor ows_themeForegroundColor] + : [UIColor ows_themeSecondaryColor]), }]]; } } @@ -488,6 +491,7 @@ NS_ASSUME_NONNULL_BEGIN OWSAssertIsOnMainThread(); self.nameLabel.font = self.nameFont; + self.nameLabel.textColor = [UIColor ows_themeForegroundColor]; ThreadViewModel *thread = self.thread; if (thread == nil) { diff --git a/Signal/src/ViewControllers/HomeView/HomeViewController.m b/Signal/src/ViewControllers/HomeView/HomeViewController.m index c2dbe5e0d..c5ef5711b 100644 --- a/Signal/src/ViewControllers/HomeView/HomeViewController.m +++ b/Signal/src/ViewControllers/HomeView/HomeViewController.m @@ -172,6 +172,10 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations selector:@selector(outageStateDidChange:) name:OutageDetection.outageStateDidChange object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(themeDidChange:) + name:NSNotificationNameThemeDidChange + object:nil]; } - (void)dealloc @@ -211,14 +215,30 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations [self updateReminderViews]; } +- (void)themeDidChange:(id)notification +{ + OWSAssertIsOnMainThread(); + + [self applyTheme]; + [self.tableView reloadData]; +} + +#pragma mark - Theme + +- (void)applyTheme +{ + OWSAssertIsOnMainThread(); + + self.view.backgroundColor = UIColor.ows_themeBackgroundColor; + self.tableView.backgroundColor = UIColor.ows_themeBackgroundColor; +} + #pragma mark - View Life Cycle - (void)loadView { [super loadView]; - self.view.backgroundColor = [UIColor whiteColor]; - // TODO: Remove this. if (self.homeViewMode == HomeViewMode_Inbox) { [SignalApp.sharedApp setHomeViewController:self]; @@ -308,6 +328,8 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations [self.tableView insertSubview:pullToRefreshView atIndex:0]; [self updateReminderViews]; + + [self applyTheme]; } - (void)updateReminderViews @@ -359,7 +381,13 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations searchBar.searchBarStyle = UISearchBarStyleMinimal; searchBar.placeholder = NSLocalizedString(@"HOME_VIEW_CONVERSATION_SEARCHBAR_PLACEHOLDER", @"Placeholder text for search bar which filters conversations."); - searchBar.backgroundColor = [UIColor whiteColor]; + searchBar.backgroundColor = UIColor.ows_themeBackgroundColor; + if (UIColor.isThemeEnabled) { + searchBar.barStyle = UIBarStyleBlack; + } else { + searchBar.barStyle = UIBarStyleDefault; + } + searchBar.delegate = self; [searchBar sizeToFit]; @@ -808,7 +836,7 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations [subview removeFromSuperview]; } - cell.backgroundColor = [UIColor whiteColor]; + cell.backgroundColor = UIColor.ows_themeBackgroundColor; UIImage *disclosureImage = [UIImage imageNamed:(CurrentAppContext().isRTL ? @"NavBarBack" : @"NavBarBackRTL")]; OWSAssert(disclosureImage); @@ -822,7 +850,7 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations label.text = NSLocalizedString(@"HOME_VIEW_ARCHIVED_CONVERSATIONS", @"Label for 'archived conversations' button."); label.textAlignment = NSTextAlignmentCenter; label.font = [UIFont ows_dynamicTypeBodyFont]; - label.textColor = [UIColor blackColor]; + label.textColor = UIColor.ows_themeForegroundColor; UIStackView *stackView = [UIStackView new]; stackView.axis = UILayoutConstraintAxisHorizontal; @@ -1411,6 +1439,7 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations - (void)updateEmptyBoxText { + // TODO: Theme, review with design. _emptyBoxLabel.textColor = [UIColor grayColor]; _emptyBoxLabel.font = [UIFont ows_regularFontWithSize:18.f]; _emptyBoxLabel.textAlignment = NSTextAlignmentCenter; @@ -1448,10 +1477,11 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations value:[UIFont ows_regularFontWithSize:14.f] range:NSMakeRange(firstLine.length + 1, secondLine.length)]; [fullLabelString addAttribute:NSForegroundColorAttributeName - value:[UIColor blackColor] + value:UIColor.ows_themeForegroundColor range:NSMakeRange(0, firstLine.length)]; + // TODO: Theme, Review with design. [fullLabelString addAttribute:NSForegroundColorAttributeName - value:[UIColor ows_darkGrayColor] + value:UIColor.ows_themeSecondaryColor range:NSMakeRange(firstLine.length + 1, secondLine.length)]; _emptyBoxLabel.attributedText = fullLabelString; } diff --git a/SignalMessaging/ViewControllers/OWSNavigationController.m b/SignalMessaging/ViewControllers/OWSNavigationController.m index 7f3fe0d28..bd38547ee 100644 --- a/SignalMessaging/ViewControllers/OWSNavigationController.m +++ b/SignalMessaging/ViewControllers/OWSNavigationController.m @@ -121,7 +121,7 @@ NS_ASSUME_NONNULL_BEGIN // Status bar is overlaying the green "call banner" return UIStatusBarStyleLightContent; } else { - return super.preferredStatusBarStyle; + return (UIColor.isThemeEnabled ? UIStatusBarStyleLightContent : super.preferredStatusBarStyle); } } diff --git a/SignalMessaging/categories/UIColor+OWS.h b/SignalMessaging/categories/UIColor+OWS.h index c51cf85b7..236aad6e5 100644 --- a/SignalMessaging/categories/UIColor+OWS.h +++ b/SignalMessaging/categories/UIColor+OWS.h @@ -10,6 +10,8 @@ NS_ASSUME_NONNULL_BEGIN #define THEME_ENABLED #endif +extern NSString *const NSNotificationNameThemeDidChange; + @interface UIColor (OWS) #pragma mark - Global App Colors @@ -88,6 +90,10 @@ NS_ASSUME_NONNULL_BEGIN + (void)setIsThemeEnabled:(BOOL)value; #endif ++ (UIColor *)ows_themeBackgroundColor; ++ (UIColor *)ows_themeForegroundColor; ++ (UIColor *)ows_themeSecondaryColor; + @end NS_ASSUME_NONNULL_END diff --git a/SignalMessaging/categories/UIColor+OWS.m b/SignalMessaging/categories/UIColor+OWS.m index 3b6e0e7da..d08d9d433 100644 --- a/SignalMessaging/categories/UIColor+OWS.m +++ b/SignalMessaging/categories/UIColor+OWS.m @@ -4,12 +4,16 @@ #import "OWSMath.h" #import "UIColor+OWS.h" +#import "UIUtil.h" #import +#import #import #import NS_ASSUME_NONNULL_BEGIN +NSString *const NSNotificationNameThemeDidChange = @"NSNotificationNameThemeDidChange"; + NSString *const UIColorCollection = @"UIColorCollection"; NSString *const UIColorKeyThemeEnabled = @"UIColorKeyThemeEnabled"; @@ -19,17 +23,19 @@ NSString *const UIColorKeyThemeEnabled = @"UIColorKeyThemeEnabled"; + (UIColor *)ows_navbarBackgroundColor { - return UIColor.ows_whiteColor; + return (UIColor.isThemeEnabled ? UIColor.ows_blackColor : UIColor.ows_whiteColor); } + (UIColor *)ows_navbarIconColor { - return UIColor.ows_light60Color; + // TODO: Review with design. + return (UIColor.isThemeEnabled ? UIColor.ows_dark60Color : UIColor.ows_light60Color); } + (UIColor *)ows_navbarTitleColor { - return UIColor.ows_light90Color; + // TODO: Review with design. + return (UIColor.isThemeEnabled ? UIColor.ows_dark60Color : UIColor.ows_light60Color); } #pragma mark - @@ -361,6 +367,29 @@ NSString *const UIColorKeyThemeEnabled = @"UIColorKeyThemeEnabled"; [OWSPrimaryStorage.sharedManager.dbReadWriteConnection setBool:value forKey:UIColorKeyThemeEnabled inCollection:UIColorCollection]; + + [UIUtil setupSignalAppearence]; + + [[NSNotificationCenter defaultCenter] postNotificationNameAsync:NSNotificationNameThemeDidChange + object:nil + userInfo:nil]; +} + ++ (UIColor *)ows_themeBackgroundColor +{ + return (UIColor.isThemeEnabled ? UIColor.ows_blackColor : UIColor.ows_whiteColor); +} + ++ (UIColor *)ows_themeForegroundColor +{ + // TODO: Review with design. + return (UIColor.isThemeEnabled ? UIColor.ows_whiteColor : UIColor.ows_light90Color); +} + ++ (UIColor *)ows_themeSecondaryColor +{ + // TODO: Review with design. + return (UIColor.isThemeEnabled ? UIColor.ows_dark60Color : UIColor.ows_light60Color); } @end diff --git a/SignalServiceKit/src/Messages/OWSBlockingManager.m b/SignalServiceKit/src/Messages/OWSBlockingManager.m index ed96ae7ba..18151ae82 100644 --- a/SignalServiceKit/src/Messages/OWSBlockingManager.m +++ b/SignalServiceKit/src/Messages/OWSBlockingManager.m @@ -15,7 +15,6 @@ NS_ASSUME_NONNULL_BEGIN NSString *const kNSNotificationName_BlockedPhoneNumbersDidChange = @"kNSNotificationName_BlockedPhoneNumbersDidChange"; -extern NSString *const kNSNotificationName_BlockedPhoneNumbersDidChange; NSString *const kOWSBlockingManager_BlockedPhoneNumbersCollection = @"kOWSBlockingManager_BlockedPhoneNumbersCollection"; // This key is used to persist the current "blocked phone numbers" state.