Skip to content

Commit

Permalink
add auto black theme option
Browse files Browse the repository at this point in the history
Signed-off-by: Philipp Born <[email protected]>
  • Loading branch information
tamcore committed Nov 9, 2022
1 parent 2184f1f commit b91e8da
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions Riot/Assets/en.lproj/Vector.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
4 changes: 4 additions & 0 deletions Riot/Generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
14 changes: 14 additions & 0 deletions Riot/Managers/Theme/ThemeService.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,20 @@ - (void)setTheme:(id<Theme> _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];
Expand Down
15 changes: 14 additions & 1 deletion Riot/Modules/Settings/SettingsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -3913,6 +3913,10 @@ - (void)showThemePicker
{
newTheme = @"black";
}
else if (action == autoBlackAction)
{
newTheme = @"autoblack";
}

NSString *theme = RiotSettings.shared.userInterfaceTheme;
if (newTheme && ![newTheme isEqualToString:theme])
Expand All @@ -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, *))
{
Expand Down Expand Up @@ -3970,6 +3979,10 @@ - (void)showThemePicker
{
[themePicker addAction:autoAction];
}
if (autoBlackAction)
{
[themePicker addAction:autoBlackAction];
}
[themePicker addAction:lightAction];
[themePicker addAction:darkAction];
[themePicker addAction:blackAction];
Expand Down
1 change: 1 addition & 0 deletions changelog.d/5966.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ThemeService: add a 'Auto (Black)' theme option (@tamcore)

0 comments on commit b91e8da

Please sign in to comment.