From 750b935122c55e67442ef2eb1fe7670541ebd774 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 11 Jul 2018 17:33:00 -0400 Subject: [PATCH 1/3] Tweak appearance. --- .../AdvancedSettingsTableViewController.m | 17 ++++++++++++++ .../translations/en.lproj/Localizable.strings | 6 +++++ SignalMessaging/utils/OWSPreferences.h | 3 ++- SignalMessaging/utils/OWSPreferences.m | 23 +++++++++++++++---- 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/Signal/src/ViewControllers/AppSettings/AdvancedSettingsTableViewController.m b/Signal/src/ViewControllers/AppSettings/AdvancedSettingsTableViewController.m index 1b6ad314b..d6482e6f1 100644 --- a/Signal/src/ViewControllers/AppSettings/AdvancedSettingsTableViewController.m +++ b/Signal/src/ViewControllers/AppSettings/AdvancedSettingsTableViewController.m @@ -195,6 +195,16 @@ NS_ASSUME_NONNULL_BEGIN } [contents addSection:censorshipSection]; +#ifdef DEBUG + OWSTableSection *themeSection = [OWSTableSection new]; + themeSection.headerTitle = NSLocalizedString(@"THEME_SECTION", nil); + [themeSection addItem:[OWSTableItem switchItemWithText:NSLocalizedString(@"SETTINGS_ADVANCED_THEME", @"") + isOn:[Environment.preferences isThemeEnabled] + target:weakSelf + selector:@selector(didToggleThemeSwitch:)]]; + [contents addSection:themeSection]; +#endif + self.contents = contents; } @@ -274,6 +284,13 @@ NS_ASSUME_NONNULL_BEGIN [self updateTableContents]; } +- (void)didToggleThemeSwitch:(UISwitch *)sender +{ + [Environment.preferences setIsThemeEnabled:sender.isOn]; + + // TODO: Notify and refresh. +} + @end NS_ASSUME_NONNULL_END diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index d852ebce1..ea18bfff8 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -1886,6 +1886,9 @@ /* No comment provided by engineer. */ "SETTINGS_ADVANCED_SUBMIT_DEBUGLOG" = "Submit Debug Log"; +/* No comment provided by engineer. */ +"SETTINGS_ADVANCED_THEME" = "Theme"; + /* No comment provided by engineer. */ "SETTINGS_ADVANCED_TITLE" = "Advanced"; @@ -2132,6 +2135,9 @@ /* Label for button to verify a user's safety number. */ "SYSTEM_MESSAGE_ACTION_VERIFY_SAFETY_NUMBER" = "Verify Safety Number"; +/* No comment provided by engineer. */ +"THEME_SECTION" = "THEME_SECTION"; + /* {{number of days}} embedded in strings, e.g. 'Alice updated disappearing messages expiration to {{5 days}}'. See other *_TIME_AMOUNT strings */ "TIME_AMOUNT_DAYS" = "%@ days"; diff --git a/SignalMessaging/utils/OWSPreferences.h b/SignalMessaging/utils/OWSPreferences.h index fca6588f2..fcd9020da 100644 --- a/SignalMessaging/utils/OWSPreferences.h +++ b/SignalMessaging/utils/OWSPreferences.h @@ -61,7 +61,8 @@ extern NSString *const OWSPreferencesCallLoggingDidChangeNotification; - (BOOL)hasGeneratedThumbnails; - (void)setHasGeneratedThumbnails:(BOOL)value; -#pragma mark - Calling +- (BOOL)isThemeEnabled; +- (void)setIsThemeEnabled:(BOOL)flag; #pragma mark Callkit diff --git a/SignalMessaging/utils/OWSPreferences.m b/SignalMessaging/utils/OWSPreferences.m index b9ef59659..239d76647 100644 --- a/SignalMessaging/utils/OWSPreferences.m +++ b/SignalMessaging/utils/OWSPreferences.m @@ -31,6 +31,7 @@ NSString *const OWSPreferencesKeyHasGeneratedThumbnails = @"OWSPreferencesKeyHas NSString *const OWSPreferencesKeyIOSUpgradeNagDate = @"iOSUpgradeNagDate"; NSString *const OWSPreferencesKey_IsReadyForAppExtensions = @"isReadyForAppExtensions_5"; NSString *const OWSPreferencesKeySystemCallLogEnabled = @"OWSPreferencesKeySystemCallLogEnabled"; +NSString *const OWSPreferencesKeyEnableTheme = @"OWSPreferencesKeyEnableTheme"; @implementation OWSPreferences @@ -58,7 +59,7 @@ NSString *const OWSPreferencesKeySystemCallLogEnabled = @"OWSPreferencesKeySyste OWSAssert(key != nil); __block id result; - [OWSPrimaryStorage.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *_Nonnull transaction) { + [OWSPrimaryStorage.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { result = [self tryGetValueForKey:key transaction:transaction]; }]; return result; @@ -72,10 +73,9 @@ NSString *const OWSPreferencesKeySystemCallLogEnabled = @"OWSPreferencesKeySyste - (void)setValueForKey:(NSString *)key toValue:(nullable id)value { - [OWSPrimaryStorage.dbReadWriteConnection - readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) { - [self setValueForKey:key toValue:value transaction:transaction]; - }]; + [OWSPrimaryStorage.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { + [self setValueForKey:key toValue:value transaction:transaction]; + }]; } - (void)setValueForKey:(NSString *)key @@ -414,6 +414,19 @@ NSString *const OWSPreferencesKeySystemCallLogEnabled = @"OWSPreferencesKeySyste } } +- (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 From 0c420ed28a6626e604968e10fd713d86bebb2a82 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 12 Jul 2018 09:26:48 -0400 Subject: [PATCH 2/3] Tweak appearance. --- .../AdvancedSettingsTableViewController.m | 6 ++--- SignalMessaging/categories/UIColor+OWS.h | 11 ++++++++ SignalMessaging/categories/UIColor+OWS.m | 27 ++++++++++++++++++- SignalMessaging/utils/OWSPreferences.h | 3 --- SignalMessaging/utils/OWSPreferences.m | 14 ---------- 5 files changed, 40 insertions(+), 21 deletions(-) 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 From 83545e72a1336aaf886ea4b31833dff5a1501d97 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 12 Jul 2018 09:28:32 -0400 Subject: [PATCH 3/3] Tweak appearance. --- Signal/translations/en.lproj/Localizable.strings | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index ea18bfff8..376104bab 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -2136,7 +2136,7 @@ "SYSTEM_MESSAGE_ACTION_VERIFY_SAFETY_NUMBER" = "Verify Safety Number"; /* No comment provided by engineer. */ -"THEME_SECTION" = "THEME_SECTION"; +"THEME_SECTION" = "Theme"; /* {{number of days}} embedded in strings, e.g. 'Alice updated disappearing messages expiration to {{5 days}}'. See other *_TIME_AMOUNT strings */ "TIME_AMOUNT_DAYS" = "%@ days";