mirror of https://github.com/oxen-io/session-ios
Merge branch 'charlesmchen/conversationColorsClass'
commit
469bb3fee2
@ -0,0 +1,83 @@
|
||||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface OWSConversationColor : NSObject
|
||||
|
||||
@property (nonatomic, readonly) UIColor *primaryColor;
|
||||
@property (nonatomic, readonly) UIColor *shadeColor;
|
||||
@property (nonatomic, readonly) UIColor *tintColor;
|
||||
|
||||
@property (nonatomic, readonly) UIColor *themeColor;
|
||||
|
||||
+ (OWSConversationColor *)conversationColorWithPrimaryColor:(UIColor *)primaryColor
|
||||
shadeColor:(UIColor *)shadeColor
|
||||
tintColor:(UIColor *)tintColor;
|
||||
|
||||
#pragma mark - Conversation Colors
|
||||
|
||||
@property (class, readonly, nonatomic) UIColor *ows_crimsonColor;
|
||||
@property (class, readonly, nonatomic) UIColor *ows_vermilionColor;
|
||||
@property (class, readonly, nonatomic) UIColor *ows_burlapColor;
|
||||
@property (class, readonly, nonatomic) UIColor *ows_forestColor;
|
||||
@property (class, readonly, nonatomic) UIColor *ows_wintergreenColor;
|
||||
@property (class, readonly, nonatomic) UIColor *ows_tealColor;
|
||||
@property (class, readonly, nonatomic) UIColor *ows_blueColor;
|
||||
@property (class, readonly, nonatomic) UIColor *ows_indigoColor;
|
||||
@property (class, readonly, nonatomic) UIColor *ows_violetColor;
|
||||
@property (class, readonly, nonatomic) UIColor *ows_plumColor;
|
||||
@property (class, readonly, nonatomic) UIColor *ows_taupeColor;
|
||||
@property (class, readonly, nonatomic) UIColor *ows_steelColor;
|
||||
|
||||
#pragma mark - Conversation Colors (Tint)
|
||||
|
||||
@property (class, readonly, nonatomic) UIColor *ows_crimsonTintColor;
|
||||
@property (class, readonly, nonatomic) UIColor *ows_vermilionTintColor;
|
||||
@property (class, readonly, nonatomic) UIColor *ows_burlapTintColor;
|
||||
@property (class, readonly, nonatomic) UIColor *ows_forestTintColor;
|
||||
@property (class, readonly, nonatomic) UIColor *ows_wintergreenTintColor;
|
||||
@property (class, readonly, nonatomic) UIColor *ows_tealTintColor;
|
||||
@property (class, readonly, nonatomic) UIColor *ows_blueTintColor;
|
||||
@property (class, readonly, nonatomic) UIColor *ows_indigoTintColor;
|
||||
@property (class, readonly, nonatomic) UIColor *ows_violetTintColor;
|
||||
@property (class, readonly, nonatomic) UIColor *ows_plumTintColor;
|
||||
@property (class, readonly, nonatomic) UIColor *ows_taupeTintColor;
|
||||
@property (class, readonly, nonatomic) UIColor *ows_steelTintColor;
|
||||
|
||||
#pragma mark - Conversation Colors (Shade)
|
||||
|
||||
@property (class, readonly, nonatomic) UIColor *ows_crimsonShadeColor;
|
||||
@property (class, readonly, nonatomic) UIColor *ows_vermilionShadeColor;
|
||||
@property (class, readonly, nonatomic) UIColor *ows_burlapShadeColor;
|
||||
@property (class, readonly, nonatomic) UIColor *ows_forestShadeColor;
|
||||
@property (class, readonly, nonatomic) UIColor *ows_wintergreenShadeColor;
|
||||
@property (class, readonly, nonatomic) UIColor *ows_tealShadeColor;
|
||||
@property (class, readonly, nonatomic) UIColor *ows_blueShadeColor;
|
||||
@property (class, readonly, nonatomic) UIColor *ows_indigoShadeColor;
|
||||
@property (class, readonly, nonatomic) UIColor *ows_violetShadeColor;
|
||||
@property (class, readonly, nonatomic) UIColor *ows_plumShadeColor;
|
||||
@property (class, readonly, nonatomic) UIColor *ows_taupeShadeColor;
|
||||
@property (class, readonly, nonatomic) UIColor *ows_steelShadeColor;
|
||||
|
||||
#pragma mark - Conversation Colors
|
||||
|
||||
+ (nullable OWSConversationColor *)conversationColorForColorName:(NSString *)colorName
|
||||
NS_SWIFT_NAME(conversationColor(colorName:));
|
||||
|
||||
// If the conversation color name is valid, return its colors.
|
||||
// Otherwise return the "default" conversation colors.
|
||||
+ (OWSConversationColor *)conversationColorOrDefaultForColorName:(NSString *)conversationColorName
|
||||
NS_SWIFT_NAME(conversationColorOrDefault(colorName:));
|
||||
|
||||
@property (class, readonly, nonatomic) NSArray<NSString *> *conversationColorNames;
|
||||
|
||||
+ (NSString *)defaultConversationColorName;
|
||||
+ (OWSConversationColor *)defaultConversationColor;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
@ -0,0 +1,380 @@
|
||||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "OWSConversationColor.h"
|
||||
#import "Theme.h"
|
||||
#import "UIColor+OWS.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface OWSConversationColor ()
|
||||
|
||||
@property (nonatomic) UIColor *primaryColor;
|
||||
@property (nonatomic) UIColor *shadeColor;
|
||||
@property (nonatomic) UIColor *tintColor;
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@implementation OWSConversationColor
|
||||
|
||||
+ (OWSConversationColor *)conversationColorWithPrimaryColor:(UIColor *)primaryColor
|
||||
shadeColor:(UIColor *)shadeColor
|
||||
tintColor:(UIColor *)tintColor
|
||||
{
|
||||
OWSConversationColor *instance = [OWSConversationColor new];
|
||||
instance.primaryColor = primaryColor;
|
||||
instance.shadeColor = shadeColor;
|
||||
instance.tintColor = tintColor;
|
||||
return instance;
|
||||
}
|
||||
|
||||
- (UIColor *)themeColor
|
||||
{
|
||||
return Theme.isDarkThemeEnabled ? self.shadeColor : self.primaryColor;
|
||||
}
|
||||
|
||||
#pragma mark - Conversation Colors
|
||||
|
||||
+ (UIColor *)ows_crimsonColor
|
||||
{
|
||||
return [UIColor colorWithRGBHex:0xCC163D];
|
||||
}
|
||||
|
||||
+ (UIColor *)ows_vermilionColor
|
||||
{
|
||||
return [UIColor colorWithRGBHex:0xC73800];
|
||||
}
|
||||
|
||||
+ (UIColor *)ows_burlapColor
|
||||
{
|
||||
return [UIColor colorWithRGBHex:0x746C53];
|
||||
}
|
||||
|
||||
+ (UIColor *)ows_forestColor
|
||||
{
|
||||
return [UIColor colorWithRGBHex:0x3B7845];
|
||||
}
|
||||
|
||||
+ (UIColor *)ows_wintergreenColor
|
||||
{
|
||||
return [UIColor colorWithRGBHex:0x1C8260];
|
||||
}
|
||||
|
||||
+ (UIColor *)ows_tealColor
|
||||
{
|
||||
return [UIColor colorWithRGBHex:0x067589];
|
||||
}
|
||||
|
||||
+ (UIColor *)ows_blueColor
|
||||
{
|
||||
return [UIColor colorWithRGBHex:0x336BA3];
|
||||
}
|
||||
|
||||
+ (UIColor *)ows_indigoColor
|
||||
{
|
||||
return [UIColor colorWithRGBHex:0x5951C8];
|
||||
}
|
||||
|
||||
+ (UIColor *)ows_violetColor
|
||||
{
|
||||
return [UIColor colorWithRGBHex:0x862CAF];
|
||||
}
|
||||
|
||||
+ (UIColor *)ows_plumColor
|
||||
{
|
||||
return [UIColor colorWithRGBHex:0xA23474];
|
||||
}
|
||||
|
||||
+ (UIColor *)ows_taupeColor
|
||||
{
|
||||
return [UIColor colorWithRGBHex:0x895D66];
|
||||
}
|
||||
|
||||
+ (UIColor *)ows_steelColor
|
||||
{
|
||||
return [UIColor colorWithRGBHex:0x6B6B78];
|
||||
}
|
||||
|
||||
#pragma mark - Conversation Colors (Tint)
|
||||
|
||||
+ (UIColor *)ows_crimsonTintColor
|
||||
{
|
||||
return [UIColor colorWithRGBHex:0xEDA6AE];
|
||||
}
|
||||
|
||||
+ (UIColor *)ows_vermilionTintColor
|
||||
{
|
||||
return [UIColor colorWithRGBHex:0xEBA78E];
|
||||
}
|
||||
|
||||
+ (UIColor *)ows_burlapTintColor
|
||||
{
|
||||
return [UIColor colorWithRGBHex:0xC4B997];
|
||||
}
|
||||
|
||||
+ (UIColor *)ows_forestTintColor
|
||||
{
|
||||
return [UIColor colorWithRGBHex:0x8FCC9A];
|
||||
}
|
||||
|
||||
+ (UIColor *)ows_wintergreenTintColor
|
||||
{
|
||||
return [UIColor colorWithRGBHex:0x9BCFBD];
|
||||
}
|
||||
|
||||
+ (UIColor *)ows_tealTintColor
|
||||
{
|
||||
return [UIColor colorWithRGBHex:0xA5CAD5];
|
||||
}
|
||||
|
||||
+ (UIColor *)ows_blueTintColor
|
||||
{
|
||||
return [UIColor colorWithRGBHex:0xADC8E1];
|
||||
}
|
||||
|
||||
+ (UIColor *)ows_indigoTintColor
|
||||
{
|
||||
return [UIColor colorWithRGBHex:0xC2C1E7];
|
||||
}
|
||||
|
||||
+ (UIColor *)ows_violetTintColor
|
||||
{
|
||||
return [UIColor colorWithRGBHex:0xCDADDC];
|
||||
}
|
||||
|
||||
+ (UIColor *)ows_plumTintColor
|
||||
{
|
||||
return [UIColor colorWithRGBHex:0xDCB2CA];
|
||||
}
|
||||
|
||||
+ (UIColor *)ows_taupeTintColor
|
||||
{
|
||||
return [UIColor colorWithRGBHex:0xCFB5BB];
|
||||
}
|
||||
|
||||
+ (UIColor *)ows_steelTintColor
|
||||
{
|
||||
return [UIColor colorWithRGBHex:0xBEBEC6];
|
||||
}
|
||||
|
||||
#pragma mark - Conversation Colors (Shade)
|
||||
|
||||
+ (UIColor *)ows_crimsonShadeColor
|
||||
{
|
||||
return [UIColor colorWithRGBHex:0x8A0F29];
|
||||
}
|
||||
|
||||
+ (UIColor *)ows_vermilionShadeColor
|
||||
{
|
||||
return [UIColor colorWithRGBHex:0x872600];
|
||||
}
|
||||
|
||||
+ (UIColor *)ows_burlapShadeColor
|
||||
{
|
||||
return [UIColor colorWithRGBHex:0x58513C];
|
||||
}
|
||||
|
||||
+ (UIColor *)ows_forestShadeColor
|
||||
{
|
||||
return [UIColor colorWithRGBHex:0x2B5934];
|
||||
}
|
||||
|
||||
+ (UIColor *)ows_wintergreenShadeColor
|
||||
{
|
||||
return [UIColor colorWithRGBHex:0x36544A];
|
||||
}
|
||||
|
||||
+ (UIColor *)ows_tealShadeColor
|
||||
{
|
||||
return [UIColor colorWithRGBHex:0x055968];
|
||||
}
|
||||
|
||||
+ (UIColor *)ows_blueShadeColor
|
||||
{
|
||||
return [UIColor colorWithRGBHex:0x285480];
|
||||
}
|
||||
|
||||
+ (UIColor *)ows_indigoShadeColor
|
||||
{
|
||||
return [UIColor colorWithRGBHex:0x4840A0];
|
||||
}
|
||||
|
||||
+ (UIColor *)ows_violetShadeColor
|
||||
{
|
||||
return [UIColor colorWithRGBHex:0x6B248A];
|
||||
}
|
||||
|
||||
+ (UIColor *)ows_plumShadeColor
|
||||
{
|
||||
return [UIColor colorWithRGBHex:0x881B5B];
|
||||
}
|
||||
|
||||
+ (UIColor *)ows_taupeShadeColor
|
||||
{
|
||||
return [UIColor colorWithRGBHex:0x6A4E54];
|
||||
}
|
||||
|
||||
+ (UIColor *)ows_steelShadeColor
|
||||
{
|
||||
return [UIColor colorWithRGBHex:0x5A5A63];
|
||||
}
|
||||
|
||||
+ (NSDictionary<NSString *, UIColor *> *)conversationColorMap
|
||||
{
|
||||
static NSDictionary<NSString *, UIColor *> *colorMap;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
colorMap = @{
|
||||
@"crimson" : self.ows_crimsonColor,
|
||||
@"vermilion" : self.ows_vermilionColor,
|
||||
@"burlap" : self.ows_burlapColor,
|
||||
@"forest" : self.ows_forestColor,
|
||||
@"wintergreen" : self.ows_wintergreenColor,
|
||||
@"teal" : self.ows_tealColor,
|
||||
@"blue" : self.ows_blueColor,
|
||||
@"indigo" : self.ows_indigoColor,
|
||||
@"violet" : self.ows_violetColor,
|
||||
@"plum" : self.ows_plumColor,
|
||||
@"taupe" : self.ows_taupeColor,
|
||||
@"steel" : self.ows_steelColor,
|
||||
};
|
||||
});
|
||||
|
||||
return colorMap;
|
||||
}
|
||||
|
||||
+ (NSDictionary<NSString *, UIColor *> *)conversationColorMapShade
|
||||
{
|
||||
static NSDictionary<NSString *, UIColor *> *colorMap;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
colorMap = @{
|
||||
@"crimson" : self.ows_crimsonShadeColor,
|
||||
@"vermilion" : self.ows_vermilionShadeColor,
|
||||
@"burlap" : self.ows_burlapShadeColor,
|
||||
@"forest" : self.ows_forestShadeColor,
|
||||
@"wintergreen" : self.ows_wintergreenShadeColor,
|
||||
@"teal" : self.ows_tealShadeColor,
|
||||
@"blue" : self.ows_blueShadeColor,
|
||||
@"indigo" : self.ows_indigoShadeColor,
|
||||
@"violet" : self.ows_violetShadeColor,
|
||||
@"plum" : self.ows_plumShadeColor,
|
||||
@"taupe" : self.ows_taupeShadeColor,
|
||||
@"steel" : self.ows_steelShadeColor,
|
||||
};
|
||||
OWSAssertDebug([self.conversationColorMap.allKeys isEqualToArray:colorMap.allKeys]);
|
||||
});
|
||||
|
||||
return colorMap;
|
||||
}
|
||||
|
||||
+ (NSDictionary<NSString *, UIColor *> *)conversationColorMapTint
|
||||
{
|
||||
static NSDictionary<NSString *, UIColor *> *colorMap;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
colorMap = @{
|
||||
@"crimson" : self.ows_crimsonTintColor,
|
||||
@"vermilion" : self.ows_vermilionTintColor,
|
||||
@"burlap" : self.ows_burlapTintColor,
|
||||
@"forest" : self.ows_forestTintColor,
|
||||
@"wintergreen" : self.ows_wintergreenTintColor,
|
||||
@"teal" : self.ows_tealTintColor,
|
||||
@"blue" : self.ows_blueTintColor,
|
||||
@"indigo" : self.ows_indigoTintColor,
|
||||
@"violet" : self.ows_violetTintColor,
|
||||
@"plum" : self.ows_plumTintColor,
|
||||
@"taupe" : self.ows_taupeTintColor,
|
||||
@"steel" : self.ows_steelTintColor,
|
||||
};
|
||||
OWSAssertDebug([self.conversationColorMap.allKeys isEqualToArray:colorMap.allKeys]);
|
||||
});
|
||||
|
||||
return colorMap;
|
||||
}
|
||||
|
||||
+ (NSDictionary<NSString *, NSString *> *)ows_legacyConversationColorMap
|
||||
{
|
||||
static NSDictionary<NSString *, NSString *> *colorMap;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
colorMap = @{
|
||||
@"red" : @"crimson",
|
||||
@"deep_orange" : @"crimson",
|
||||
@"orange" : @"vermilion",
|
||||
@"amber" : @"vermilion",
|
||||
@"brown" : @"burlap",
|
||||
@"yellow" : @"burlap",
|
||||
@"pink" : @"plum",
|
||||
@"purple" : @"violet",
|
||||
@"deep_purple" : @"violet",
|
||||
@"indigo" : @"indigo",
|
||||
@"blue" : @"blue",
|
||||
@"light_blue" : @"blue",
|
||||
@"cyan" : @"teal",
|
||||
@"teal" : @"teal",
|
||||
@"green" : @"forest",
|
||||
@"light_green" : @"wintergreen",
|
||||
@"lime" : @"wintergreen",
|
||||
@"blue_grey" : @"taupe",
|
||||
@"grey" : @"steel",
|
||||
};
|
||||
});
|
||||
|
||||
return colorMap;
|
||||
}
|
||||
|
||||
+ (NSArray<NSString *> *)conversationColorNames
|
||||
{
|
||||
return self.conversationColorMap.allKeys;
|
||||
}
|
||||
|
||||
+ (nullable OWSConversationColor *)conversationColorForColorName:(NSString *)conversationColorName
|
||||
{
|
||||
NSString *_Nullable mappedColorName = self.ows_legacyConversationColorMap[conversationColorName.lowercaseString];
|
||||
if (mappedColorName) {
|
||||
conversationColorName = mappedColorName;
|
||||
} else {
|
||||
OWSAssertDebug(self.conversationColorMap[conversationColorName] != nil);
|
||||
}
|
||||
|
||||
UIColor *_Nullable primaryColor = self.conversationColorMap[conversationColorName];
|
||||
UIColor *_Nullable shadeColor = self.conversationColorMapShade[conversationColorName];
|
||||
UIColor *_Nullable tintColor = self.conversationColorMapTint[conversationColorName];
|
||||
if (!primaryColor || !shadeColor || !tintColor) {
|
||||
return nil;
|
||||
}
|
||||
OWSAssertDebug(primaryColor);
|
||||
OWSAssertDebug(shadeColor);
|
||||
OWSAssertDebug(tintColor);
|
||||
return
|
||||
[OWSConversationColor conversationColorWithPrimaryColor:primaryColor shadeColor:shadeColor tintColor:tintColor];
|
||||
}
|
||||
|
||||
+ (OWSConversationColor *)conversationColorOrDefaultForColorName:(NSString *)conversationColorName
|
||||
{
|
||||
OWSConversationColor *_Nullable conversationColor = [self conversationColorForColorName:conversationColorName];
|
||||
if (conversationColor) {
|
||||
return conversationColor;
|
||||
}
|
||||
return [self defaultConversationColor];
|
||||
}
|
||||
|
||||
+ (NSString *)defaultConversationColorName
|
||||
{
|
||||
NSString *conversationColorName = @"steel";
|
||||
OWSAssert([self.conversationColorNames containsObject:conversationColorName]);
|
||||
return conversationColorName;
|
||||
}
|
||||
|
||||
+ (OWSConversationColor *)defaultConversationColor
|
||||
{
|
||||
return [self conversationColorForColorName:self.defaultConversationColorName];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
Loading…
Reference in New Issue