diff --git a/Signal/src/ViewControllers/AppSettings/AdvancedSettingsTableViewController.m b/Signal/src/ViewControllers/AppSettings/AdvancedSettingsTableViewController.m index d6482e6f1..73d2902d5 100644 --- a/Signal/src/ViewControllers/AppSettings/AdvancedSettingsTableViewController.m +++ b/Signal/src/ViewControllers/AppSettings/AdvancedSettingsTableViewController.m @@ -195,11 +195,11 @@ NS_ASSUME_NONNULL_BEGIN } [contents addSection:censorshipSection]; -#ifdef DEBUG +#ifdef THEME_ENABLED OWSTableSection *themeSection = [OWSTableSection new]; themeSection.headerTitle = NSLocalizedString(@"THEME_SECTION", nil); [themeSection addItem:[OWSTableItem switchItemWithText:NSLocalizedString(@"SETTINGS_ADVANCED_THEME", @"") - isOn:[Environment.preferences isThemeEnabled] + isOn:[UIColor isThemeEnabled] target:weakSelf selector:@selector(didToggleThemeSwitch:)]]; [contents addSection:themeSection]; @@ -286,7 +286,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)didToggleThemeSwitch:(UISwitch *)sender { - [Environment.preferences setIsThemeEnabled:sender.isOn]; + [UIColor setIsThemeEnabled:sender.isOn]; // TODO: Notify and refresh. } diff --git a/SignalMessaging/categories/UIColor+OWS.h b/SignalMessaging/categories/UIColor+OWS.h index 419b20bc5..c51cf85b7 100644 --- a/SignalMessaging/categories/UIColor+OWS.h +++ b/SignalMessaging/categories/UIColor+OWS.h @@ -6,6 +6,10 @@ NS_ASSUME_NONNULL_BEGIN +#ifdef DEBUG +#define THEME_ENABLED +#endif + @interface UIColor (OWS) #pragma mark - Global App Colors @@ -77,6 +81,13 @@ NS_ASSUME_NONNULL_BEGIN @property (class, readonly, nonatomic) UIColor *ows_grey600Color; @property (class, readonly, nonatomic) UIColor *ows_darkSkyBlueColor; +#pragma mark - Theme + +#ifdef THEME_ENABLED ++ (BOOL)isThemeEnabled; ++ (void)setIsThemeEnabled:(BOOL)value; +#endif + @end NS_ASSUME_NONNULL_END diff --git a/SignalMessaging/categories/UIColor+OWS.m b/SignalMessaging/categories/UIColor+OWS.m index 3c979ad8c..3b6e0e7da 100644 --- a/SignalMessaging/categories/UIColor+OWS.m +++ b/SignalMessaging/categories/UIColor+OWS.m @@ -2,12 +2,17 @@ // Copyright (c) 2018 Open Whisper Systems. All rights reserved. // -#import "UIColor+OWS.h" #import "OWSMath.h" +#import "UIColor+OWS.h" #import +#import +#import NS_ASSUME_NONNULL_BEGIN +NSString *const UIColorCollection = @"UIColorCollection"; +NSString *const UIColorKeyThemeEnabled = @"UIColorKeyThemeEnabled"; + @implementation UIColor (OWS) #pragma mark - Global App Colors @@ -338,6 +343,26 @@ NS_ASSUME_NONNULL_BEGIN return [self.ows_conversationColorMap allKeysForObject:color].firstObject; } +#pragma mark - Theme + ++ (BOOL)isThemeEnabled +{ + OWSAssertIsOnMainThread(); + + return [OWSPrimaryStorage.sharedManager.dbReadConnection boolForKey:UIColorKeyThemeEnabled + inCollection:UIColorCollection + defaultValue:NO]; +} + ++ (void)setIsThemeEnabled:(BOOL)value +{ + OWSAssertIsOnMainThread(); + + [OWSPrimaryStorage.sharedManager.dbReadWriteConnection setBool:value + forKey:UIColorKeyThemeEnabled + inCollection:UIColorCollection]; +} + @end NS_ASSUME_NONNULL_END diff --git a/SignalMessaging/utils/OWSPreferences.h b/SignalMessaging/utils/OWSPreferences.h index fcd9020da..15c653f38 100644 --- a/SignalMessaging/utils/OWSPreferences.h +++ b/SignalMessaging/utils/OWSPreferences.h @@ -61,9 +61,6 @@ extern NSString *const OWSPreferencesCallLoggingDidChangeNotification; - (BOOL)hasGeneratedThumbnails; - (void)setHasGeneratedThumbnails:(BOOL)value; -- (BOOL)isThemeEnabled; -- (void)setIsThemeEnabled:(BOOL)flag; - #pragma mark Callkit - (BOOL)isSystemCallLogEnabled; diff --git a/SignalMessaging/utils/OWSPreferences.m b/SignalMessaging/utils/OWSPreferences.m index 239d76647..9484812df 100644 --- a/SignalMessaging/utils/OWSPreferences.m +++ b/SignalMessaging/utils/OWSPreferences.m @@ -31,7 +31,6 @@ NSString *const OWSPreferencesKeyHasGeneratedThumbnails = @"OWSPreferencesKeyHas NSString *const OWSPreferencesKeyIOSUpgradeNagDate = @"iOSUpgradeNagDate"; NSString *const OWSPreferencesKey_IsReadyForAppExtensions = @"isReadyForAppExtensions_5"; NSString *const OWSPreferencesKeySystemCallLogEnabled = @"OWSPreferencesKeySystemCallLogEnabled"; -NSString *const OWSPreferencesKeyEnableTheme = @"OWSPreferencesKeyEnableTheme"; @implementation OWSPreferences @@ -414,19 +413,6 @@ NSString *const OWSPreferencesKeyEnableTheme = @"OWSPreferencesKeyEnableTheme"; } } -- (BOOL)isThemeEnabled -{ - NSNumber *preference = [self tryGetValueForKey:OWSPreferencesKeyEnableTheme]; - return preference ? [preference boolValue] : NO; -} - -- (void)setIsThemeEnabled:(BOOL)flag -{ - OWSAssert(CurrentAppContext().isMainApp); - - [self setValueForKey:OWSPreferencesKeyEnableTheme toValue:@(flag)]; -} - #pragma mark - Push Tokens - (void)setPushToken:(NSString *)value