diff --git a/Riot/Utils/RiotDesignValues.h b/Riot/Utils/RiotDesignValues.h index 268fe8946..8e2de7b52 100644 --- a/Riot/Utils/RiotDesignValues.h +++ b/Riot/Utils/RiotDesignValues.h @@ -17,6 +17,11 @@ #import +/** + Posted when the user interface theme has been changed. + */ +extern NSString *const kRiotDesignValuesDidChangeThemeNotification; + /** Convert a RGB hexadecimal value into a UIColor. */ @@ -26,10 +31,16 @@ blue:((float)((rgbValue & 0x0000FF) >> 0))/255.0 \ alpha:1.0] +#pragma mark - Riot Theme Colors (depends on the selected theme light or dark). +extern UIColor *kRiotPrimaryBgColor; +extern UIColor *kRiotSecondaryBgColor; +extern UIColor *kRiotPrimaryTextColor; +extern UIColor *kRiotSecondaryTextColor; //subtitle, sending messages color. +extern UIColor *kRiotTopicTextColor; + #pragma mark - Riot Colors extern UIColor *kRiotColorGreen; extern UIColor *kRiotColorLightGreen; -extern UIColor *kRiotColorLightGrey; extern UIColor *kRiotColorLightOrange; extern UIColor *kRiotColorSilver; extern UIColor *kRiotColorPinkRed; @@ -37,24 +48,31 @@ extern UIColor *kRiotColorRed; extern UIColor *kRiotColorIndigo; extern UIColor *kRiotColorOrange; +#pragma mark - Riot Background Colors +extern UIColor *kRiotBgColorWhite; +extern UIColor *kRiotBgColorBlack; + +extern UIColor *kRiotColorLightGrey; +extern UIColor *kRiotColorLightBlack; + #pragma mark - Riot Text Colors extern UIColor *kRiotTextColorBlack; extern UIColor *kRiotTextColorDarkGray; extern UIColor *kRiotTextColorGray; - -#pragma mark - Riot Navigation Bar Tint Color -extern UIColor *kRiotNavBarTintColor; +extern UIColor *kRiotTextColorWhite; +extern UIColor *kRiotTextColorDarkWhite; #pragma mark - Riot Standard Room Member Power Level extern NSInteger const kRiotRoomModeratorLevel; extern NSInteger const kRiotRoomAdminLevel; +#pragma mark - Riot +extern UIStatusBarStyle kRiotDesignStatusBarStyle; + + /** `RiotDesignValues` class manages the Riot design parameters */ @interface RiotDesignValues : NSObject -// to update the navigation bar buttons color -// [[AppDelegate theDelegate] recentsNavigationController].navigationBar.tintColor = [UIColor greenColor]; - @end diff --git a/Riot/Utils/RiotDesignValues.m b/Riot/Utils/RiotDesignValues.m index bceb38954..9f162f0bc 100644 --- a/Riot/Utils/RiotDesignValues.m +++ b/Riot/Utils/RiotDesignValues.m @@ -17,9 +17,16 @@ #import "RiotDesignValues.h" +NSString *const kRiotDesignValuesDidChangeThemeNotification = @"kRiotDesignValuesDidChangeThemeNotification"; + +UIColor *kRiotPrimaryBgColor; +UIColor *kRiotSecondaryBgColor; +UIColor *kRiotPrimaryTextColor; +UIColor *kRiotSecondaryTextColor; +UIColor *kRiotTopicTextColor; + UIColor *kRiotColorGreen; UIColor *kRiotColorLightGreen; -UIColor *kRiotColorLightGrey; UIColor *kRiotColorLightOrange; UIColor *kRiotColorSilver; UIColor *kRiotColorPinkRed; @@ -27,17 +34,37 @@ UIColor *kRiotColorRed; UIColor *kRiotColorIndigo; UIColor *kRiotColorOrange; +UIColor *kRiotBgColorWhite; +UIColor *kRiotBgColorBlack; + +UIColor *kRiotColorLightGrey; +UIColor *kRiotColorLightBlack; + UIColor *kRiotTextColorBlack; UIColor *kRiotTextColorDarkGray; UIColor *kRiotTextColorGray; - -UIColor *kRiotNavBarTintColor; +UIColor *kRiotTextColorWhite; +UIColor *kRiotTextColorDarkWhite; NSInteger const kRiotRoomModeratorLevel = 50; NSInteger const kRiotRoomAdminLevel = 100; +UIStatusBarStyle kRiotDesignStatusBarStyle = UIStatusBarStyleDefault; + @implementation RiotDesignValues ++ (RiotDesignValues *)sharedInstance +{ + static RiotDesignValues *sharedOnceInstance; + + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + sharedOnceInstance = [[RiotDesignValues alloc] init]; + }); + + return sharedOnceInstance; +} + + (void)load { [super load]; @@ -46,22 +73,72 @@ NSInteger const kRiotRoomAdminLevel = 100; // Colors as defined by the design kRiotColorGreen = UIColorFromRGB(0x62CE9C); - kRiotColorLightGrey = [UIColor colorWithRed:(242.0 / 255.0) green:(242.0 / 255.0) blue:(242.0 / 255.0) alpha:1.0]; kRiotColorSilver = UIColorFromRGB(0xC7C7CC); kRiotColorPinkRed = UIColorFromRGB(0xFF0064); kRiotColorRed = UIColorFromRGB(0xFF4444); kRiotColorIndigo = UIColorFromRGB(0xBD79CC); kRiotColorOrange = UIColorFromRGB(0xF8A15F); - - kRiotTextColorBlack = [UIColor colorWithRed:(60.0 / 255.0) green:(60.0 / 255.0) blue:(60.0 / 255.0) alpha:1.0]; - kRiotTextColorDarkGray = [UIColor colorWithRed:(74.0 / 255.0) green:(74.0 / 255.0) blue:(74.0 / 255.0) alpha:1.0]; - kRiotTextColorGray = [UIColor colorWithRed:(157.0 / 255.0) green:(157.0 / 255.0) blue:(157.0 / 255.0) alpha:1.0]; - kRiotNavBarTintColor = kRiotColorLightGrey; + kRiotBgColorWhite = [UIColor whiteColor]; + kRiotBgColorBlack = UIColorFromRGB(0x2D2D2D); + + kRiotColorLightGrey = UIColorFromRGB(0xF2F2F2); + kRiotColorLightBlack = UIColorFromRGB(0x353535); + + kRiotTextColorBlack = UIColorFromRGB(0x3C3C3C); + kRiotTextColorDarkGray = UIColorFromRGB(0x4A4A4A); + kRiotTextColorGray = UIColorFromRGB(0x9D9D9D); + kRiotTextColorWhite = UIColorFromRGB(0xDDDDDD); + kRiotTextColorDarkWhite = UIColorFromRGB(0xD9D9D9); // Colors copied from Vector web kRiotColorLightGreen = UIColorFromRGB(0x50e2c2); kRiotColorLightOrange = UIColorFromRGB(0xf4c371); + + // Observe user interface theme change. + [[NSUserDefaults standardUserDefaults] addObserver:[RiotDesignValues sharedInstance] forKeyPath:@"userInterfaceTheme" options:0 context:nil]; + [[RiotDesignValues sharedInstance] userInterfaceThemeDidChange]; +} + + +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context +{ + if ([@"userInterfaceTheme" isEqualToString:keyPath]) + { + [self userInterfaceThemeDidChange]; + } +} + +- (void)userInterfaceThemeDidChange +{ + // Retrieve the current selected theme ("light" if none). + NSString *theme = [[NSUserDefaults standardUserDefaults] stringForKey:@"userInterfaceTheme"]; + + // Currently only 2 themes is supported + if ([theme isEqualToString:@"dark"]) + { + // Set dark theme colors + kRiotPrimaryBgColor = kRiotBgColorBlack; + kRiotSecondaryBgColor = kRiotColorLightBlack; + kRiotPrimaryTextColor = kRiotTextColorWhite; + kRiotSecondaryTextColor = kRiotTextColorGray; + kRiotTopicTextColor = kRiotTextColorDarkWhite; + + kRiotDesignStatusBarStyle = UIStatusBarStyleLightContent; + } + else + { + // Set light theme colors by default. + kRiotPrimaryBgColor = kRiotBgColorWhite; + kRiotSecondaryBgColor = kRiotColorLightGrey; + kRiotPrimaryTextColor = kRiotTextColorBlack; + kRiotSecondaryTextColor = kRiotTextColorGray; + kRiotTopicTextColor = kRiotTextColorDarkGray; + + kRiotDesignStatusBarStyle = UIStatusBarStyleDefault; + } + + [[NSNotificationCenter defaultCenter] postNotificationName:kRiotDesignValuesDidChangeThemeNotification object:nil]; } @end diff --git a/Riot/ViewController/AttachmentsViewController.m b/Riot/ViewController/AttachmentsViewController.m index 589b97bfc..a02845a13 100644 --- a/Riot/ViewController/AttachmentsViewController.m +++ b/Riot/ViewController/AttachmentsViewController.m @@ -19,6 +19,14 @@ #import "AppDelegate.h" +@interface AttachmentsViewController () +{ + // Observe kRiotDesignValuesDidChangeThemeNotification to handle user interface theme change. + id kRiotDesignValuesDidChangeThemeNotificationObserver; +} + +@end + @implementation AttachmentsViewController #pragma mark - @@ -27,8 +35,7 @@ { [super finalizeInit]; - // Setup `MXKViewControllerHandling` properties - self.defaultBarTintColor = kRiotNavBarTintColor; + // Setup `MXKViewControllerHandling` properties. self.enableBarTintColorStatusChange = NO; self.rageShakeManager = [RageShakeManager sharedManager]; } @@ -39,6 +46,20 @@ // Do any additional setup after loading the view, typically from a nib. self.attachmentsCollection.accessibilityIdentifier =@"AttachmentsVC"; + + // Observe user interface theme change. + kRiotDesignValuesDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kRiotDesignValuesDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { + + [self userInterfaceThemeDidChange]; + + }]; + [self userInterfaceThemeDidChange]; +} + +- (void)userInterfaceThemeDidChange +{ + self.view.backgroundColor = kRiotPrimaryBgColor; + self.defaultBarTintColor = kRiotSecondaryBgColor; } - (void)viewWillAppear:(BOOL)animated @@ -54,4 +75,15 @@ } } +- (void)destroy +{ + [super destroy]; + + if (kRiotDesignValuesDidChangeThemeNotificationObserver) + { + [[NSNotificationCenter defaultCenter] removeObserver:kRiotDesignValuesDidChangeThemeNotificationObserver]; + kRiotDesignValuesDidChangeThemeNotificationObserver = nil; + } +} + @end diff --git a/Riot/ViewController/AuthenticationViewController.h b/Riot/ViewController/AuthenticationViewController.h index dfc819591..67b3b0463 100644 --- a/Riot/ViewController/AuthenticationViewController.h +++ b/Riot/ViewController/AuthenticationViewController.h @@ -19,6 +19,8 @@ @interface AuthenticationViewController : MXKAuthenticationViewController +@property (weak, nonatomic) IBOutlet UINavigationBar *navigationBar; + @property (weak, nonatomic) IBOutlet UINavigationItem *mainNavigationItem; @property (weak, nonatomic) IBOutlet UIBarButtonItem *rightBarButtonItem; diff --git a/Riot/ViewController/AuthenticationViewController.m b/Riot/ViewController/AuthenticationViewController.m index 0c57dabf3..6a1a802a7 100644 --- a/Riot/ViewController/AuthenticationViewController.m +++ b/Riot/ViewController/AuthenticationViewController.m @@ -34,6 +34,11 @@ The default country code used to initialize the mobile phone number input. */ NSString *defaultCountryCode; + + /** + Observe kRiotDesignValuesDidChangeThemeNotification to handle user interface theme change. + */ + id kRiotDesignValuesDidChangeThemeNotificationObserver; } @end @@ -59,7 +64,6 @@ [super finalizeInit]; // Setup `MXKViewControllerHandling` properties - self.defaultBarTintColor = kRiotNavBarTintColor; self.enableBarTintColorStatusChange = NO; self.rageShakeManager = [RageShakeManager sharedManager]; @@ -76,12 +80,8 @@ self.rightBarButtonItem.title = NSLocalizedStringFromTable(@"auth_register", @"Vector", nil); self.defaultHomeServerUrl = [[NSUserDefaults standardUserDefaults] objectForKey:@"homeserverurl"]; - self.homeServerTextField.textColor = kRiotTextColorBlack; - self.homeServerLabel.textColor = kRiotTextColorGray; self.defaultIdentityServerUrl = [[NSUserDefaults standardUserDefaults] objectForKey:@"identityserverurl"]; - self.identityServerTextField.textColor = kRiotTextColorBlack; - self.identityServerLabel.textColor = kRiotTextColorGray; self.welcomeImageView.image = [UIImage imageNamed:@"logo"]; @@ -129,6 +129,32 @@ MXAuthenticationSession *authSession = [MXAuthenticationSession modelFromJSON:@{@"flows":@[@{@"stages":@[kMXLoginFlowTypePassword]}]}]; [authInputsView setAuthSession:authSession withAuthType:MXKAuthenticationTypeLogin]; self.authInputsView = authInputsView; + + // Observe user interface theme change. + kRiotDesignValuesDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kRiotDesignValuesDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { + + [self userInterfaceThemeDidChange]; + + }]; + [self userInterfaceThemeDidChange]; +} + +- (void)userInterfaceThemeDidChange +{ + self.view.backgroundColor = kRiotSecondaryBgColor; + self.navigationBar.barTintColor = kRiotSecondaryBgColor; + self.authenticationScrollView.backgroundColor = kRiotPrimaryBgColor; + self.authFallbackContentView.backgroundColor = kRiotPrimaryBgColor; + + self.homeServerTextField.textColor = kRiotPrimaryTextColor; + self.homeServerLabel.textColor = kRiotTextColorGray; + + self.identityServerTextField.textColor = kRiotPrimaryTextColor; + self.identityServerLabel.textColor = kRiotTextColorGray; + + self.defaultBarTintColor = kRiotSecondaryBgColor; + + [[UIApplication sharedApplication] setStatusBarStyle:kRiotDesignStatusBarStyle animated:NO]; } - (void)viewWillAppear:(BOOL)animated @@ -144,6 +170,17 @@ } } +- (void)destroy +{ + [super destroy]; + + if (kRiotDesignValuesDidChangeThemeNotificationObserver) + { + [[NSNotificationCenter defaultCenter] removeObserver:kRiotDesignValuesDidChangeThemeNotificationObserver]; + kRiotDesignValuesDidChangeThemeNotificationObserver = nil; + } +} + - (void)setAuthType:(MXKAuthenticationType)authType { if (self.authType == MXKAuthenticationTypeRegister) diff --git a/Riot/ViewController/AuthenticationViewController.xib b/Riot/ViewController/AuthenticationViewController.xib index 4b4481795..1bfa7d80e 100644 --- a/Riot/ViewController/AuthenticationViewController.xib +++ b/Riot/ViewController/AuthenticationViewController.xib @@ -34,6 +34,7 @@ + @@ -51,7 +52,7 @@ - + @@ -84,7 +85,7 @@ - + @@ -121,7 +122,7 @@ - + @@ -254,7 +255,7 @@ - + @@ -302,7 +303,7 @@ - + @@ -318,7 +319,7 @@ - + @@ -331,7 +332,7 @@ - + @@ -344,7 +345,7 @@ - + @@ -362,7 +363,7 @@ - + diff --git a/Riot/ViewController/CallViewController.m b/Riot/ViewController/CallViewController.m index f6f580b66..a83bf4e7e 100644 --- a/Riot/ViewController/CallViewController.m +++ b/Riot/ViewController/CallViewController.m @@ -30,10 +30,11 @@ // Display a gradient view above the screen CAGradientLayer* gradientMaskLayer; - /** - Current alert (if any). - */ + // Current alert (if any). UIAlertController *currentAlert; + + // Observe kRiotDesignValuesDidChangeThemeNotification to handle user interface theme change. + id kRiotDesignValuesDidChangeThemeNotificationObserver; } @end @@ -45,7 +46,6 @@ [super finalizeInit]; // Setup `MXKViewControllerHandling` properties - self.defaultBarTintColor = kRiotNavBarTintColor; self.enableBarTintColorStatusChange = NO; self.rageShakeManager = [RageShakeManager sharedManager]; } @@ -108,6 +108,20 @@ [self.gradientMaskContainerView.layer addSublayer:gradientMaskLayer]; [self updateLocalPreviewLayout]; + + // Observe user interface theme change. + kRiotDesignValuesDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kRiotDesignValuesDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { + + [self userInterfaceThemeDidChange]; + + }]; + [self userInterfaceThemeDidChange]; +} + +- (void)userInterfaceThemeDidChange +{ + self.view.backgroundColor = kRiotPrimaryBgColor; + self.defaultBarTintColor = kRiotSecondaryBgColor; } - (void)viewDidLayoutSubviews @@ -154,6 +168,12 @@ { [super destroy]; + if (kRiotDesignValuesDidChangeThemeNotificationObserver) + { + [[NSNotificationCenter defaultCenter] removeObserver:kRiotDesignValuesDidChangeThemeNotificationObserver]; + kRiotDesignValuesDidChangeThemeNotificationObserver = nil; + } + [gradientMaskLayer removeFromSuperlayer]; gradientMaskLayer = nil; } diff --git a/Riot/ViewController/ContactDetailsViewController.m b/Riot/ViewController/ContactDetailsViewController.m index 7e3e82076..76c436534 100644 --- a/Riot/ViewController/ContactDetailsViewController.m +++ b/Riot/ViewController/ContactDetailsViewController.m @@ -74,6 +74,11 @@ Current alert (if any). */ UIAlertController *currentAlert; + + /** + Observe kRiotDesignValuesDidChangeThemeNotification to handle user interface theme change. + */ + id kRiotDesignValuesDidChangeThemeNotificationObserver; } @end @@ -100,7 +105,6 @@ [super finalizeInit]; // Setup `MXKViewControllerHandling` properties - self.defaultBarTintColor = kRiotNavBarTintColor; self.enableBarTintColorStatusChange = NO; self.rageShakeManager = [RageShakeManager sharedManager]; } @@ -202,6 +206,19 @@ NSNumber *orientation = (NSNumber*)(notif.userInfo[UIApplicationStatusBarOrientationUserInfoKey]); self.bottomImageView.hidden = (orientation.integerValue == UIInterfaceOrientationLandscapeLeft || orientation.integerValue == UIInterfaceOrientationLandscapeRight); }]; + + // Observe user interface theme change. + kRiotDesignValuesDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kRiotDesignValuesDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { + + [self userInterfaceThemeDidChange]; + + }]; + [self userInterfaceThemeDidChange]; +} + +- (void)userInterfaceThemeDidChange +{ + self.defaultBarTintColor = kRiotSecondaryBgColor; } - (void)viewWillAppear:(BOOL)animated @@ -271,6 +288,12 @@ { [super destroy]; + if (kRiotDesignValuesDidChangeThemeNotificationObserver) + { + [[NSNotificationCenter defaultCenter] removeObserver:kRiotDesignValuesDidChangeThemeNotificationObserver]; + kRiotDesignValuesDidChangeThemeNotificationObserver = nil; + } + if (roomCreationRequest) { [roomCreationRequest cancel]; diff --git a/Riot/ViewController/ContactsTableViewController.m b/Riot/ViewController/ContactsTableViewController.m index 83df3d870..921094c8e 100644 --- a/Riot/ViewController/ContactsTableViewController.m +++ b/Riot/ViewController/ContactsTableViewController.m @@ -29,8 +29,15 @@ @interface ContactsTableViewController () { - // Observe kAppDelegateDidTapStatusBarNotification to handle tap on clock status bar. + /** + Observe kAppDelegateDidTapStatusBarNotification to handle tap on clock status bar. + */ id kAppDelegateDidTapStatusBarNotificationObserver; + + /** + Observe kRiotDesignValuesDidChangeThemeNotification to handle user interface theme change. + */ + id kRiotDesignValuesDidChangeThemeNotificationObserver; } @end @@ -58,7 +65,6 @@ [super finalizeInit]; // Setup `MXKViewControllerHandling` properties - self.defaultBarTintColor = kRiotNavBarTintColor; self.enableBarTintColorStatusChange = NO; self.rageShakeManager = [RageShakeManager sharedManager]; @@ -85,6 +91,19 @@ // Hide line separators of empty cells self.contactsTableView.tableFooterView = [[UIView alloc] init]; + + // Observe user interface theme change. + kRiotDesignValuesDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kRiotDesignValuesDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { + + [self userInterfaceThemeDidChange]; + + }]; + [self userInterfaceThemeDidChange]; +} + +- (void)userInterfaceThemeDidChange +{ + self.defaultBarTintColor = kRiotSecondaryBgColor; } - (void)didReceiveMemoryWarning @@ -96,6 +115,12 @@ - (void)destroy { [super destroy]; + + if (kRiotDesignValuesDidChangeThemeNotificationObserver) + { + [[NSNotificationCenter defaultCenter] removeObserver:kRiotDesignValuesDidChangeThemeNotificationObserver]; + kRiotDesignValuesDidChangeThemeNotificationObserver = nil; + } } - (void)viewWillAppear:(BOOL)animated diff --git a/Riot/ViewController/CountryPickerViewController.m b/Riot/ViewController/CountryPickerViewController.m index 87237af0c..e5f311559 100644 --- a/Riot/ViewController/CountryPickerViewController.m +++ b/Riot/ViewController/CountryPickerViewController.m @@ -18,6 +18,16 @@ #import "AppDelegate.h" +@interface CountryPickerViewController () +{ + /** + Observe kRiotDesignValuesDidChangeThemeNotification to handle user interface theme change. + */ + id kRiotDesignValuesDidChangeThemeNotificationObserver; +} + +@end + @implementation CountryPickerViewController - (void)finalizeInit @@ -25,7 +35,6 @@ [super finalizeInit]; // Setup `MXKViewControllerHandling` properties - self.defaultBarTintColor = kRiotNavBarTintColor; self.enableBarTintColorStatusChange = NO; self.rageShakeManager = [RageShakeManager sharedManager]; } @@ -49,6 +58,30 @@ [tracker set:kGAIScreenName value:@"CountryPicker"]; [tracker send:[[GAIDictionaryBuilder createScreenView] build]]; } + + // Observe user interface theme change. + kRiotDesignValuesDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kRiotDesignValuesDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { + + [self userInterfaceThemeDidChange]; + + }]; + [self userInterfaceThemeDidChange]; +} + +- (void)userInterfaceThemeDidChange +{ + self.defaultBarTintColor = kRiotSecondaryBgColor; +} + +- (void)destroy +{ + [super destroy]; + + if (kRiotDesignValuesDidChangeThemeNotificationObserver) + { + [[NSNotificationCenter defaultCenter] removeObserver:kRiotDesignValuesDidChangeThemeNotificationObserver]; + kRiotDesignValuesDidChangeThemeNotificationObserver = nil; + } } @end diff --git a/Riot/ViewController/DirectoryServerPickerViewController.m b/Riot/ViewController/DirectoryServerPickerViewController.m index 07f2ce68f..a4a0d2bf2 100644 --- a/Riot/ViewController/DirectoryServerPickerViewController.m +++ b/Riot/ViewController/DirectoryServerPickerViewController.m @@ -34,6 +34,9 @@ // Current request in progress. MXHTTPOperation *mxCurrentOperation; + + // Observe kRiotDesignValuesDidChangeThemeNotification to handle user interface theme change. + id kRiotDesignValuesDidChangeThemeNotificationObserver; } @end @@ -44,7 +47,6 @@ [super finalizeInit]; // Setup `MXKViewControllerHandling` properties - self.defaultBarTintColor = kRiotNavBarTintColor; self.enableBarTintColorStatusChange = NO; self.rageShakeManager = [RageShakeManager sharedManager]; } @@ -54,6 +56,12 @@ dataSource.delegate = nil; dataSource = nil; onCompleteBlock = nil; + + if (kRiotDesignValuesDidChangeThemeNotificationObserver) + { + [[NSNotificationCenter defaultCenter] removeObserver:kRiotDesignValuesDidChangeThemeNotificationObserver]; + kRiotDesignValuesDidChangeThemeNotificationObserver = nil; + } if (kAppDelegateDidTapStatusBarNotificationObserver) { @@ -99,6 +107,19 @@ // Hide line separators of empty cells self.tableView.tableFooterView = [[UIView alloc] init]; + + // Observe user interface theme change. + kRiotDesignValuesDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kRiotDesignValuesDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { + + [self userInterfaceThemeDidChange]; + + }]; + [self userInterfaceThemeDidChange]; +} + +- (void)userInterfaceThemeDidChange +{ + self.defaultBarTintColor = kRiotSecondaryBgColor; } - (void)viewWillAppear:(BOOL)animated diff --git a/Riot/ViewController/DirectoryViewController.m b/Riot/ViewController/DirectoryViewController.m index ed5156d0f..19c9ef4f3 100644 --- a/Riot/ViewController/DirectoryViewController.m +++ b/Riot/ViewController/DirectoryViewController.m @@ -30,6 +30,9 @@ // The animated view displayed at the table view bottom when paginating UIView* footerSpinnerView; + + // Observe kRiotDesignValuesDidChangeThemeNotification to handle user interface theme change. + id kRiotDesignValuesDidChangeThemeNotificationObserver; } @end @@ -41,7 +44,6 @@ [super finalizeInit]; // Setup `MXKViewControllerHandling` properties - self.defaultBarTintColor = kRiotNavBarTintColor; self.enableBarTintColorStatusChange = NO; self.rageShakeManager = [RageShakeManager sharedManager]; } @@ -56,6 +58,30 @@ // Hide line separators of empty cells self.tableView.tableFooterView = [[UIView alloc] init]; + + // Observe user interface theme change. + kRiotDesignValuesDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kRiotDesignValuesDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { + + [self userInterfaceThemeDidChange]; + + }]; + [self userInterfaceThemeDidChange]; +} + +- (void)userInterfaceThemeDidChange +{ + self.defaultBarTintColor = kRiotSecondaryBgColor; +} + +- (void)destroy +{ + [super destroy]; + + if (kRiotDesignValuesDidChangeThemeNotificationObserver) + { + [[NSNotificationCenter defaultCenter] removeObserver:kRiotDesignValuesDidChangeThemeNotificationObserver]; + kRiotDesignValuesDidChangeThemeNotificationObserver = nil; + } } - (void)viewWillAppear:(BOOL)animated diff --git a/Riot/ViewController/HomeFilesSearchViewController.m b/Riot/ViewController/HomeFilesSearchViewController.m index 7d08185b9..fd20607a1 100644 --- a/Riot/ViewController/HomeFilesSearchViewController.m +++ b/Riot/ViewController/HomeFilesSearchViewController.m @@ -26,6 +26,16 @@ #import "EventFormatter.h" +@interface HomeFilesSearchViewController() +{ + /** + Observe kRiotDesignValuesDidChangeThemeNotification to handle user interface theme change. + */ + id kRiotDesignValuesDidChangeThemeNotificationObserver; +} + +@end + @implementation HomeFilesSearchViewController - (void)finalizeInit @@ -33,7 +43,6 @@ [super finalizeInit]; // Setup `MXKViewControllerHandling` properties - self.defaultBarTintColor = kRiotNavBarTintColor; self.enableBarTintColorStatusChange = NO; self.rageShakeManager = [RageShakeManager sharedManager]; } @@ -49,6 +58,30 @@ // Hide line separators of empty cells self.searchTableView.tableFooterView = [[UIView alloc] init]; + + // Observe user interface theme change. + kRiotDesignValuesDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kRiotDesignValuesDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { + + [self userInterfaceThemeDidChange]; + + }]; + [self userInterfaceThemeDidChange]; +} + +- (void)userInterfaceThemeDidChange +{ + self.defaultBarTintColor = kRiotSecondaryBgColor; +} + +- (void)destroy +{ + [super destroy]; + + if (kRiotDesignValuesDidChangeThemeNotificationObserver) + { + [[NSNotificationCenter defaultCenter] removeObserver:kRiotDesignValuesDidChangeThemeNotificationObserver]; + kRiotDesignValuesDidChangeThemeNotificationObserver = nil; + } } - (void)viewWillAppear:(BOOL)animated diff --git a/Riot/ViewController/HomeMessagesSearchViewController.m b/Riot/ViewController/HomeMessagesSearchViewController.m index 2f6049091..9756cbe27 100644 --- a/Riot/ViewController/HomeMessagesSearchViewController.m +++ b/Riot/ViewController/HomeMessagesSearchViewController.m @@ -30,6 +30,16 @@ #import "EventFormatter.h" +@interface HomeMessagesSearchViewController () +{ + /** + Observe kRiotDesignValuesDidChangeThemeNotification to handle user interface theme change. + */ + id kRiotDesignValuesDidChangeThemeNotificationObserver; +} + +@end + @implementation HomeMessagesSearchViewController - (void)finalizeInit @@ -37,7 +47,6 @@ [super finalizeInit]; // Setup `MXKViewControllerHandling` properties - self.defaultBarTintColor = kRiotNavBarTintColor; self.enableBarTintColorStatusChange = NO; self.rageShakeManager = [RageShakeManager sharedManager]; } @@ -56,6 +65,30 @@ // Hide line separators of empty cells self.searchTableView.tableFooterView = [[UIView alloc] init]; + + // Observe user interface theme change. + kRiotDesignValuesDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kRiotDesignValuesDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { + + [self userInterfaceThemeDidChange]; + + }]; + [self userInterfaceThemeDidChange]; +} + +- (void)userInterfaceThemeDidChange +{ + self.defaultBarTintColor = kRiotSecondaryBgColor; +} + +- (void)destroy +{ + [super destroy]; + + if (kRiotDesignValuesDidChangeThemeNotificationObserver) + { + [[NSNotificationCenter defaultCenter] removeObserver:kRiotDesignValuesDidChangeThemeNotificationObserver]; + kRiotDesignValuesDidChangeThemeNotificationObserver = nil; + } } - (void)viewWillAppear:(BOOL)animated diff --git a/Riot/ViewController/MasterTabBarController.m b/Riot/ViewController/MasterTabBarController.m index c0cf93993..7f4f48b9b 100644 --- a/Riot/ViewController/MasterTabBarController.m +++ b/Riot/ViewController/MasterTabBarController.m @@ -46,6 +46,9 @@ // Current alert (if any). UIAlertController *currentAlert; + + // Keep reference on the pushed view controllers to release them correctly + NSMutableArray *childViewControllers; } @property(nonatomic,getter=isHidden) BOOL hidden; @@ -76,6 +79,8 @@ tabBarItem.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0); } + childViewControllers = [NSMutableArray array]; + // Initialize here the data sources if a matrix session has been already set. [self initializeDataSources]; } @@ -107,6 +112,31 @@ } [self refreshTabBarBadges]; + + // Release properly pushed and/or presented view controller + if (childViewControllers.count) + { + for (id viewController in childViewControllers) + { + if ([viewController isKindOfClass:[UINavigationController class]]) + { + UINavigationController *navigationController = (UINavigationController*)viewController; + for (id subViewController in navigationController.viewControllers) + { + if ([subViewController respondsToSelector:@selector(destroy)]) + { + [subViewController destroy]; + } + } + } + else if ([viewController respondsToSelector:@selector(destroy)]) + { + [viewController destroy]; + } + } + + [childViewControllers removeAllObjects]; + } } if (unifiedSearchViewController) @@ -141,6 +171,8 @@ [[NSNotificationCenter defaultCenter] removeObserver:authViewControllerObserver]; authViewControllerObserver = nil; } + + childViewControllers = nil; } #pragma mark - @@ -546,7 +578,7 @@ else { // Keep ref on destinationViewController - [super prepareForSegue:segue sender:sender]; + [childViewControllers addObject:segue.destinationViewController]; if ([[segue identifier] isEqualToString:@"showAuth"]) { @@ -585,6 +617,14 @@ self.navigationController.topViewController.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]; } +- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion +{ + // Keep ref on presented view controller + [childViewControllers addObject:viewControllerToPresent]; + + [super presentViewController:viewControllerToPresent animated:flag completion:completion]; +} + // Made the actual selected view controller update its selected cell. - (void)refreshCurrentSelectedCell:(BOOL)forceVisible { diff --git a/Riot/ViewController/MediaAlbumContentViewController.m b/Riot/ViewController/MediaAlbumContentViewController.m index e7ae70b28..9b3c999b2 100644 --- a/Riot/ViewController/MediaAlbumContentViewController.m +++ b/Riot/ViewController/MediaAlbumContentViewController.m @@ -37,6 +37,11 @@ The currently selected media. Nil when the multiselection is not active. */ NSMutableArray *selectedAssets; + + /** + Observe kRiotDesignValuesDidChangeThemeNotification to handle user interface theme change. + */ + id kRiotDesignValuesDidChangeThemeNotificationObserver; } @end @@ -64,7 +69,6 @@ [super finalizeInit]; // Setup `MXKViewControllerHandling` properties - self.defaultBarTintColor = kRiotNavBarTintColor; self.enableBarTintColorStatusChange = NO; self.rageShakeManager = [RageShakeManager sharedManager]; } @@ -95,11 +99,30 @@ { self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedStringFromTable(@"media_picker_select", @"Vector", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onSelect:)]; } + + // Observe user interface theme change. + kRiotDesignValuesDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kRiotDesignValuesDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { + + [self userInterfaceThemeDidChange]; + + }]; + [self userInterfaceThemeDidChange]; } -- (void)dealloc +- (void)userInterfaceThemeDidChange { + self.defaultBarTintColor = kRiotSecondaryBgColor; +} + +- (void)destroy +{ + [super destroy]; + if (kRiotDesignValuesDidChangeThemeNotificationObserver) + { + [[NSNotificationCenter defaultCenter] removeObserver:kRiotDesignValuesDidChangeThemeNotificationObserver]; + kRiotDesignValuesDidChangeThemeNotificationObserver = nil; + } } - (void)didReceiveMemoryWarning @@ -189,13 +212,6 @@ [self.assetsCollectionView reloadData]; } -#pragma mark - Override MXKViewController - -- (void)destroy -{ - [super destroy]; -} - #pragma mark - UICollectionViewDataSource - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section diff --git a/Riot/ViewController/MediaPickerViewController.m b/Riot/ViewController/MediaPickerViewController.m index 4bc0b3324..ea6e5a900 100644 --- a/Riot/ViewController/MediaPickerViewController.m +++ b/Riot/ViewController/MediaPickerViewController.m @@ -78,7 +78,11 @@ static void *RecordingContext = &RecordingContext; NSTimer *updateVideoRecordingTimer; NSDate *videoRecordStartDate; - + + /** + Observe kRiotDesignValuesDidChangeThemeNotification to handle user interface theme change. + */ + id kRiotDesignValuesDidChangeThemeNotificationObserver; } @property (nonatomic) UIBackgroundTaskIdentifier backgroundRecordingID; @@ -108,7 +112,6 @@ static void *RecordingContext = &RecordingContext; [super finalizeInit]; // Setup `MXKViewControllerHandling` properties - self.defaultBarTintColor = kRiotNavBarTintColor; self.enableBarTintColorStatusChange = NO; self.rageShakeManager = [RageShakeManager sharedManager]; @@ -155,6 +158,19 @@ static void *RecordingContext = &RecordingContext; [self reloadUserLibraryAlbums]; }]; + + // Observe user interface theme change. + kRiotDesignValuesDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kRiotDesignValuesDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { + + [self userInterfaceThemeDidChange]; + + }]; + [self userInterfaceThemeDidChange]; +} + +- (void)userInterfaceThemeDidChange +{ + self.defaultBarTintColor = kRiotSecondaryBgColor; } - (void)viewDidLayoutSubviews @@ -853,6 +869,12 @@ static void *RecordingContext = &RecordingContext; { [self stopAVCapture]; + if (kRiotDesignValuesDidChangeThemeNotificationObserver) + { + [[NSNotificationCenter defaultCenter] removeObserver:kRiotDesignValuesDidChangeThemeNotificationObserver]; + kRiotDesignValuesDidChangeThemeNotificationObserver = nil; + } + if (UIApplicationWillEnterForegroundNotificationObserver) { [[NSNotificationCenter defaultCenter] removeObserver:UIApplicationWillEnterForegroundNotificationObserver]; diff --git a/Riot/ViewController/RecentsViewController.m b/Riot/ViewController/RecentsViewController.m index fa6ac30e1..4a54e7594 100644 --- a/Riot/ViewController/RecentsViewController.m +++ b/Riot/ViewController/RecentsViewController.m @@ -60,6 +60,9 @@ // The fake search bar displayed at the top of the recents table. We switch on the actual search bar (self.recentsSearchBar) // when the user selects it. UISearchBar *tableSearchBar; + + // Observe kRiotDesignValuesDidChangeThemeNotification to handle user interface theme change. + id kRiotDesignValuesDidChangeThemeNotificationObserver; } @end @@ -87,7 +90,6 @@ [super finalizeInit]; // Setup `MXKViewControllerHandling` properties - self.defaultBarTintColor = kRiotNavBarTintColor; self.enableBarTintColorStatusChange = NO; self.rageShakeManager = [RageShakeManager sharedManager]; @@ -143,6 +145,19 @@ self.recentsSearchBar.autocapitalizationType = UITextAutocapitalizationTypeNone; self.recentsSearchBar.placeholder = NSLocalizedStringFromTable(@"search_default_placeholder", @"Vector", nil); + + // Observe user interface theme change. + kRiotDesignValuesDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kRiotDesignValuesDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { + + [self userInterfaceThemeDidChange]; + + }]; + [self userInterfaceThemeDidChange]; +} + +- (void)userInterfaceThemeDidChange +{ + self.defaultBarTintColor = kRiotSecondaryBgColor; } - (void)destroy @@ -168,6 +183,12 @@ [[NSNotificationCenter defaultCenter] removeObserver:UIApplicationDidEnterBackgroundNotificationObserver]; UIApplicationDidEnterBackgroundNotificationObserver = nil; } + + if (kRiotDesignValuesDidChangeThemeNotificationObserver) + { + [[NSNotificationCenter defaultCenter] removeObserver:kRiotDesignValuesDidChangeThemeNotificationObserver]; + kRiotDesignValuesDidChangeThemeNotificationObserver = nil; + } } - (void)setEditing:(BOOL)editing animated:(BOOL)animated diff --git a/Riot/ViewController/RoomFilesSearchViewController.m b/Riot/ViewController/RoomFilesSearchViewController.m index fa25e3a5b..8794dae73 100644 --- a/Riot/ViewController/RoomFilesSearchViewController.m +++ b/Riot/ViewController/RoomFilesSearchViewController.m @@ -30,6 +30,9 @@ { // Observe kAppDelegateDidTapStatusBarNotification to handle tap on clock status bar. id kAppDelegateDidTapStatusBarNotificationObserver; + + // Observe kRiotDesignValuesDidChangeThemeNotification to handle user interface theme change. + id kRiotDesignValuesDidChangeThemeNotificationObserver; } @end @@ -41,7 +44,6 @@ [super finalizeInit]; // Setup `MXKViewControllerHandling` properties - self.defaultBarTintColor = kRiotNavBarTintColor; self.enableBarTintColorStatusChange = NO; self.rageShakeManager = [RageShakeManager sharedManager]; } @@ -57,6 +59,30 @@ [self.searchTableView registerClass:FilesSearchTableViewCell.class forCellReuseIdentifier:FilesSearchTableViewCell.defaultReuseIdentifier]; self.searchTableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag; + + // Observe user interface theme change. + kRiotDesignValuesDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kRiotDesignValuesDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { + + [self userInterfaceThemeDidChange]; + + }]; + [self userInterfaceThemeDidChange]; +} + +- (void)userInterfaceThemeDidChange +{ + self.defaultBarTintColor = kRiotSecondaryBgColor; +} + +- (void)destroy +{ + [super destroy]; + + if (kRiotDesignValuesDidChangeThemeNotificationObserver) + { + [[NSNotificationCenter defaultCenter] removeObserver:kRiotDesignValuesDidChangeThemeNotificationObserver]; + kRiotDesignValuesDidChangeThemeNotificationObserver = nil; + } } - (void)viewWillAppear:(BOOL)animated diff --git a/Riot/ViewController/RoomFilesViewController.m b/Riot/ViewController/RoomFilesViewController.m index d602b906b..a0c4ea1c3 100644 --- a/Riot/ViewController/RoomFilesViewController.m +++ b/Riot/ViewController/RoomFilesViewController.m @@ -23,6 +23,16 @@ #import "AttachmentsViewController.h" +@interface RoomFilesViewController () +{ + /** + Observe kRiotDesignValuesDidChangeThemeNotification to handle user interface theme change. + */ + id kRiotDesignValuesDidChangeThemeNotificationObserver; +} + +@end + @implementation RoomFilesViewController #pragma mark - @@ -56,7 +66,6 @@ [super finalizeInit]; // Setup `MXKViewControllerHandling` properties - self.defaultBarTintColor = kRiotNavBarTintColor; self.enableBarTintColorStatusChange = NO; self.rageShakeManager = [RageShakeManager sharedManager]; } @@ -88,6 +97,30 @@ [UIView setAnimationsEnabled:NO]; [self roomInputToolbarView:self.inputToolbarView heightDidChanged:0 completion:nil]; [UIView setAnimationsEnabled:YES]; + + // Observe user interface theme change. + kRiotDesignValuesDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kRiotDesignValuesDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { + + [self userInterfaceThemeDidChange]; + + }]; + [self userInterfaceThemeDidChange]; +} + +- (void)userInterfaceThemeDidChange +{ + self.defaultBarTintColor = kRiotSecondaryBgColor; +} + +- (void)destroy +{ + [super destroy]; + + if (kRiotDesignValuesDidChangeThemeNotificationObserver) + { + [[NSNotificationCenter defaultCenter] removeObserver:kRiotDesignValuesDidChangeThemeNotificationObserver]; + kRiotDesignValuesDidChangeThemeNotificationObserver = nil; + } } // This method is called when the viewcontroller is added or removed from a container view controller. diff --git a/Riot/ViewController/RoomMemberDetailsViewController.m b/Riot/ViewController/RoomMemberDetailsViewController.m index 11c60c5d8..a1c44e913 100644 --- a/Riot/ViewController/RoomMemberDetailsViewController.m +++ b/Riot/ViewController/RoomMemberDetailsViewController.m @@ -66,6 +66,11 @@ Observe UIApplicationWillChangeStatusBarOrientationNotification to hide/show bubbles bg. */ id UIApplicationWillChangeStatusBarOrientationNotificationObserver; + + /** + Observe kRiotDesignValuesDidChangeThemeNotification to handle user interface theme change. + */ + id kRiotDesignValuesDidChangeThemeNotificationObserver; } @end @@ -92,7 +97,6 @@ [super finalizeInit]; // Setup `MXKViewControllerHandling` properties - self.defaultBarTintColor = kRiotNavBarTintColor; self.enableBarTintColorStatusChange = NO; self.rageShakeManager = [RageShakeManager sharedManager]; @@ -187,6 +191,19 @@ NSNumber *orientation = (NSNumber*)(notif.userInfo[UIApplicationStatusBarOrientationUserInfoKey]); self.bottomImageView.hidden = (orientation.integerValue == UIInterfaceOrientationLandscapeLeft || orientation.integerValue == UIInterfaceOrientationLandscapeRight); }]; + + // Observe user interface theme change. + kRiotDesignValuesDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kRiotDesignValuesDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { + + [self userInterfaceThemeDidChange]; + + }]; + [self userInterfaceThemeDidChange]; +} + +- (void)userInterfaceThemeDidChange +{ + self.defaultBarTintColor = kRiotSecondaryBgColor; } - (void)viewWillAppear:(BOOL)animated @@ -249,6 +266,12 @@ UIApplicationWillChangeStatusBarOrientationNotificationObserver = nil; } + if (kRiotDesignValuesDidChangeThemeNotificationObserver) + { + [[NSNotificationCenter defaultCenter] removeObserver:kRiotDesignValuesDidChangeThemeNotificationObserver]; + kRiotDesignValuesDidChangeThemeNotificationObserver = nil; + } + [memberTitleView removeFromSuperview]; memberTitleView = nil; } diff --git a/Riot/ViewController/RoomMessagesSearchViewController.m b/Riot/ViewController/RoomMessagesSearchViewController.m index fd08d6521..7d9b36be5 100644 --- a/Riot/ViewController/RoomMessagesSearchViewController.m +++ b/Riot/ViewController/RoomMessagesSearchViewController.m @@ -32,6 +32,9 @@ { // Observe kAppDelegateDidTapStatusBarNotification to handle tap on clock status bar. id kAppDelegateDidTapStatusBarNotificationObserver; + + // Observe kRiotDesignValuesDidChangeThemeNotification to handle user interface theme change. + id kRiotDesignValuesDidChangeThemeNotificationObserver; } @end @@ -43,7 +46,6 @@ [super finalizeInit]; // Setup `MXKViewControllerHandling` properties - self.defaultBarTintColor = kRiotNavBarTintColor; self.enableBarTintColorStatusChange = NO; self.rageShakeManager = [RageShakeManager sharedManager]; } @@ -58,6 +60,30 @@ // Reuse cells from the RoomViewController to display results [self.searchTableView registerClass:RoomIncomingTextMsgBubbleCell.class forCellReuseIdentifier:RoomIncomingTextMsgBubbleCell.defaultReuseIdentifier]; [self.searchTableView registerClass:RoomIncomingAttachmentBubbleCell.class forCellReuseIdentifier:RoomIncomingAttachmentBubbleCell.defaultReuseIdentifier]; + + // Observe user interface theme change. + kRiotDesignValuesDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kRiotDesignValuesDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { + + [self userInterfaceThemeDidChange]; + + }]; + [self userInterfaceThemeDidChange]; +} + +- (void)userInterfaceThemeDidChange +{ + self.defaultBarTintColor = kRiotSecondaryBgColor; +} + +- (void)destroy +{ + [super destroy]; + + if (kRiotDesignValuesDidChangeThemeNotificationObserver) + { + [[NSNotificationCenter defaultCenter] removeObserver:kRiotDesignValuesDidChangeThemeNotificationObserver]; + kRiotDesignValuesDidChangeThemeNotificationObserver = nil; + } } - (void)viewWillAppear:(BOOL)animated diff --git a/Riot/ViewController/RoomParticipantsViewController.m b/Riot/ViewController/RoomParticipantsViewController.m index 0d79f73ff..88ebc5d00 100644 --- a/Riot/ViewController/RoomParticipantsViewController.m +++ b/Riot/ViewController/RoomParticipantsViewController.m @@ -59,6 +59,9 @@ NSLayoutConstraint *addParticipantButtonImageViewBottomConstraint; UIAlertController *currentAlert; + + // Observe kRiotDesignValuesDidChangeThemeNotification to handle user interface theme change. + id kRiotDesignValuesDidChangeThemeNotificationObserver; } @end @@ -86,7 +89,6 @@ [super finalizeInit]; // Setup `MXKViewControllerHandling` properties - self.defaultBarTintColor = kRiotNavBarTintColor; self.enableBarTintColorStatusChange = NO; self.rageShakeManager = [RageShakeManager sharedManager]; } @@ -145,6 +147,19 @@ // Add room creation button programmatically [self addAddParticipantButton]; + + // Observe user interface theme change. + kRiotDesignValuesDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kRiotDesignValuesDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { + + [self userInterfaceThemeDidChange]; + + }]; + [self userInterfaceThemeDidChange]; +} + +- (void)userInterfaceThemeDidChange +{ + self.defaultBarTintColor = kRiotSecondaryBgColor; } // This method is called when the viewcontroller is added or removed from a container view controller. @@ -157,6 +172,12 @@ - (void)destroy { + if (kRiotDesignValuesDidChangeThemeNotificationObserver) + { + [[NSNotificationCenter defaultCenter] removeObserver:kRiotDesignValuesDidChangeThemeNotificationObserver]; + kRiotDesignValuesDidChangeThemeNotificationObserver = nil; + } + if (leaveRoomNotificationObserver) { [[NSNotificationCenter defaultCenter] removeObserver:leaveRoomNotificationObserver]; diff --git a/Riot/ViewController/RoomSettingsViewController.m b/Riot/ViewController/RoomSettingsViewController.m index e0b147dca..6b72e9589 100644 --- a/Riot/ViewController/RoomSettingsViewController.m +++ b/Riot/ViewController/RoomSettingsViewController.m @@ -147,6 +147,9 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti // A copy of the banned members NSArray *bannedMembers; + + // Observe kRiotDesignValuesDidChangeThemeNotification to handle user interface theme change. + id kRiotDesignValuesDidChangeThemeNotificationObserver; } @end @@ -159,7 +162,6 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti _selectedRoomSettingsField = RoomSettingsViewControllerFieldNone; // Setup `MXKViewControllerHandling` properties - self.defaultBarTintColor = kRiotNavBarTintColor; self.enableBarTintColorStatusChange = NO; self.rageShakeManager = [RageShakeManager sharedManager]; } @@ -232,6 +234,19 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti self.tableView.estimatedRowHeight = 44; [self setNavBarButtons]; + + // Observe user interface theme change. + kRiotDesignValuesDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kRiotDesignValuesDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { + + [self userInterfaceThemeDidChange]; + + }]; + [self userInterfaceThemeDidChange]; +} + +- (void)userInterfaceThemeDidChange +{ + self.defaultBarTintColor = kRiotSecondaryBgColor; } - (void)viewWillAppear:(BOOL)animated @@ -334,6 +349,12 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti actualDirectoryVisibilityRequest = nil; } + if (kRiotDesignValuesDidChangeThemeNotificationObserver) + { + [[NSNotificationCenter defaultCenter] removeObserver:kRiotDesignValuesDidChangeThemeNotificationObserver]; + kRiotDesignValuesDidChangeThemeNotificationObserver = nil; + } + if (appDelegateDidTapStatusBarNotificationObserver) { [[NSNotificationCenter defaultCenter] removeObserver:appDelegateDidTapStatusBarNotificationObserver]; diff --git a/Riot/ViewController/RoomViewController.m b/Riot/ViewController/RoomViewController.m index f8895aac6..c8aed8166 100644 --- a/Riot/ViewController/RoomViewController.m +++ b/Riot/ViewController/RoomViewController.m @@ -174,6 +174,9 @@ // The search bar buttom item back up. UIBarButtonItem *searchBarButtonItem; + + // Observe kRiotDesignValuesDidChangeThemeNotification to handle user interface theme change. + id kRiotDesignValuesDidChangeThemeNotificationObserver; } @end @@ -234,7 +237,6 @@ [super finalizeInit]; // Setup `MXKViewControllerHandling` properties - self.defaultBarTintColor = kRiotNavBarTintColor; self.enableBarTintColorStatusChange = NO; self.rageShakeManager = [RageShakeManager sharedManager]; @@ -402,6 +404,19 @@ { [self refreshRoomInputToolbar]; } + + // Observe user interface theme change. + kRiotDesignValuesDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kRiotDesignValuesDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { + + [self userInterfaceThemeDidChange]; + + }]; + [self userInterfaceThemeDidChange]; +} + +- (void)userInterfaceThemeDidChange +{ + self.defaultBarTintColor = kRiotSecondaryBgColor; } - (void)didReceiveMemoryWarning @@ -1020,6 +1035,11 @@ [self removeTypingNotificationsListener]; + if (kRiotDesignValuesDidChangeThemeNotificationObserver) + { + [[NSNotificationCenter defaultCenter] removeObserver:kRiotDesignValuesDidChangeThemeNotificationObserver]; + kRiotDesignValuesDidChangeThemeNotificationObserver = nil; + } if (kAppDelegateDidTapStatusBarNotificationObserver) { [[NSNotificationCenter defaultCenter] removeObserver:kAppDelegateDidTapStatusBarNotificationObserver]; diff --git a/Riot/ViewController/SegmentedViewController.m b/Riot/ViewController/SegmentedViewController.m index f203a094b..da1181456 100644 --- a/Riot/ViewController/SegmentedViewController.m +++ b/Riot/ViewController/SegmentedViewController.m @@ -42,6 +42,9 @@ // the selected marker view UIView* selectedMarkerView; NSLayoutConstraint *leftMarkerViewConstraint; + + // Observe kRiotDesignValuesDidChangeThemeNotification to handle user interface theme change. + id kRiotDesignValuesDidChangeThemeNotificationObserver; } @end @@ -95,6 +98,12 @@ selectedMarkerView = nil; } + if (kRiotDesignValuesDidChangeThemeNotificationObserver) + { + [[NSNotificationCenter defaultCenter] removeObserver:kRiotDesignValuesDidChangeThemeNotificationObserver]; + kRiotDesignValuesDidChangeThemeNotificationObserver = nil; + } + [super destroy]; } @@ -119,7 +128,6 @@ [super finalizeInit]; // Setup `MXKViewControllerHandling` properties - self.defaultBarTintColor = kRiotNavBarTintColor; self.enableBarTintColorStatusChange = NO; self.rageShakeManager = [RageShakeManager sharedManager]; } @@ -151,6 +159,19 @@ [NSLayoutConstraint activateConstraints:@[self.selectionContainerTopConstraint]]; [self createSegmentedViews]; + + // Observe user interface theme change. + kRiotDesignValuesDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kRiotDesignValuesDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { + + [self userInterfaceThemeDidChange]; + + }]; + [self userInterfaceThemeDidChange]; +} + +- (void)userInterfaceThemeDidChange +{ + self.defaultBarTintColor = kRiotSecondaryBgColor; } - (void)viewWillAppear:(BOOL)animated diff --git a/Riot/ViewController/SettingsViewController.m b/Riot/ViewController/SettingsViewController.m index a1f8da2d5..5b1c7b815 100644 --- a/Riot/ViewController/SettingsViewController.m +++ b/Riot/ViewController/SettingsViewController.m @@ -172,6 +172,9 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)(); // Observe kAppDelegateDidTapStatusBarNotification to handle tap on clock status bar. id kAppDelegateDidTapStatusBarNotificationObserver; + // Observe kRiotDesignValuesDidChangeThemeNotification to handle user interface theme change. + id kRiotDesignValuesDidChangeThemeNotificationObserver; + // Postpone destroy operation when saving, pwd reset or email binding is in progress BOOL isSavingInProgress; BOOL isResetPwdInProgress; @@ -212,7 +215,6 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)(); [super finalizeInit]; // Setup `MXKViewControllerHandling` properties - self.defaultBarTintColor = kRiotNavBarTintColor; self.enableBarTintColorStatusChange = NO; self.rageShakeManager = [RageShakeManager sharedManager]; @@ -278,6 +280,26 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)(); self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(onSave:)]; self.navigationItem.rightBarButtonItem.accessibilityIdentifier=@"SettingsVCNavBarSaveButton"; + + // Observe user interface theme change. + kRiotDesignValuesDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kRiotDesignValuesDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { + + [self userInterfaceThemeDidChange]; + + }]; + [self userInterfaceThemeDidChange]; +} + +- (void)userInterfaceThemeDidChange +{ + self.defaultBarTintColor = kRiotSecondaryBgColor; + + if (self.tableView.dataSource) + { + [self refreshSettings]; + } + + [[UIApplication sharedApplication] setStatusBarStyle:kRiotDesignStatusBarStyle animated:NO]; } - (void)didReceiveMemoryWarning @@ -294,6 +316,12 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)(); [documentInteractionController dismissMenuAnimated:NO]; documentInteractionController = nil; } + + if (kRiotDesignValuesDidChangeThemeNotificationObserver) + { + [[NSNotificationCenter defaultCenter] removeObserver:kRiotDesignValuesDidChangeThemeNotificationObserver]; + kRiotDesignValuesDidChangeThemeNotificationObserver = nil; + } if (isSavingInProgress || isResetPwdInProgress || is3PIDBindingInProgress) { @@ -3495,9 +3523,6 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)(); // The user wants to select this theme [[NSUserDefaults standardUserDefaults] setObject:theme forKey:@"userInterfaceTheme"]; [[NSUserDefaults standardUserDefaults] synchronize]; - - // Select the tapped tag - [uiThemeCell setCheckBoxValue:YES atIndex:index]; } } } diff --git a/Riot/ViewController/UsersDevicesViewController.m b/Riot/ViewController/UsersDevicesViewController.m index 17503088c..14c522556 100644 --- a/Riot/ViewController/UsersDevicesViewController.m +++ b/Riot/ViewController/UsersDevicesViewController.m @@ -25,6 +25,9 @@ MXSession *mxSession; void (^onCompleteBlock)(BOOL doneButtonPressed); + + // Observe kRiotDesignValuesDidChangeThemeNotification to handle user interface theme change. + id kRiotDesignValuesDidChangeThemeNotificationObserver; } @end @@ -43,7 +46,6 @@ [super finalizeInit]; // Setup `MXKViewControllerHandling` properties - self.defaultBarTintColor = kRiotNavBarTintColor; self.enableBarTintColorStatusChange = NO; self.rageShakeManager = [RageShakeManager sharedManager]; } @@ -67,6 +69,30 @@ // Hide line separators of empty cells self.tableView.tableFooterView = [[UIView alloc] init]; + + // Observe user interface theme change. + kRiotDesignValuesDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kRiotDesignValuesDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { + + [self userInterfaceThemeDidChange]; + + }]; + [self userInterfaceThemeDidChange]; +} + +- (void)userInterfaceThemeDidChange +{ + self.defaultBarTintColor = kRiotSecondaryBgColor; +} + +- (void)destroy +{ + [super destroy]; + + if (kRiotDesignValuesDidChangeThemeNotificationObserver) + { + [[NSNotificationCenter defaultCenter] removeObserver:kRiotDesignValuesDidChangeThemeNotificationObserver]; + kRiotDesignValuesDidChangeThemeNotificationObserver = nil; + } } - (void)viewWillAppear:(BOOL)animated diff --git a/Riot/Views/TableViewCell/TableViewCellWithCollectionView.m b/Riot/Views/TableViewCell/TableViewCellWithCollectionView.m index 541442ab0..0656bb875 100644 --- a/Riot/Views/TableViewCell/TableViewCellWithCollectionView.m +++ b/Riot/Views/TableViewCell/TableViewCellWithCollectionView.m @@ -15,6 +15,7 @@ */ #import "TableViewCellWithCollectionView.h" +#import "RiotDesignValues.h" @implementation TableViewCellWithCollectionView @@ -23,6 +24,8 @@ [super awakeFromNib]; self.editionViewHeightConstraint.constant = 0; + + self.editionView.backgroundColor = kRiotSecondaryBgColor; } - (void)prepareForReuse