Refine theme.

This commit is contained in:
Matthew Chen 2018-07-23 15:03:07 -04:00
parent 594eeea19f
commit f795b12a86
13 changed files with 102 additions and 19 deletions

View File

@ -148,6 +148,8 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver,
super.init(nibName: nil, bundle: nil)
allAudioSources = Set(callUIAdapter.audioService.availableInputs)
self.shouldUseTheme = false
}
deinit {

View File

@ -48,6 +48,8 @@ class ConversationSearchViewController: UITableViewController {
var blockedPhoneNumberSet = Set<String>()
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 {

View File

@ -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];

View File

@ -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

View File

@ -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];
}

View File

@ -68,6 +68,8 @@ NS_ASSUME_NONNULL_BEGIN
{
[super viewDidLoad];
self.shouldUseTheme = NO;
[self createViews];
[self initializeKeyboardHandlers];

View File

@ -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.

View File

@ -483,7 +483,7 @@ NSString *const kOWSTableCellIdentifier = @"kOWSTableCellIdentifier";
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(themeDidChange:)
name:NSNotificationNameThemeDidChange
name:ThemeDidChangeNotification
object:nil];
}

View File

@ -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;

View File

@ -4,6 +4,7 @@
#import "OWSViewController.h"
#import "UIView+OWS.h"
#import <SignalMessaging/Theme.h>
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);

View File

@ -10,7 +10,7 @@ NS_ASSUME_NONNULL_BEGIN
#define THEME_ENABLED
#endif
extern NSString *const NSNotificationNameThemeDidChange;
extern NSString *const ThemeDidChangeNotification;
@interface Theme : NSObject

View File

@ -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

View File

@ -25,6 +25,8 @@
{
[super loadView];
self.shouldUseTheme = NO;
self.view.backgroundColor = [UIColor whiteColor];
self.title = NSLocalizedString(@"COUNTRYCODE_SELECT_TITLE", @"");