Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ThemeService: add a 'Auto (Black)' theme option #7057

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)