From f795b12a86e92403ebbad418d561f04b80aa9d4e Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Mon, 23 Jul 2018 15:03:07 -0400 Subject: [PATCH] Refine theme. --- .../ViewControllers/CallViewController.swift | 2 + .../ConversationSearchViewController.swift | 46 +++++++++++++++++++ .../ViewControllers/HomeView/HomeViewCell.m | 5 -- .../HomeView/HomeViewController.m | 35 +++++++++++--- .../NewContactThreadViewController.m | 3 +- .../CodeVerificationViewController.m | 2 + .../Registration/RegistrationViewController.m | 2 + .../ViewControllers/OWSTableViewController.m | 2 +- .../ViewControllers/OWSViewController.h | 2 + .../ViewControllers/OWSViewController.m | 12 +++++ SignalMessaging/categories/Theme.h | 2 +- SignalMessaging/categories/Theme.m | 6 +-- .../contacts/CountryCodeViewController.m | 2 + 13 files changed, 102 insertions(+), 19 deletions(-) diff --git a/Signal/src/ViewControllers/CallViewController.swift b/Signal/src/ViewControllers/CallViewController.swift index b64b9786f..9401f0a55 100644 --- a/Signal/src/ViewControllers/CallViewController.swift +++ b/Signal/src/ViewControllers/CallViewController.swift @@ -148,6 +148,8 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver, super.init(nibName: nil, bundle: nil) allAudioSources = Set(callUIAdapter.audioService.availableInputs) + + self.shouldUseTheme = false } deinit { diff --git a/Signal/src/ViewControllers/HomeView/ConversationSearchViewController.swift b/Signal/src/ViewControllers/HomeView/ConversationSearchViewController.swift index c0f88a133..525114c76 100644 --- a/Signal/src/ViewControllers/HomeView/ConversationSearchViewController.swift +++ b/Signal/src/ViewControllers/HomeView/ConversationSearchViewController.swift @@ -48,6 +48,8 @@ class ConversationSearchViewController: UITableViewController { var blockedPhoneNumberSet = Set() + private var hasThemeChanged = false + // MARK: View Lifecycle override func viewDidLoad() { @@ -67,6 +69,28 @@ class ConversationSearchViewController: UITableViewController { selector: #selector(yapDatabaseModified), name: NSNotification.Name.YapDatabaseModified, object: OWSPrimaryStorage.shared().dbNotificationObject) + NotificationCenter.default.addObserver(self, + selector: #selector(themeDidChange), + name: NSNotification.Name.ThemeDidChange, + object: nil) + + applyTheme() + } + + override func viewDidAppear(_ animated: Bool) { + super.viewDidAppear(animated) + + guard hasThemeChanged else { + return + } + hasThemeChanged = false + + applyTheme() + self.tableView.reloadData() + } + + deinit { + NotificationCenter.default.removeObserver(self) } @objc internal func yapDatabaseModified(notification: NSNotification) { @@ -75,6 +99,22 @@ class ConversationSearchViewController: UITableViewController { refreshSearchResults() } + @objc internal func themeDidChange(notification: NSNotification) { + SwiftAssertIsOnMainThread(#function) + + applyTheme() + self.tableView.reloadData() + + hasThemeChanged = true + } + + private func applyTheme() { + SwiftAssertIsOnMainThread(#function) + + self.view.backgroundColor = Theme.backgroundColor + self.tableView.backgroundColor = Theme.backgroundColor + } + // MARK: UITableViewDelegate override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { @@ -159,6 +199,8 @@ class ConversationSearchViewController: UITableViewController { return UITableViewCell() } + OWSTableItem.configureCell(cell) + let searchText = self.searchResultSet.searchText cell.configure(searchText: searchText) return cell @@ -172,6 +214,7 @@ class ConversationSearchViewController: UITableViewController { owsFail("searchResult was unexpectedly nil") return UITableViewCell() } + OWSTableItem.configureCell(cell) cell.configure(withThread: searchResult.thread, contactsManager: contactsManager, blockedPhoneNumber: self.blockedPhoneNumberSet) return cell case .contacts: @@ -184,6 +227,7 @@ class ConversationSearchViewController: UITableViewController { owsFail("searchResult was unexpectedly nil") return UITableViewCell() } + OWSTableItem.configureCell(cell) cell.configure(with: searchResult.signalAccount, contactsManager: contactsManager) return cell case .messages: @@ -197,6 +241,8 @@ class ConversationSearchViewController: UITableViewController { return UITableViewCell() } + OWSTableItem.configureCell(cell) + var overrideSnippet = NSAttributedString() var overrideDate: Date? if searchResult.messageId != nil { diff --git a/Signal/src/ViewControllers/HomeView/HomeViewCell.m b/Signal/src/ViewControllers/HomeView/HomeViewCell.m index bde7dd8ba..0b1abe0e6 100644 --- a/Signal/src/ViewControllers/HomeView/HomeViewCell.m +++ b/Signal/src/ViewControllers/HomeView/HomeViewCell.m @@ -65,11 +65,6 @@ NS_ASSUME_NONNULL_BEGIN _viewConstraints = [NSMutableArray new]; - UIView *selectedBackgroundView = [UIView new]; - selectedBackgroundView.backgroundColor = [Theme.cellSelectedColor colorWithAlphaComponent:0.08f]; - - self.selectedBackgroundView = selectedBackgroundView; - self.avatarView = [[AvatarImageView alloc] init]; [self.contentView addSubview:self.avatarView]; [self.avatarView autoSetDimension:ALDimensionWidth toSize:self.avatarSize]; diff --git a/Signal/src/ViewControllers/HomeView/HomeViewController.m b/Signal/src/ViewControllers/HomeView/HomeViewController.m index 81719972c..f5fe3d0bf 100644 --- a/Signal/src/ViewControllers/HomeView/HomeViewController.m +++ b/Signal/src/ViewControllers/HomeView/HomeViewController.m @@ -84,6 +84,7 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations @property (nonatomic) TSThread *lastThread; @property (nonatomic) BOOL hasArchivedThreadsRow; +@property (nonatomic) BOOL hasThemeChanged; @end @@ -174,7 +175,7 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(themeDidChange:) - name:NSNotificationNameThemeDidChange + name:ThemeDidChangeNotification object:nil]; } @@ -223,14 +224,20 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations [self applyTheme]; [self.tableView reloadData]; + + self.hasThemeChanged = YES; } - (void)applyTheme { OWSAssertIsOnMainThread(); + OWSAssert(self.tableView); + OWSAssert(self.searchBar); self.view.backgroundColor = Theme.backgroundColor; self.tableView.backgroundColor = Theme.backgroundColor; + self.searchBar.backgroundColor = Theme.backgroundColor; + self.searchBar.barStyle = Theme.barStyle; } #pragma mark - View Life Cycle @@ -328,8 +335,6 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations [self.tableView insertSubview:pullToRefreshView atIndex:0]; [self updateReminderViews]; - - [self applyTheme]; } - (void)updateReminderViews @@ -383,9 +388,6 @@ 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 = Theme.backgroundColor; - searchBar.barStyle = Theme.barStyle; - searchBar.delegate = self; [searchBar sizeToFit]; @@ -404,6 +406,8 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations searchResultsController.view.hidden = YES; [self updateBarButtonItems]; + + [self applyTheme]; } - (void)applyDefaultBackButton @@ -435,6 +439,20 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations [self displayAnyUnseenUpgradeExperience]; [self applyDefaultBackButton]; + + if (self.hasThemeChanged) { + [self.tableView reloadData]; + self.hasThemeChanged = NO; + } + + [self.searchResultsController viewDidAppear:animated]; +} + +- (void)viewDidDisappear:(BOOL)animated +{ + [super viewDidDisappear:animated]; + + [self.searchResultsController viewDidDisappear:animated]; } - (void)updateBarButtonItems @@ -567,6 +585,8 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations if ([self updateHasArchivedThreadsRow]) { [self.tableView reloadData]; } + + [self.searchResultsController viewWillAppear:animated]; } - (void)viewWillDisappear:(BOOL)animated @@ -574,6 +594,8 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations [super viewWillDisappear:animated]; self.isViewVisible = NO; + + [self.searchResultsController viewWillDisappear:animated]; } - (void)setIsViewVisible:(BOOL)isViewVisible @@ -784,6 +806,7 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations { HomeViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:HomeViewCell.cellReuseIdentifier]; OWSAssert(cell); + [OWSTableItem configureCell:cell]; ThreadViewModel *thread = [self threadViewModelForIndexPath:indexPath]; [cell configureWithThread:thread diff --git a/Signal/src/ViewControllers/NewContactThreadViewController.m b/Signal/src/ViewControllers/NewContactThreadViewController.m index d7c53557f..ab3e77a23 100644 --- a/Signal/src/ViewControllers/NewContactThreadViewController.m +++ b/Signal/src/ViewControllers/NewContactThreadViewController.m @@ -75,7 +75,6 @@ NS_ASSUME_NONNULL_BEGIN { [super loadView]; - self.view.backgroundColor = Theme.backgroundColor; _contactsViewHelper = [[ContactsViewHelper alloc] initWithDelegate:self]; _conversationSearcher = [ConversationSearcher shared]; _nonContactAccountSet = [NSMutableSet set]; @@ -145,7 +144,7 @@ NS_ASSUME_NONNULL_BEGIN [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(themeDidChange:) - name:NSNotificationNameThemeDidChange + name:ThemeDidChangeNotification object:nil]; } diff --git a/Signal/src/ViewControllers/Registration/CodeVerificationViewController.m b/Signal/src/ViewControllers/Registration/CodeVerificationViewController.m index b84aaa510..653659b47 100644 --- a/Signal/src/ViewControllers/Registration/CodeVerificationViewController.m +++ b/Signal/src/ViewControllers/Registration/CodeVerificationViewController.m @@ -68,6 +68,8 @@ NS_ASSUME_NONNULL_BEGIN { [super viewDidLoad]; + self.shouldUseTheme = NO; + [self createViews]; [self initializeKeyboardHandlers]; diff --git a/Signal/src/ViewControllers/Registration/RegistrationViewController.m b/Signal/src/ViewControllers/Registration/RegistrationViewController.m index f772a608b..f4609ffea 100644 --- a/Signal/src/ViewControllers/Registration/RegistrationViewController.m +++ b/Signal/src/ViewControllers/Registration/RegistrationViewController.m @@ -47,6 +47,8 @@ NSString *const kKeychainKey_LastRegisteredPhoneNumber = @"kKeychainKey_LastRegi { [super loadView]; + self.shouldUseTheme = NO; + [self createViews]; // Do any additional setup after loading the view. diff --git a/SignalMessaging/ViewControllers/OWSTableViewController.m b/SignalMessaging/ViewControllers/OWSTableViewController.m index ab193480c..2024bc9d0 100644 --- a/SignalMessaging/ViewControllers/OWSTableViewController.m +++ b/SignalMessaging/ViewControllers/OWSTableViewController.m @@ -483,7 +483,7 @@ NSString *const kOWSTableCellIdentifier = @"kOWSTableCellIdentifier"; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(themeDidChange:) - name:NSNotificationNameThemeDidChange + name:ThemeDidChangeNotification object:nil]; } diff --git a/SignalMessaging/ViewControllers/OWSViewController.h b/SignalMessaging/ViewControllers/OWSViewController.h index 1afe534ee..81b488f7e 100644 --- a/SignalMessaging/ViewControllers/OWSViewController.h +++ b/SignalMessaging/ViewControllers/OWSViewController.h @@ -10,6 +10,8 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic) BOOL shouldIgnoreKeyboardChanges; +@property (nonatomic) BOOL shouldUseTheme; + // We often want to pin one view to the bottom of a view controller // BUT adjust its location upward if the keyboard appears. - (void)autoPinViewToBottomOfViewControllerOrKeyboard:(UIView *)view; diff --git a/SignalMessaging/ViewControllers/OWSViewController.m b/SignalMessaging/ViewControllers/OWSViewController.m index b4d3eaa4c..231569c6b 100644 --- a/SignalMessaging/ViewControllers/OWSViewController.m +++ b/SignalMessaging/ViewControllers/OWSViewController.m @@ -4,6 +4,7 @@ #import "OWSViewController.h" #import "UIView+OWS.h" +#import NS_ASSUME_NONNULL_BEGIN @@ -30,6 +31,7 @@ NS_ASSUME_NONNULL_BEGIN { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (!self) { + self.shouldUseTheme = YES; return self; } @@ -42,6 +44,7 @@ NS_ASSUME_NONNULL_BEGIN { self = [super initWithCoder:aDecoder]; if (!self) { + self.shouldUseTheme = YES; return self; } @@ -50,6 +53,15 @@ NS_ASSUME_NONNULL_BEGIN return self; } +- (void)viewDidLoad +{ + [super viewDidLoad]; + + if (self.shouldUseTheme) { + self.view.backgroundColor = Theme.backgroundColor; + } +} + - (void)autoPinViewToBottomOfViewControllerOrKeyboard:(UIView *)view { OWSAssert(view); diff --git a/SignalMessaging/categories/Theme.h b/SignalMessaging/categories/Theme.h index 6b88777e4..2a5cc56e6 100644 --- a/SignalMessaging/categories/Theme.h +++ b/SignalMessaging/categories/Theme.h @@ -10,7 +10,7 @@ NS_ASSUME_NONNULL_BEGIN #define THEME_ENABLED #endif -extern NSString *const NSNotificationNameThemeDidChange; +extern NSString *const ThemeDidChangeNotification; @interface Theme : NSObject diff --git a/SignalMessaging/categories/Theme.m b/SignalMessaging/categories/Theme.m index 9a2fb9eb9..b6ff7256e 100644 --- a/SignalMessaging/categories/Theme.m +++ b/SignalMessaging/categories/Theme.m @@ -11,7 +11,7 @@ NS_ASSUME_NONNULL_BEGIN -NSString *const NSNotificationNameThemeDidChange = @"NSNotificationNameThemeDidChange"; +NSString *const ThemeDidChangeNotification = @"ThemeDidChangeNotification"; NSString *const ThemeCollection = @"ThemeCollection"; NSString *const ThemeKeyThemeEnabled = @"ThemeKeyThemeEnabled"; @@ -41,9 +41,7 @@ NSString *const ThemeKeyThemeEnabled = @"ThemeKeyThemeEnabled"; [UIUtil setupSignalAppearence]; - [[NSNotificationCenter defaultCenter] postNotificationNameAsync:NSNotificationNameThemeDidChange - object:nil - userInfo:nil]; + [[NSNotificationCenter defaultCenter] postNotificationNameAsync:ThemeDidChangeNotification object:nil userInfo:nil]; } + (UIColor *)backgroundColor diff --git a/SignalMessaging/contacts/CountryCodeViewController.m b/SignalMessaging/contacts/CountryCodeViewController.m index 0799e24e3..c16039d17 100644 --- a/SignalMessaging/contacts/CountryCodeViewController.m +++ b/SignalMessaging/contacts/CountryCodeViewController.m @@ -25,6 +25,8 @@ { [super loadView]; + self.shouldUseTheme = NO; + self.view.backgroundColor = [UIColor whiteColor]; self.title = NSLocalizedString(@"COUNTRYCODE_SELECT_TITLE", @"");