فهرست منبع

Network Login: Fix wrong colors by listening to kVLCThemeDidChangeNotification

Edgar Fouillet 5 سال پیش
والد
کامیت
3fa8a20748

+ 7 - 1
Sources/LocalNetworkConnectivity/VLCNetworkLoginDataSourceProtocol.m

@@ -101,7 +101,8 @@ static NSString *const VLCNetworkLoginDataSourceProtocolCellIdentifier = @"VLCNe
                                                  forState:UIControlStateSelected];
         }
         [self.contentView addSubview:_segmentedControl];
-        self.backgroundColor = PresentationTheme.current.colors.background;
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(themeDidChange) name:kVLCThemeDidChangeNotification object:nil];
+        [self themeDidChange];
     }
     return self;
 }
@@ -112,4 +113,9 @@ static NSString *const VLCNetworkLoginDataSourceProtocolCellIdentifier = @"VLCNe
     self.segmentedControl.frame = CGRectInset(self.contentView.bounds, 20, 5);
 }
 
+- (void)themeDidChange
+{
+    self.backgroundColor = PresentationTheme.current.colors.background;
+}
+
 @end

+ 9 - 3
Sources/LocalNetworkConnectivity/VLCNetworkLoginDataSourceSavedLogins.m

@@ -199,11 +199,17 @@ static NSString *const VLCNetworkLoginSavedLoginCellIdentifier = @"VLCNetworkLog
 {
     self = [super initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
     if (self) {
-        self.textLabel.textColor = PresentationTheme.current.colors.cellTextColor;
-        self.detailTextLabel.textColor = PresentationTheme.current.colors.lightTextColor;
-        self.backgroundColor = PresentationTheme.current.colors.background;
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(themeDidChange) name:kVLCThemeDidChangeNotification object:nil];
+        [self themeDidChange];
     }
     return self;
 }
 
+- (void)themeDidChange
+{
+    self.backgroundColor = PresentationTheme.current.colors.background;
+    self.textLabel.textColor = PresentationTheme.current.colors.cellTextColor;
+    self.detailTextLabel.textColor = PresentationTheme.current.colors.lightTextColor;
+}
+
 @end

+ 7 - 1
Sources/LocalNetworkConnectivity/VLCNetworkLoginViewButtonCell.m

@@ -22,7 +22,8 @@ NSString * const kVLCNetworkLoginViewButtonCellIdentifier = @"VLCNetworkLoginVie
 {
     self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
     if (self) {
-        self.backgroundColor = PresentationTheme.current.colors.background;
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(themeDidChange) name:kVLCThemeDidChangeNotification object:nil];
+        [self themeDidChange];
         self.textLabel.backgroundColor = [UIColor clearColor];
         self.textLabel.textColor = [UIColor whiteColor];
         self.textLabel.textAlignment = NSTextAlignmentCenter;
@@ -59,4 +60,9 @@ NSString * const kVLCNetworkLoginViewButtonCellIdentifier = @"VLCNetworkLoginVie
     return self.textLabel.text;
 }
 
+- (void)themeDidChange
+{
+    self.backgroundColor = PresentationTheme.current.colors.background;
+}
+
 @end

+ 9 - 2
Sources/LocalNetworkConnectivity/VLCNetworkLoginViewController.m

@@ -50,8 +50,8 @@
 
     self.title = NSLocalizedString(@"CONNECT_TO_SERVER", nil);
 
-    self.tableView.backgroundColor = PresentationTheme.current.colors.background;
-    self.tableView.separatorColor = PresentationTheme.current.colors.separatorColor;
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(themeDidChange) name:kVLCThemeDidChangeNotification object:nil];
+    [self themeDidChange];
 
     self.protocolDataSource = [[VLCNetworkLoginDataSourceProtocol alloc] init];
     self.protocolDataSource.delegate = self;
@@ -134,6 +134,13 @@
     self.loginDataSource.loginInformation = loginInformation;
 }
 
+- (void)themeDidChange
+{
+    self.view.backgroundColor = PresentationTheme.current.colors.background;
+    self.tableView.backgroundColor = PresentationTheme.current.colors.background;
+    self.tableView.separatorColor = PresentationTheme.current.colors.background;
+}
+
 #pragma mark - VLCNetworkLoginDataSourceProtocolDelegate
 - (void)protocolDidChange:(VLCNetworkLoginDataSourceProtocol *)protocolSection
 {

+ 1 - 0
Sources/LocalNetworkConnectivity/VLCNetworkLoginViewFieldCell.h

@@ -20,6 +20,7 @@ extern NSString * const kVLCNetworkLoginViewFieldCellIdentifier;
 @interface VLCNetworkLoginViewFieldCell : UITableViewCell
 @property (nonatomic, weak) id<VLCNetworkLoginViewFieldCellDelegate> delegate;
 @property (nonatomic, retain) UITextField *textField;
+@property (nonatomic, retain) UIView *darkView;
 @property (nonatomic, nullable, copy) NSString *placeholderString;
 @end
 

+ 16 - 9
Sources/LocalNetworkConnectivity/VLCNetworkLoginViewFieldCell.m

@@ -23,7 +23,8 @@ NSString * const kVLCNetworkLoginViewFieldCellIdentifier = @"VLCNetworkLoginView
 {
     self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
     if (self) {
-        self.backgroundColor = PresentationTheme.current.colors.background;
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(themeDidChange) name:kVLCThemeDidChangeNotification object:nil];
+        [self themeDidChange];
         [self setupSubviews];
     }
     return self;
@@ -31,10 +32,9 @@ NSString * const kVLCNetworkLoginViewFieldCellIdentifier = @"VLCNetworkLoginView
 
 - (void)setupSubviews
 {
-    UIView *darkView = [[UIView alloc] init];
-    darkView.translatesAutoresizingMaskIntoConstraints = NO;
-    [self addSubview:darkView];
-    darkView.backgroundColor = PresentationTheme.current.colors.background;
+    _darkView = [[UIView alloc] init];
+    _darkView.translatesAutoresizingMaskIntoConstraints = NO;
+    [self addSubview:_darkView];
     self.textField = [[UITextField alloc] initWithFrame:CGRectZero];
     self.textField.translatesAutoresizingMaskIntoConstraints = NO;
     self.textField.delegate = self;
@@ -46,10 +46,10 @@ NSString * const kVLCNetworkLoginViewFieldCellIdentifier = @"VLCNetworkLoginView
         guide = self.safeAreaLayoutGuide;
     }
     [NSLayoutConstraint activateConstraints:@[
-                                              [darkView.leftAnchor constraintEqualToAnchor:self.leftAnchor],
-                                              [darkView.topAnchor constraintEqualToAnchor:self.topAnchor],
-                                              [darkView.rightAnchor constraintEqualToAnchor:self.rightAnchor],
-                                              [darkView.bottomAnchor constraintEqualToAnchor:self.bottomAnchor constant:-1],
+                                              [_darkView.leftAnchor constraintEqualToAnchor:self.leftAnchor],
+                                              [_darkView.topAnchor constraintEqualToAnchor:self.topAnchor],
+                                              [_darkView.rightAnchor constraintEqualToAnchor:self.rightAnchor],
+                                              [_darkView.bottomAnchor constraintEqualToAnchor:self.bottomAnchor constant:-1],
                                               [self.textField.leftAnchor constraintEqualToAnchor:guide.leftAnchor constant:8.0],
                                               [self.textField.topAnchor constraintEqualToAnchor:guide.topAnchor],
                                               [self.textField.rightAnchor constraintEqualToAnchor:guide.rightAnchor constant:8.0],
@@ -74,6 +74,13 @@ NSString * const kVLCNetworkLoginViewFieldCellIdentifier = @"VLCNetworkLoginView
     }
 }
 
+- (void)themeDidChange
+{
+    self.backgroundColor = PresentationTheme.current.colors.background;
+    self.textField.textColor = PresentationTheme.current.colors.cellTextColor;
+    _darkView.backgroundColor = PresentationTheme.current.colors.background;
+}
+
 #pragma mark - Properties
 
 - (void)setPlaceholderString:(NSString *)placeholderString