Rename OWSConversationColor.

This commit is contained in:
Matthew Chen 2018-09-27 09:15:15 -04:00
parent 3adc03fa2c
commit b20cd57383
10 changed files with 50 additions and 65 deletions

View File

@ -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)
}

View File

@ -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

View File

@ -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];

View File

@ -57,12 +57,4 @@ extern NSString *const ThemeDidChangeNotification;
@end
#pragma mark -
@interface OWSConversationColors (Theme)
@property (nonatomic, readonly) UIColor *themeColor;
@end
NS_ASSUME_NONNULL_END

View File

@ -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

View File

@ -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<NSString *> *ows_conversationColorNames;
+ (NSString *)ows_defaultConversationColorName;
+ (OWSConversationColors *)ows_defaultConversationColors;
+ (OWSConversationColor *)ows_defaultConversationColor;
// TODO: Remove
@property (class, readonly, nonatomic) UIColor *ows_darkSkyBlueColor;

View File

@ -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

View File

@ -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
}

View File

@ -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 =

View File

@ -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) {