From b91e8daba21c2058aea8343c7bd99286112a15f6 Mon Sep 17 00:00:00 2001 From: Philipp Born Date: Wed, 9 Nov 2022 11:01:44 +0100 Subject: [PATCH] add auto black theme option Signed-off-by: Philipp Born --- Riot/Assets/en.lproj/Vector.strings | 1 + Riot/Generated/Strings.swift | 4 ++++ Riot/Managers/Theme/ThemeService.m | 14 ++++++++++++++ Riot/Modules/Settings/SettingsViewController.m | 15 ++++++++++++++- changelog.d/5966.feature | 1 + 5 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 changelog.d/5966.feature diff --git a/Riot/Assets/en.lproj/Vector.strings b/Riot/Assets/en.lproj/Vector.strings index a168812bd4..e48b07dc33 100644 --- a/Riot/Assets/en.lproj/Vector.strings +++ b/Riot/Assets/en.lproj/Vector.strings @@ -767,6 +767,7 @@ Tap the + to start adding people."; "settings_ui_language" = "Language"; "settings_ui_theme" = "Theme"; "settings_ui_theme_auto" = "Auto"; +"settings_ui_theme_autoblack" = "Auto (Black)"; "settings_ui_theme_light" = "Light"; "settings_ui_theme_dark" = "Dark"; "settings_ui_theme_black" = "Black"; diff --git a/Riot/Generated/Strings.swift b/Riot/Generated/Strings.swift index 1ff68cf26f..d4d695ccf8 100644 --- a/Riot/Generated/Strings.swift +++ b/Riot/Generated/Strings.swift @@ -7795,6 +7795,10 @@ public class VectorL10n: NSObject { public static var settingsUiThemeAuto: String { return VectorL10n.tr("Vector", "settings_ui_theme_auto") } + /// Auto (Black) + public static var settingsUiThemeAutoBlack: String { + return VectorL10n.tr("Vector", "settings_ui_theme_autoblack") + } /// Black public static var settingsUiThemeBlack: String { return VectorL10n.tr("Vector", "settings_ui_theme_black") diff --git a/Riot/Managers/Theme/ThemeService.m b/Riot/Managers/Theme/ThemeService.m index 9d544ddce7..0602a2d2eb 100644 --- a/Riot/Managers/Theme/ThemeService.m +++ b/Riot/Managers/Theme/ThemeService.m @@ -74,6 +74,20 @@ - (void)setTheme:(id _Nonnull)theme } } + if ([themeId isEqualToString:@"autoblack"]) + { + if (@available(iOS 13, *)) + { + // Translate "auto" into a theme with UITraitCollection + themeId = ([UITraitCollection currentTraitCollection].userInterfaceStyle == UIUserInterfaceStyleDark) ? @"black" : @"light"; + } + else + { + // Translate "auto" into a theme + themeId = UIAccessibilityIsInvertColorsEnabled() ? @"black" : @"light"; + } + } + if ([themeId isEqualToString:@"dark"]) { theme = [DarkTheme new]; diff --git a/Riot/Modules/Settings/SettingsViewController.m b/Riot/Modules/Settings/SettingsViewController.m index 54bb95d34e..f5d0dfa55c 100644 --- a/Riot/Modules/Settings/SettingsViewController.m +++ b/Riot/Modules/Settings/SettingsViewController.m @@ -3887,7 +3887,7 @@ - (void)showThemePicker { __weak typeof(self) weakSelf = self; - __block UIAlertAction *autoAction, *lightAction, *darkAction, *blackAction; + __block UIAlertAction *autoAction, *autoBlackAction, *lightAction, *darkAction, *blackAction; NSString *themePickerMessage; void (^actionBlock)(UIAlertAction *action) = ^(UIAlertAction * action) { @@ -3913,6 +3913,10 @@ - (void)showThemePicker { newTheme = @"black"; } + else if (action == autoBlackAction) + { + newTheme = @"autoblack"; + } NSString *theme = RiotSettings.shared.userInterfaceTheme; if (newTheme && ![newTheme isEqualToString:theme]) @@ -3938,6 +3942,11 @@ - (void)showThemePicker style:UIAlertActionStyleDefault handler:actionBlock]; + autoBlackAction = [UIAlertAction actionWithTitle:[VectorL10n settingsUiThemeAutoBlack] + style:UIAlertActionStyleDefault + handler:actionBlock]; + + // Explain what is "auto" if (@available(iOS 13, *)) { @@ -3970,6 +3979,10 @@ - (void)showThemePicker { [themePicker addAction:autoAction]; } + if (autoBlackAction) + { + [themePicker addAction:autoBlackAction]; + } [themePicker addAction:lightAction]; [themePicker addAction:darkAction]; [themePicker addAction:blackAction]; diff --git a/changelog.d/5966.feature b/changelog.d/5966.feature new file mode 100644 index 0000000000..72a75d5b3c --- /dev/null +++ b/changelog.d/5966.feature @@ -0,0 +1 @@ +ThemeService: add a 'Auto (Black)' theme option (@tamcore)