diff --git a/Signal/src/ViewControllers/ColorPickerViewController.swift b/Signal/src/ViewControllers/ColorPickerViewController.swift index 089e9988a..6f06784a0 100644 --- a/Signal/src/ViewControllers/ColorPickerViewController.swift +++ b/Signal/src/ViewControllers/ColorPickerViewController.swift @@ -110,9 +110,9 @@ class ColorPickerViewController: UIViewController, UIPickerViewDelegate, UIPicke owsFailDebug("color was unexpectedly nil") return ColorView(color: .white) } - guard let colors = UIColor.ows_conversationColors(colorName: colorName) else { + guard let colors = UIColor.ows_conversationColor(colorName: colorName) else { owsFailDebug("unknown color name") - return ColorView(color: UIColor.ows_defaultConversationColors().themeColor) + return ColorView(color: UIColor.ows_defaultConversationColor().themeColor) } return ColorView(color: colors.themeColor) } diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m b/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m index da8ef94a2..bd045002e 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m +++ b/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m @@ -1528,7 +1528,7 @@ NS_ASSUME_NONNULL_BEGIN [self fakeIncomingPngAction:thread actionLabel:@"Fake Incoming 'Incoming' Png" imageSize:CGSizeMake(200.f, 200.f) - backgroundColor:[conversationStyle conversationColors].defaultColor + backgroundColor:[conversationStyle conversationColor].defaultColor textColor:[UIColor whiteColor] imageLabel:@"W" isAttachmentDownloaded:YES @@ -1536,7 +1536,7 @@ NS_ASSUME_NONNULL_BEGIN [self fakeIncomingPngAction:thread actionLabel:@"Fake Incoming 'Incoming' Png" imageSize:CGSizeMake(200.f, 200.f) - backgroundColor:[conversationStyle conversationColors].shadeColor + backgroundColor:[conversationStyle conversationColor].shadeColor textColor:[UIColor whiteColor] imageLabel:@"W" isAttachmentDownloaded:YES @@ -1544,7 +1544,7 @@ NS_ASSUME_NONNULL_BEGIN [self fakeIncomingPngAction:thread actionLabel:@"Fake Incoming 'Incoming' Png" imageSize:CGSizeMake(200.f, 200.f) - backgroundColor:[conversationStyle conversationColors].defaultColor + backgroundColor:[conversationStyle conversationColor].defaultColor textColor:[UIColor whiteColor] imageLabel:@"W" isAttachmentDownloaded:NO @@ -1552,7 +1552,7 @@ NS_ASSUME_NONNULL_BEGIN [self fakeIncomingPngAction:thread actionLabel:@"Fake Incoming 'Incoming' Png" imageSize:CGSizeMake(200.f, 200.f) - backgroundColor:[conversationStyle conversationColors].shadeColor + backgroundColor:[conversationStyle conversationColor].shadeColor textColor:[UIColor whiteColor] imageLabel:@"W" isAttachmentDownloaded:NO diff --git a/Signal/src/ViewControllers/ThreadSettings/OWSConversationSettingsViewController.m b/Signal/src/ViewControllers/ThreadSettings/OWSConversationSettingsViewController.m index ca66b3bf7..ff43e3e18 100644 --- a/Signal/src/ViewControllers/ThreadSettings/OWSConversationSettingsViewController.m +++ b/Signal/src/ViewControllers/ThreadSettings/OWSConversationSettingsViewController.m @@ -289,7 +289,7 @@ const CGFloat kIconViewLength = 24; itemWithCustomCellBlock:^{ NSString *colorName = self.thread.conversationColorName; UIColor *currentColor = - [UIColor ows_conversationColorsForColorName:colorName].themeColor; + [UIColor ows_conversationColorForColorName:colorName].themeColor; NSString *title = NSLocalizedString(@"CONVERSATION_SETTINGS_CONVERSATION_COLOR", @"Label for table cell which leads to picking a new conversation color"); return [weakSelf disclosureCellWithName:title iconColor:currentColor]; diff --git a/SignalMessaging/categories/Theme.h b/SignalMessaging/categories/Theme.h index e1482cf35..5a38d48c9 100644 --- a/SignalMessaging/categories/Theme.h +++ b/SignalMessaging/categories/Theme.h @@ -57,12 +57,4 @@ extern NSString *const ThemeDidChangeNotification; @end -#pragma mark - - -@interface OWSConversationColors (Theme) - -@property (nonatomic, readonly) UIColor *themeColor; - -@end - NS_ASSUME_NONNULL_END diff --git a/SignalMessaging/categories/Theme.m b/SignalMessaging/categories/Theme.m index 1a5b29fd6..453495cf6 100644 --- a/SignalMessaging/categories/Theme.m +++ b/SignalMessaging/categories/Theme.m @@ -162,15 +162,4 @@ NSString *const ThemeKeyThemeEnabled = @"ThemeKeyThemeEnabled"; @end -#pragma mark - - -@implementation OWSConversationColors (Theme) - -- (UIColor *)themeColor -{ - return Theme.isDarkThemeEnabled ? self.shadeColor : self.defaultColor; -} - -@end - NS_ASSUME_NONNULL_END diff --git a/SignalMessaging/categories/UIColor+OWS.h b/SignalMessaging/categories/UIColor+OWS.h index f5e6910f9..2ab582027 100644 --- a/SignalMessaging/categories/UIColor+OWS.h +++ b/SignalMessaging/categories/UIColor+OWS.h @@ -6,15 +6,17 @@ NS_ASSUME_NONNULL_BEGIN -@interface OWSConversationColors : NSObject +@interface OWSConversationColor : NSObject @property (nonatomic, readonly) UIColor *defaultColor; @property (nonatomic, readonly) UIColor *shadeColor; @property (nonatomic, readonly) UIColor *tintColor; -+ (OWSConversationColors *)conversationColorsWithDefaultColor:(UIColor *)defaultColor - shadeColor:(UIColor *)shadeColor - tintColor:(UIColor *)tintColor; +@property (nonatomic, readonly) UIColor *themeColor; + ++ (OWSConversationColor *)conversationColorWithDefaultColor:(UIColor *)defaultColor + shadeColor:(UIColor *)shadeColor + tintColor:(UIColor *)tintColor; @end @@ -109,18 +111,18 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - Conversation Colors -+ (nullable OWSConversationColors *)ows_conversationColorsForColorName:(NSString *)colorName - NS_SWIFT_NAME(ows_conversationColors(colorName:)); ++ (nullable OWSConversationColor *)ows_conversationColorForColorName:(NSString *)colorName + NS_SWIFT_NAME(ows_conversationColor(colorName:)); // If the conversation color name is valid, return its colors. // Otherwise return the "default" conversation colors. -+ (OWSConversationColors *)ows_conversationColorsOrDefaultForColorName:(NSString *)conversationColorName - NS_SWIFT_NAME(ows_conversationColorsOrDefault(colorName:)); ++ (OWSConversationColor *)ows_conversationColorOrDefaultForColorName:(NSString *)conversationColorName + NS_SWIFT_NAME(ows_conversationColorOrDefault(colorName:)); @property (class, readonly, nonatomic) NSArray *ows_conversationColorNames; + (NSString *)ows_defaultConversationColorName; -+ (OWSConversationColors *)ows_defaultConversationColors; ++ (OWSConversationColor *)ows_defaultConversationColor; // TODO: Remove @property (class, readonly, nonatomic) UIColor *ows_darkSkyBlueColor; diff --git a/SignalMessaging/categories/UIColor+OWS.m b/SignalMessaging/categories/UIColor+OWS.m index 9082aab79..0300f919d 100644 --- a/SignalMessaging/categories/UIColor+OWS.m +++ b/SignalMessaging/categories/UIColor+OWS.m @@ -10,7 +10,7 @@ NS_ASSUME_NONNULL_BEGIN -@interface OWSConversationColors () +@interface OWSConversationColor () @property (nonatomic) UIColor *defaultColor; @property (nonatomic) UIColor *shadeColor; @@ -20,19 +20,24 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - -@implementation OWSConversationColors +@implementation OWSConversationColor -+ (OWSConversationColors *)conversationColorsWithDefaultColor:(UIColor *)defaultColor - shadeColor:(UIColor *)shadeColor - tintColor:(UIColor *)tintColor ++ (OWSConversationColor *)conversationColorWithDefaultColor:(UIColor *)defaultColor + shadeColor:(UIColor *)shadeColor + tintColor:(UIColor *)tintColor { - OWSConversationColors *instance = [OWSConversationColors new]; + OWSConversationColor *instance = [OWSConversationColor new]; instance.defaultColor = defaultColor; instance.shadeColor = shadeColor; instance.tintColor = tintColor; return instance; } +- (UIColor *)themeColor +{ + return Theme.isDarkThemeEnabled ? self.shadeColor : self.defaultColor; +} + @end #pragma mark - @@ -488,7 +493,7 @@ NS_ASSUME_NONNULL_BEGIN return self.ows_conversationColorMap.allKeys; } -+ (nullable OWSConversationColors *)ows_conversationColorsForColorName:(NSString *)conversationColorName ++ (nullable OWSConversationColor *)ows_conversationColorForColorName:(NSString *)conversationColorName { UIColor *_Nullable defaultColor = self.ows_conversationColorMap[conversationColorName]; UIColor *_Nullable shadeColor = self.ows_conversationColorMapShade[conversationColorName]; @@ -499,19 +504,17 @@ NS_ASSUME_NONNULL_BEGIN OWSAssertDebug(defaultColor); OWSAssertDebug(shadeColor); OWSAssertDebug(tintColor); - return [OWSConversationColors conversationColorsWithDefaultColor:defaultColor - shadeColor:shadeColor - tintColor:tintColor]; + return + [OWSConversationColor conversationColorWithDefaultColor:defaultColor shadeColor:shadeColor tintColor:tintColor]; } -+ (OWSConversationColors *)ows_conversationColorsOrDefaultForColorName:(NSString *)conversationColorName ++ (OWSConversationColor *)ows_conversationColorOrDefaultForColorName:(NSString *)conversationColorName { - OWSConversationColors *_Nullable conversationColors = - [self ows_conversationColorsForColorName:conversationColorName]; - if (conversationColors) { - return conversationColors; + OWSConversationColor *_Nullable conversationColor = [self ows_conversationColorForColorName:conversationColorName]; + if (conversationColor) { + return conversationColor; } - return [self ows_defaultConversationColors]; + return [self ows_defaultConversationColor]; } + (NSString *)ows_defaultConversationColorName @@ -521,9 +524,9 @@ NS_ASSUME_NONNULL_BEGIN return conversationColorName; } -+ (OWSConversationColors *)ows_defaultConversationColors ++ (OWSConversationColor *)ows_defaultConversationColor { - return [self ows_conversationColorsForColorName:self.ows_defaultConversationColorName]; + return [self ows_conversationColorForColorName:self.ows_defaultConversationColorName]; } // TODO: Remove diff --git a/SignalMessaging/utils/ConversationStyle.swift b/SignalMessaging/utils/ConversationStyle.swift index 86f7da230..ab780b01b 100644 --- a/SignalMessaging/utils/ConversationStyle.swift +++ b/SignalMessaging/utils/ConversationStyle.swift @@ -64,7 +64,7 @@ public class ConversationStyle: NSObject { public required init(thread: TSThread) { self.thread = thread - self.conversationColors = ConversationStyle.conversationColors(thread: thread) + self.conversationColor = ConversationStyle.conversationColor(thread: thread) super.init() @@ -126,18 +126,18 @@ public class ConversationStyle: NSObject { lastTextLineAxis = CGFloat(round(baseFontOffset + messageTextFont.capHeight * 0.5)) - self.conversationColors = ConversationStyle.conversationColors(thread: thread) + self.conversationColor = ConversationStyle.conversationColor(thread: thread) } // MARK: Colors @objc - public var conversationColors: OWSConversationColors + public var conversationColor: OWSConversationColor - private class func conversationColors(thread: TSThread) -> OWSConversationColors { + private class func conversationColor(thread: TSThread) -> OWSConversationColor { let colorName = thread.conversationColorName - return UIColor.ows_conversationColorsOrDefault(colorName: colorName) + return UIColor.ows_conversationColorOrDefault(colorName: colorName) } @objc @@ -162,7 +162,7 @@ public class ConversationStyle: NSObject { if isIncoming { return ConversationStyle.defaultBubbleColorIncoming } else { - return conversationColors.defaultColor + return conversationColor.defaultColor } } @@ -203,16 +203,16 @@ public class ConversationStyle: NSObject { @objc public func quotedReplyBubbleColor(isIncoming: Bool) -> UIColor { if Theme.isDarkThemeEnabled { - return conversationColors.shadeColor + return conversationColor.shadeColor } else { - return conversationColors.tintColor + return conversationColor.tintColor } } @objc public func quotedReplyStripeColor(isIncoming: Bool) -> UIColor { if isIncoming { - return conversationColors.defaultColor + return conversationColor.defaultColor } else { return Theme.backgroundColor } diff --git a/SignalMessaging/utils/OWSContactAvatarBuilder.m b/SignalMessaging/utils/OWSContactAvatarBuilder.m index 2f559ecd4..16d7fc8c0 100644 --- a/SignalMessaging/utils/OWSContactAvatarBuilder.m +++ b/SignalMessaging/utils/OWSContactAvatarBuilder.m @@ -124,7 +124,7 @@ NS_ASSUME_NONNULL_BEGIN [initials appendString:@"#"]; } - UIColor *color = [UIColor ows_conversationColorsOrDefaultForColorName:self.colorName].themeColor; + UIColor *color = [UIColor ows_conversationColorOrDefaultForColorName:self.colorName].themeColor; OWSAssertDebug(color); UIImage *_Nullable image = diff --git a/SignalMessaging/utils/OWSGroupAvatarBuilder.m b/SignalMessaging/utils/OWSGroupAvatarBuilder.m index 1c8c8b025..1200eb614 100644 --- a/SignalMessaging/utils/OWSGroupAvatarBuilder.m +++ b/SignalMessaging/utils/OWSGroupAvatarBuilder.m @@ -66,8 +66,7 @@ NS_ASSUME_NONNULL_BEGIN return cachedAvatar; } - UIColor *backgroundColor = - [UIColor ows_conversationColorForColorName:conversationColorName isShaded:Theme.isDarkThemeEnabled]; + UIColor *backgroundColor = [UIColor ows_conversationColorForColorName:conversationColorName].themeColor; UIImage *_Nullable image = [OWSGroupAvatarBuilder groupAvatarImageWithBackgroundColor:backgroundColor diameter:diameter]; if (!image) {