mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
189 lines
4.5 KiB
Objective-C
189 lines
4.5 KiB
Objective-C
//
|
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
|
//
|
|
|
|
#import "Theme.h"
|
|
#import "UIColor+OWS.h"
|
|
#import "UIUtil.h"
|
|
#import <SignalServiceKit/NSNotificationCenter+OWS.h>
|
|
#import <SignalServiceKit/OWSPrimaryStorage.h>
|
|
#import <SignalServiceKit/YapDatabaseConnection+OWS.h>
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
NSString *const ThemeDidChangeNotification = @"ThemeDidChangeNotification";
|
|
|
|
NSString *const ThemeCollection = @"ThemeCollection";
|
|
NSString *const ThemeKeyThemeEnabled = @"ThemeKeyThemeEnabled";
|
|
|
|
@implementation Theme
|
|
|
|
+ (BOOL)isDarkThemeEnabled
|
|
{
|
|
if (!CurrentAppContext().isMainApp) {
|
|
// Ignore theme in app extensions.
|
|
return NO;
|
|
}
|
|
|
|
return [OWSPrimaryStorage.sharedManager.dbReadConnection boolForKey:ThemeKeyThemeEnabled
|
|
inCollection:ThemeCollection
|
|
defaultValue:NO];
|
|
}
|
|
|
|
+ (void)setIsDarkThemeEnabled:(BOOL)value
|
|
{
|
|
OWSAssertIsOnMainThread();
|
|
|
|
[OWSPrimaryStorage.sharedManager.dbReadWriteConnection setBool:value
|
|
forKey:ThemeKeyThemeEnabled
|
|
inCollection:ThemeCollection];
|
|
|
|
[UIUtil setupSignalAppearence];
|
|
|
|
[UIView performWithoutAnimation:^{
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:ThemeDidChangeNotification object:nil userInfo:nil];
|
|
}];
|
|
}
|
|
|
|
+ (UIColor *)backgroundColor
|
|
{
|
|
return (Theme.isDarkThemeEnabled ? Theme.darkThemeBackgroundColor : UIColor.ows_whiteColor);
|
|
}
|
|
|
|
+ (UIColor *)offBackgroundColor
|
|
{
|
|
return (
|
|
Theme.isDarkThemeEnabled ? [UIColor colorWithWhite:0.2f alpha:1.f] : [UIColor colorWithWhite:0.94f alpha:1.f]);
|
|
}
|
|
|
|
+ (UIColor *)primaryColor
|
|
{
|
|
return (Theme.isDarkThemeEnabled ? Theme.darkThemePrimaryColor : UIColor.ows_gray90Color);
|
|
}
|
|
|
|
+ (UIColor *)secondaryColor
|
|
{
|
|
return (Theme.isDarkThemeEnabled ? UIColor.ows_gray25Color : UIColor.ows_gray60Color);
|
|
}
|
|
|
|
+ (UIColor *)boldColor
|
|
{
|
|
return (Theme.isDarkThemeEnabled ? UIColor.ows_whiteColor : UIColor.blackColor);
|
|
}
|
|
|
|
+ (UIColor *)middleGrayColor
|
|
{
|
|
return [UIColor colorWithWhite:0.5f alpha:1.f];
|
|
}
|
|
|
|
+ (UIColor *)placeholderColor
|
|
{
|
|
return (Theme.isDarkThemeEnabled ? UIColor.ows_gray45Color : UIColor.ows_gray45Color);
|
|
}
|
|
|
|
+ (UIColor *)hairlineColor
|
|
{
|
|
return (Theme.isDarkThemeEnabled ? UIColor.ows_gray75Color : UIColor.ows_gray25Color);
|
|
}
|
|
|
|
#pragma mark - Global App Colors
|
|
|
|
+ (UIColor *)navbarBackgroundColor
|
|
{
|
|
return (Theme.isDarkThemeEnabled ? self.darkThemeNavbarBackgroundColor : UIColor.ows_whiteColor);
|
|
}
|
|
|
|
+ (UIColor *)darkThemeNavbarBackgroundColor
|
|
{
|
|
return UIColor.ows_blackColor;
|
|
}
|
|
|
|
+ (UIColor *)navbarIconColor
|
|
{
|
|
return (Theme.isDarkThemeEnabled ? self.darkThemeNavbarIconColor : UIColor.ows_gray60Color);
|
|
}
|
|
|
|
+ (UIColor *)darkThemeNavbarIconColor;
|
|
{
|
|
return UIColor.ows_gray25Color;
|
|
}
|
|
|
|
+ (UIColor *)navbarTitleColor
|
|
{
|
|
return Theme.primaryColor;
|
|
}
|
|
|
|
+ (UIColor *)toolbarBackgroundColor
|
|
{
|
|
return self.navbarBackgroundColor;
|
|
}
|
|
|
|
+ (UIColor *)cellSelectedColor
|
|
{
|
|
return (Theme.isDarkThemeEnabled ? [UIColor colorWithWhite:0.2 alpha:1] : [UIColor colorWithWhite:0.92 alpha:1]);
|
|
}
|
|
|
|
+ (UIColor *)cellSeparatorColor
|
|
{
|
|
return Theme.hairlineColor;
|
|
}
|
|
|
|
+ (UIColor *)darkThemeBackgroundColor
|
|
{
|
|
return UIColor.ows_gray95Color;
|
|
}
|
|
|
|
+ (UIColor *)darkThemePrimaryColor
|
|
{
|
|
return UIColor.ows_gray05Color;
|
|
}
|
|
|
|
+ (UIColor *)conversationButtonBackgroundColor
|
|
{
|
|
return (Theme.isDarkThemeEnabled ? [UIColor colorWithWhite:0.35f alpha:1.f] : UIColor.ows_gray02Color);
|
|
}
|
|
|
|
+ (UIBlurEffect *)barBlurEffect
|
|
{
|
|
return Theme.isDarkThemeEnabled ? self.darkThemeBarBlurEffect
|
|
: [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
|
|
}
|
|
|
|
+ (UIBlurEffect *)darkThemeBarBlurEffect
|
|
{
|
|
return [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
|
|
}
|
|
|
|
+ (UIKeyboardAppearance)keyboardAppearance
|
|
{
|
|
return Theme.isDarkThemeEnabled ? UIKeyboardAppearanceDark : UIKeyboardAppearanceDefault;
|
|
}
|
|
|
|
#pragma mark - Search Bar
|
|
|
|
+ (UIBarStyle)barStyle
|
|
{
|
|
return Theme.isDarkThemeEnabled ? UIBarStyleBlack : UIBarStyleDefault;
|
|
}
|
|
|
|
+ (UIColor *)searchFieldBackgroundColor
|
|
{
|
|
return Theme.isDarkThemeEnabled ? Theme.offBackgroundColor : UIColor.ows_gray05Color;
|
|
}
|
|
|
|
#pragma mark -
|
|
|
|
+ (UIColor *)toastForegroundColor
|
|
{
|
|
return (Theme.isDarkThemeEnabled ? UIColor.ows_whiteColor : UIColor.ows_whiteColor);
|
|
}
|
|
|
|
+ (UIColor *)toastBackgroundColor
|
|
{
|
|
return (Theme.isDarkThemeEnabled ? UIColor.ows_gray75Color : UIColor.ows_gray60Color);
|
|
}
|
|
|
|
@end
|
|
|
|
NS_ASSUME_NONNULL_END
|