#1268 (appearance changes)

- Manually changing the theme now turns off the preference to follow the system appearance.
- Turning on following the system appearance immediately updates the theme appropriately.
This commit is contained in:
David Sinclair 2019-12-21 13:34:29 -08:00
parent 4f365dd456
commit 7326aeadba
3 changed files with 20 additions and 3 deletions

View file

@ -819,6 +819,7 @@
BOOL theme_follow_system = [[NSUserDefaults standardUserDefaults] boolForKey:@"theme_follow_system"];
if (theme_follow_system) {
[hiddenSet addObjectsFromArray:@[@"theme_auto_toggle", @"theme_auto_brightness", @"theme_style", @"theme_gesture"]];
[[ThemeManager themeManager] updateForSystemAppearance];
}
}
BOOL theme_auto_toggle = [[NSUserDefaults standardUserDefaults] boolForKey:@"theme_auto_toggle"];

View file

@ -50,6 +50,7 @@ extern NSString * const ThemeStyleDark;
- (void)updatePreferencesTheme;
- (BOOL)autoChangeTheme;
- (UIGestureRecognizer *)addThemeGestureRecognizerToView:(UIView *)view;
- (void)updateForSystemAppearance;
- (void)systemAppearanceDidChange:(BOOL)isDark;
@end

View file

@ -53,6 +53,15 @@ NSString * const ThemeStyleDark = @"dark";
}
- (void)setTheme:(NSString *)theme {
// Automatically turn off following the system appearance when manually changing the theme.
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"theme_follow_system"];
[self reallySetTheme:theme];
NSLog(@"Manually changed to theme: %@", self.themeDisplayName); // log
}
- (void)reallySetTheme:(NSString *)theme {
if ([self isValidTheme:theme]) {
[[NSUserDefaults standardUserDefaults] setObject:theme forKey:@"theme_style"];
[self updateTheme];
@ -385,6 +394,14 @@ NSString * const ThemeStyleDark = @"dark";
AudioServicesPlaySystemSound(1105);
}
- (void)updateForSystemAppearance {
if (@available(iOS 12.0, *)) {
BOOL isDark = self.appDelegate.window.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark;
[self systemAppearanceDidChange:isDark];
}
}
- (void)systemAppearanceDidChange:(BOOL)isDark {
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *wantTheme = nil;
@ -400,11 +417,9 @@ NSString * const ThemeStyleDark = @"dark";
}
if (self.theme != wantTheme) {
self.theme = wantTheme;
[self reallySetTheme:wantTheme];
NSLog(@"System changed to theme: %@", self.themeDisplayName); // log
[self updateTheme];
}
}