Rework conversation message bubble colors; add "conversation colors" class.

pull/1/head
Matthew Chen 7 years ago
parent 26a2d568de
commit b3ad6e27dc

@ -8,6 +8,7 @@
#import "UIColor+OWS.h"
#import "UIFont+OWS.h"
#import "UIView+OWS.h"
#import <SignalMessaging/Theme.h>
#import <SignalServiceKit/OWSSignalService.h>
NS_ASSUME_NONNULL_BEGIN

@ -82,8 +82,8 @@ class ColorPickerViewController: UIViewController, UIPickerViewDelegate, UIPicke
override func viewDidLoad() {
super.viewDidLoad()
if let colorName = thread.conversationColorName,
let index = colorNames.index(of: colorName) {
let colorName = thread.conversationColorName
if let index = colorNames.index(of: colorName) {
pickerView.selectRow(index, inComponent: 0, animated: false)
}
}
@ -110,12 +110,11 @@ class ColorPickerViewController: UIViewController, UIPickerViewDelegate, UIPicke
owsFailDebug("color was unexpectedly nil")
return ColorView(color: .white)
}
guard let color = UIColor.ows_conversationColor(colorName: colorName,
mode: Theme.isDarkThemeEnabled ? .shade : .default) else {
guard let colors = UIColor.ows_conversationColors(colorName: colorName) else {
owsFailDebug("unknown color name")
return ColorView(color: .white)
return ColorView(color: UIColor.ows_defaultConversationColors().themeColor)
}
return ColorView(color: color)
return ColorView(color: colors.themeColor)
}
// MARK: Actions

@ -122,7 +122,7 @@ const CGFloat kRemotelySourcedContentRowSpacing = 3;
- (UIColor *)highlightColor
{
BOOL isQuotingSelf = [NSObject isNullableObject:self.quotedMessage.authorId equalTo:TSAccountManager.localNumber];
return (isQuotingSelf ? self.conversationStyle.bubbleColorOutgoingSent
return (isQuotingSelf ? [self.conversationStyle bubbleColorWithIsIncoming:NO]
: [self.conversationStyle quotingSelfHighlightColor]);
}

@ -6,6 +6,7 @@
#import "UIColor+OWS.h"
#import "UIFont+OWS.h"
#import "UIView+OWS.h"
#import <SignalMessaging/Theme.h>
NS_ASSUME_NONNULL_BEGIN

@ -1342,75 +1342,25 @@ NS_ASSUME_NONNULL_BEGIN
hasCaption:YES],
[self fakeOutgoingPngAction:thread
actionLabel:@"Fake Outgoing 'Outgoing Unsent' Png"
actionLabel:@"Fake Outgoing 'Outgoing' Png"
imageSize:CGSizeMake(200.f, 200.f)
backgroundColor:[conversationStyle bubbleColorOutgoingFailed]
backgroundColor:[conversationStyle bubbleColorWithIsIncoming:NO]
textColor:[UIColor whiteColor]
imageLabel:@"W"
messageState:TSOutgoingMessageStateFailed
hasCaption:YES],
[self fakeOutgoingPngAction:thread
actionLabel:@"Fake Outgoing 'Outgoing Unsent' Png"
actionLabel:@"Fake Outgoing 'Outgoing' Png"
imageSize:CGSizeMake(200.f, 200.f)
backgroundColor:[conversationStyle bubbleColorOutgoingFailed]
backgroundColor:[conversationStyle bubbleColorWithIsIncoming:NO]
textColor:[UIColor whiteColor]
imageLabel:@"W"
messageState:TSOutgoingMessageStateSending
hasCaption:YES],
[self fakeOutgoingPngAction:thread
actionLabel:@"Fake Outgoing 'Outgoing Unsent' Png"
actionLabel:@"Fake Outgoing 'Outgoing' Png"
imageSize:CGSizeMake(200.f, 200.f)
backgroundColor:[conversationStyle bubbleColorOutgoingFailed]
textColor:[UIColor whiteColor]
imageLabel:@"W"
messageState:TSOutgoingMessageStateSent
hasCaption:YES],
[self fakeOutgoingPngAction:thread
actionLabel:@"Fake Outgoing 'Outgoing Sending' Png"
imageSize:CGSizeMake(200.f, 200.f)
backgroundColor:[conversationStyle bubbleColorOutgoingSending]
textColor:[UIColor whiteColor]
imageLabel:@"W"
messageState:TSOutgoingMessageStateFailed
hasCaption:YES],
[self fakeOutgoingPngAction:thread
actionLabel:@"Fake Outgoing 'Outgoing Sending' Png"
imageSize:CGSizeMake(200.f, 200.f)
backgroundColor:[conversationStyle bubbleColorOutgoingSending]
textColor:[UIColor whiteColor]
imageLabel:@"W"
messageState:TSOutgoingMessageStateSending
hasCaption:YES],
[self fakeOutgoingPngAction:thread
actionLabel:@"Fake Outgoing 'Outgoing Sending' Png"
imageSize:CGSizeMake(200.f, 200.f)
backgroundColor:[conversationStyle bubbleColorOutgoingSending]
textColor:[UIColor whiteColor]
imageLabel:@"W"
messageState:TSOutgoingMessageStateSent
hasCaption:YES],
[self fakeOutgoingPngAction:thread
actionLabel:@"Fake Outgoing 'Outgoing Sent' Png"
imageSize:CGSizeMake(200.f, 200.f)
backgroundColor:[conversationStyle bubbleColorOutgoingSent]
textColor:[UIColor whiteColor]
imageLabel:@"W"
messageState:TSOutgoingMessageStateFailed
hasCaption:YES],
[self fakeOutgoingPngAction:thread
actionLabel:@"Fake Outgoing 'Outgoing Sent' Png"
imageSize:CGSizeMake(200.f, 200.f)
backgroundColor:[conversationStyle bubbleColorOutgoingSent]
textColor:[UIColor whiteColor]
imageLabel:@"W"
messageState:TSOutgoingMessageStateSending
hasCaption:YES],
[self fakeOutgoingPngAction:thread
actionLabel:@"Fake Outgoing 'Outgoing Sent' Png"
imageSize:CGSizeMake(200.f, 200.f)
backgroundColor:[conversationStyle bubbleColorOutgoingSent]
backgroundColor:[conversationStyle bubbleColorWithIsIncoming:NO]
textColor:[UIColor whiteColor]
imageLabel:@"W"
messageState:TSOutgoingMessageStateSent
@ -1578,7 +1528,15 @@ NS_ASSUME_NONNULL_BEGIN
[self fakeIncomingPngAction:thread
actionLabel:@"Fake Incoming 'Incoming' Png"
imageSize:CGSizeMake(200.f, 200.f)
backgroundColor:[conversationStyle primaryColor]
backgroundColor:[conversationStyle conversationColors].defaultColor
textColor:[UIColor whiteColor]
imageLabel:@"W"
isAttachmentDownloaded:YES
hasCaption:YES],
[self fakeIncomingPngAction:thread
actionLabel:@"Fake Incoming 'Incoming' Png"
imageSize:CGSizeMake(200.f, 200.f)
backgroundColor:[conversationStyle conversationColors].shadeColor
textColor:[UIColor whiteColor]
imageLabel:@"W"
isAttachmentDownloaded:YES
@ -1586,7 +1544,15 @@ NS_ASSUME_NONNULL_BEGIN
[self fakeIncomingPngAction:thread
actionLabel:@"Fake Incoming 'Incoming' Png"
imageSize:CGSizeMake(200.f, 200.f)
backgroundColor:[conversationStyle primaryColor]
backgroundColor:[conversationStyle conversationColors].defaultColor
textColor:[UIColor whiteColor]
imageLabel:@"W"
isAttachmentDownloaded:NO
hasCaption:YES],
[self fakeIncomingPngAction:thread
actionLabel:@"Fake Incoming 'Incoming' Png"
imageSize:CGSizeMake(200.f, 200.f)
backgroundColor:[conversationStyle conversationColors].shadeColor
textColor:[UIColor whiteColor]
imageLabel:@"W"
isAttachmentDownloaded:NO

@ -288,11 +288,8 @@ const CGFloat kIconViewLength = 24;
[mainSection addItem:[OWSTableItem
itemWithCustomCellBlock:^{
NSString *colorName = self.thread.conversationColorName;
UIColor *currentColor = [UIColor
ows_conversationColorForColorName:colorName
mode:(Theme.isDarkThemeEnabled
? ConversationColorMode_Shade
: ConversationColorMode_Default)];
UIColor *currentColor =
[UIColor ows_conversationColorsForColorName: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];

@ -5,6 +5,7 @@
#import "CountryCodeViewController.h"
#import "OWSSearchBar.h"
#import "PhoneNumberUtil.h"
#import "Theme.h"
#import "UIColor+OWS.h"
#import "UIFont+OWS.h"
#import "UIView+OWS.h"

@ -4,6 +4,7 @@
#import "OWSTableViewController.h"
#import "OWSNavigationController.h"
#import "Theme.h"
#import "UIColor+OWS.h"
#import "UIFont+OWS.h"
#import "UIView+OWS.h"

@ -2,6 +2,7 @@
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "UIColor+OWS.h"
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@ -56,4 +57,12 @@ extern NSString *const ThemeDidChangeNotification;
@end
#pragma mark -
@interface OWSConversationColors (Theme)
@property (nonatomic, readonly) UIColor *themeColor;
@end
NS_ASSUME_NONNULL_END

@ -162,4 +162,15 @@ NSString *const ThemeKeyThemeEnabled = @"ThemeKeyThemeEnabled";
@end
#pragma mark -
@implementation OWSConversationColors (Theme)
- (UIColor *)themeColor
{
return Theme.isDarkThemeEnabled ? self.shadeColor : self.defaultColor;
}
@end
NS_ASSUME_NONNULL_END

@ -2,16 +2,23 @@
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "Theme.h"
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSUInteger, ConversationColorMode) {
ConversationColorMode_Default,
ConversationColorMode_Shade,
ConversationColorMode_Tint,
};
@interface OWSConversationColors : 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;
@end
#pragma mark -
@interface UIColor (OWS)
@ -102,15 +109,18 @@ typedef NS_ENUM(NSUInteger, ConversationColorMode) {
#pragma mark - Conversation Colors
+ (nullable UIColor *)ows_conversationColorForColorName:(NSString *)colorName
mode:(ConversationColorMode)mode
NS_SWIFT_NAME(ows_conversationColor(colorName:mode:));
+ (nullable OWSConversationColors *)ows_conversationColorsForColorName:(NSString *)colorName
NS_SWIFT_NAME(ows_conversationColors(colorName:));
@property (class, readonly, nonatomic) NSArray<NSString *> *ows_conversationColorNames;
// 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:));
+ (nullable UIColor *)ows_conversationTintColorForColorName:(NSString *)colorName;
@property (class, readonly, nonatomic) NSArray<NSString *> *ows_conversationColorNames;
+ (NSString *)ows_defaultConversationColorName;
+ (OWSConversationColors *)ows_defaultConversationColors;
// TODO: Remove
@property (class, readonly, nonatomic) UIColor *ows_darkSkyBlueColor;

@ -2,12 +2,41 @@
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "UIColor+OWS.h"
#import "OWSMath.h"
#import "Theme.h"
#import "UIColor+OWS.h"
#import <SignalServiceKit/Cryptography.h>
NS_ASSUME_NONNULL_BEGIN
@interface OWSConversationColors ()
@property (nonatomic) UIColor *defaultColor;
@property (nonatomic) UIColor *shadeColor;
@property (nonatomic) UIColor *tintColor;
@end
#pragma mark -
@implementation OWSConversationColors
+ (OWSConversationColors *)conversationColorsWithDefaultColor:(UIColor *)defaultColor
shadeColor:(UIColor *)shadeColor
tintColor:(UIColor *)tintColor
{
OWSConversationColors *instance = [OWSConversationColors new];
instance.defaultColor = defaultColor;
instance.shadeColor = shadeColor;
instance.tintColor = tintColor;
return instance;
}
@end
#pragma mark -
@implementation UIColor (OWS)
#pragma mark -
@ -459,30 +488,42 @@ NS_ASSUME_NONNULL_BEGIN
return self.ows_conversationColorMap.allKeys;
}
+ (nullable UIColor *)ows_conversationColorForColorName:(NSString *)colorName mode:(ConversationColorMode)mode
+ (nullable OWSConversationColors *)ows_conversationColorsForColorName:(NSString *)conversationColorName
{
OWSAssertDebug(colorName.length > 0);
switch (mode) {
case ConversationColorMode_Default:
return self.ows_conversationColorMap[colorName];
case ConversationColorMode_Shade:
return self.ows_conversationColorMapShade[colorName];
case ConversationColorMode_Tint:
return self.ows_conversationColorMapTint[colorName];
UIColor *_Nullable defaultColor = self.ows_conversationColorMap[conversationColorName];
UIColor *_Nullable shadeColor = self.ows_conversationColorMapShade[conversationColorName];
UIColor *_Nullable tintColor = self.ows_conversationColorMapTint[conversationColorName];
if (!defaultColor || !shadeColor || !tintColor) {
return nil;
}
OWSAssertDebug(defaultColor);
OWSAssertDebug(shadeColor);
OWSAssertDebug(tintColor);
return [OWSConversationColors conversationColorsWithDefaultColor:defaultColor
shadeColor:shadeColor
tintColor:tintColor];
}
+ (nullable UIColor *)ows_conversationTintColorForColorName:(NSString *)colorName
+ (OWSConversationColors *)ows_conversationColorsOrDefaultForColorName:(NSString *)conversationColorName
{
OWSAssertDebug(colorName.length > 0);
return self.ows_conversationColorMapTint[colorName];
OWSConversationColors *_Nullable conversationColors =
[self ows_conversationColorsForColorName:conversationColorName];
if (conversationColors) {
return conversationColors;
}
return [self ows_defaultConversationColors];
}
+ (NSString *)ows_defaultConversationColorName
{
return @"teal";
NSString *conversationColorName = @"teal";
OWSAssert([self.ows_conversationColorNames containsObject:conversationColorName]);
return conversationColorName;
}
+ (OWSConversationColors *)ows_defaultConversationColors
{
return [self ows_conversationColorsForColorName:self.ows_defaultConversationColorName];
}
// TODO: Remove

@ -2,9 +2,10 @@
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "UIViewController+OWS.h"
#import "Theme.h"
#import "UIColor+OWS.h"
#import "UIView+OWS.h"
#import "UIViewController+OWS.h"
#import <SignalServiceKit/AppContext.h>
#import <SignalServiceKit/iOSVersions.h>

@ -64,7 +64,7 @@ public class ConversationStyle: NSObject {
public required init(thread: TSThread) {
self.thread = thread
self.primaryColor = ConversationStyle.primaryColor(thread: thread)
self.conversationColors = ConversationStyle.conversationColors(thread: thread)
super.init()
@ -126,22 +126,18 @@ public class ConversationStyle: NSObject {
lastTextLineAxis = CGFloat(round(baseFontOffset + messageTextFont.capHeight * 0.5))
self.primaryColor = ConversationStyle.primaryColor(thread: thread)
self.conversationColors = ConversationStyle.conversationColors(thread: thread)
}
// MARK: Colors
private class func primaryColor(thread: TSThread) -> UIColor {
guard let colorName = thread.conversationColorName else {
return self.defaultBubbleColorIncoming
}
@objc
public var conversationColors: OWSConversationColors
guard let color = UIColor.ows_conversationColor(colorName: colorName,
mode: Theme.isDarkThemeEnabled ? .shade : .default) else {
return self.defaultBubbleColorIncoming
}
private class func conversationColors(thread: TSThread) -> OWSConversationColors {
let colorName = thread.conversationColorName
return color
return UIColor.ows_conversationColorsOrDefault(colorName: colorName)
}
@objc
@ -149,37 +145,15 @@ public class ConversationStyle: NSObject {
return Theme.isDarkThemeEnabled ? UIColor.ows_gray75 : UIColor.ows_messageBubbleLightGray
}
@objc
public let bubbleColorOutgoingFailed = UIColor.ows_darkSkyBlue
@objc
public let bubbleColorOutgoingSending = UIColor.ows_darkSkyBlue
@objc
public let bubbleColorOutgoingSent = UIColor.ows_darkSkyBlue
@objc
public let dateBreakTextColor = UIColor.ows_gray60
@objc
public var primaryColor: UIColor
@objc
public func bubbleColor(message: TSMessage) -> UIColor {
if message is TSIncomingMessage {
return ConversationStyle.defaultBubbleColorIncoming
} else if let outgoingMessage = message as? TSOutgoingMessage {
switch outgoingMessage.messageState {
case .failed:
return bubbleColorOutgoingFailed
case .sending:
return bubbleColorOutgoingSending
default:
return bubbleColorOutgoingSent
}
return bubbleColor(isIncoming: true)
} else {
owsFailDebug("Unexpected message type: \(message)")
return bubbleColorOutgoingSent
return bubbleColor(isIncoming: false)
}
}
@ -188,7 +162,7 @@ public class ConversationStyle: NSObject {
if isIncoming {
return ConversationStyle.defaultBubbleColorIncoming
} else {
return self.bubbleColorOutgoingSent
return conversationColors.themeColor
}
}
@ -229,10 +203,9 @@ public class ConversationStyle: NSObject {
@objc
public func quotedReplyBubbleColor(isIncoming: Bool) -> UIColor {
if Theme.isDarkThemeEnabled {
let alpha: CGFloat = (isIncoming ? 0.6 :0.5)
return UIColor.white.blend(with: bubbleColorOutgoingSent, alpha: alpha)
return conversationColors.shadeColor
} else if isIncoming {
return bubbleColorOutgoingSent.withAlphaComponent(0.25)
return conversationColors.tintColor
} else {
return ConversationStyle.defaultBubbleColorIncoming.withAlphaComponent(0.75)
}
@ -241,9 +214,9 @@ public class ConversationStyle: NSObject {
@objc
public func quotedReplyStripeColor(isIncoming: Bool) -> UIColor {
if isIncoming {
return bubbleColorOutgoingSent
return conversationColors.themeColor
} else {
return UIColor.white
return Theme.backgroundColor
}
}

@ -7,6 +7,7 @@
#import "OWSGroupAvatarBuilder.h"
#import "TSContactThread.h"
#import "TSGroupThread.h"
#import "Theme.h"
#import "UIColor+OWS.h"
#import "UIFont+OWS.h"
#import "UIView+OWS.h"

@ -124,10 +124,7 @@ NS_ASSUME_NONNULL_BEGIN
[initials appendString:@"#"];
}
UIColor *color =
[UIColor ows_conversationColorForColorName:self.colorName
mode:(Theme.isDarkThemeEnabled ? ConversationColorMode_Shade
: ConversationColorMode_Default)];
UIColor *color = [UIColor ows_conversationColorsOrDefaultForColorName:self.colorName].themeColor;
OWSAssertDebug(color);
UIImage *_Nullable image =

@ -3,6 +3,7 @@
//
#import "UIUtil.h"
#import "Theme.h"
#import "UIColor+OWS.h"
#import <SignalServiceKit/AppContext.h>

@ -33,7 +33,7 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (NSString *)name;
@property (readonly, nullable) NSString *conversationColorName;
@property (nonatomic, readonly) NSString *conversationColorName;
- (void)updateConversationColorName:(NSString *)colorName transaction:(YapDatabaseReadWriteTransaction *)transaction;
+ (NSString *)stableConversationColorNameForString:(NSString *)colorSeed;

@ -23,7 +23,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic) NSDate *creationDate;
@property (nonatomic, copy, nullable) NSDate *archivalDate;
@property (nonatomic, nullable) NSString *conversationColorName;
@property (nonatomic) NSString *conversationColorName;
@property (nonatomic, nullable) NSDate *lastMessageDate;
@property (nonatomic, copy, nullable) NSString *messageDraft;
@property (atomic, nullable) NSDate *mutedUntilDate;

Loading…
Cancel
Save