123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- /**
- * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
- * SPDX-License-Identifier: GPL-3.0-or-later
- */
- #import "NCAppBranding.h"
- #import "NCDatabaseManager.h"
- #import "NextcloudTalk-Swift.h"
- typedef enum NCTextColorStyle {
- NCTextColorStyleLight = 0,
- NCTextColorStyleDark
- } NCTextColorStyle;
- @implementation NCAppBranding
- #pragma mark - App configuration
- NSString * const talkAppName = @"SX Rooms";
- NSString * const filesAppName = @"SX Space";
- NSString * const copyright = @"© 2024 ShariX";
- NSString * const bundleIdentifier = @"com.sharix.sxrooms";
- NSString * const groupIdentifier = @"group.com.sharix.sxrooms";
- NSString * const appsGroupIdentifier = @"group.com.sharix.apps";
- NSString * const pushNotificationServer = @"https://push-notifications.nextcloud.com";
- NSString * const privacyURL = @"https://wiki.sharix-app.org/doku.php/sharix/legal/politika_konfidencialnosti_platformy_sharix";
- BOOL const isBrandedApp = YES;
- BOOL const multiAccountEnabled = NO;
- BOOL const useAppsGroup = YES;
- BOOL const forceDomain = YES;
- NSString * const domain = @"https://nc.sharix-app.org";
- NSString * const appAlternateVersion = @"SX Edition";
- + (NSString *)getAppVersionString
- {
- if ([appAlternateVersion length] > 0) {
- return appAlternateVersion;
- }
- NSString *appVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
- return appVersion;
- }
- #pragma mark - Theming
- NSString * const brandColorHex = @"#39b54a";
- NSString * const brandTextColorHex = @"#FFFFFF";
- BOOL const customNavigationLogo = NO;
- BOOL const useServerThemimg = NO;
- + (UIColor *)brandColor
- {
- return [NCUtils colorFromHexString:brandColorHex];
- }
- + (UIColor *)brandTextColor
- {
- return [NCUtils colorFromHexString:brandTextColorHex];
- }
- + (UIColor *)themeColor
- {
- UIColor *color = [NCUtils colorFromHexString:brandColorHex];
- if (useServerThemimg) {
- TalkAccount *activeAccount = [[NCDatabaseManager sharedInstance] activeAccount];
- ServerCapabilities *serverCapabilities = [[NCDatabaseManager sharedInstance] serverCapabilitiesForAccountId:activeAccount.accountId];
- if (serverCapabilities && serverCapabilities.color) {
- UIColor *themeColor = [NCUtils colorFromHexString:serverCapabilities.color];
- if (themeColor) {
- color = themeColor;
- }
- }
- }
- return color;
- }
- + (UIColor *)themeTextColor
- {
- UIColor *textColor = [NCUtils colorFromHexString:brandTextColorHex];
- if (useServerThemimg) {
- TalkAccount *activeAccount = [[NCDatabaseManager sharedInstance] activeAccount];
- ServerCapabilities *serverCapabilities = [[NCDatabaseManager sharedInstance] serverCapabilitiesForAccountId:activeAccount.accountId];
- if (serverCapabilities && serverCapabilities.colorText) {
- UIColor *themeTextColor = [NCUtils colorFromHexString:serverCapabilities.colorText];
- if (themeTextColor) {
- textColor = themeTextColor;
- }
- }
- }
- return textColor;
- }
- + (UIColor *)elementColor
- {
- // Do not check if using server theming or not for now
- // We could check it once we calculate color element locally
- TalkAccount *activeAccount = [[NCDatabaseManager sharedInstance] activeAccount];
- ServerCapabilities *serverCapabilities = [[NCDatabaseManager sharedInstance] serverCapabilitiesForAccountId:activeAccount.accountId];
- if (serverCapabilities) {
- UIColor *elementColorBright = [NCUtils colorFromHexString:serverCapabilities.colorElementBright];
- UIColor *elementColorDark = [NCUtils colorFromHexString:serverCapabilities.colorElementDark];
- if (elementColorBright && elementColorDark) {
- return [self getDynamicColor:elementColorBright withDarkMode:elementColorDark];
- }
- UIColor *color = [NCUtils colorFromHexString:serverCapabilities.colorElement];
- if (color) {
- return color;
- }
- }
-
- UIColor *elementColor = [NCUtils colorFromHexString:brandColorHex];
- return elementColor;
- }
- + (UIColor *)getDynamicColor:(UIColor *)lightModeColor withDarkMode:(UIColor *)darkModeColor
- {
- return [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traits) {
- if (traits.userInterfaceStyle == UIUserInterfaceStyleDark) {
- return darkModeColor;
- }
-
- return lightModeColor;
- }];
- }
- + (NSString *)navigationLogoImageName
- {
- NSString *imageName = @"navigationLogo";
- if (!customNavigationLogo) {
- if (useServerThemimg && [self textColorStyleForBackgroundColor:[self themeColor]] == NCTextColorStyleDark) {
- imageName = @"navigationLogoDark";
- } else if ([self brandTextColorStyle] == NCTextColorStyleDark) {
- imageName = @"navigationLogoDark";
- }
- }
- return imageName;
- }
- + (UIColor *)placeholderColor
- {
- return [UIColor placeholderTextColor];
- }
- + (UIColor *)backgroundColor
- {
- return [UIColor systemBackgroundColor];
- }
- + (UIColor *)avatarPlaceholderColor
- {
- UIColor *light = [NCUtils colorFromHexString:@"#dbdbdb"];
- UIColor *dark = [NCUtils colorFromHexString:@"#3b3b3b"];
- return [self getDynamicColor:light withDarkMode:dark];
- }
- + (UIColor *)chatForegroundColor
- {
- return [self getDynamicColor:[UIColor darkGrayColor] withDarkMode:[UIColor labelColor]];
- }
- + (UIStatusBarStyle)statusBarStyleForBrandColor
- {
- return [self statusBarStyleForTextColorStyle:[self brandTextColorStyle]];
- }
- + (UIStatusBarStyle)statusBarStyleForThemeColor
- {
- if (useServerThemimg) {
- NCTextColorStyle style = [self textColorStyleForBackgroundColor:[self themeColor]];
- return [self statusBarStyleForTextColorStyle:style];
- }
- return [self statusBarStyleForBrandColor];
- }
- + (UIStatusBarStyle)statusBarStyleForTextColorStyle:(NCTextColorStyle)style
- {
- if (style == NCTextColorStyleDark) {
- return UIStatusBarStyleDarkContent;
- }
- return UIStatusBarStyleLightContent;
- }
- + (NCTextColorStyle)brandTextColorStyle
- {
- // Dark style when brand text color is black
- if ([brandTextColorHex isEqualToString:@"#000000"]) {
- return NCTextColorStyleDark;
- }
-
- // Light style when brand text color is white
- if ([brandTextColorHex isEqualToString:@"#FFFFFF"]) {
- return NCTextColorStyleLight;
- }
-
- // Check brand-color luma when brand-text-color is neither black nor white
- return [self textColorStyleForBackgroundColor:[self brandColor]];
- }
- + (NCTextColorStyle)textColorStyleForBackgroundColor:(UIColor *)color
- {
- CGFloat luma = [NCUtils calculateLumaFromColor:color];
- return (luma > 0.6) ? NCTextColorStyleDark : NCTextColorStyleLight;
- }
- + (void)styleViewController:(UIViewController *)controller {
- [controller.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[NCAppBranding themeTextColor]}];
- controller.navigationController.navigationBar.barTintColor = [NCAppBranding themeColor];
- controller.navigationController.navigationBar.tintColor = [NCAppBranding themeTextColor];
- controller.navigationController.navigationBar.translucent = NO;
- controller.tabBarController.tabBar.tintColor = [NCAppBranding themeColor];
- UIColor *themeColor = [NCAppBranding themeColor];
- UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
- [appearance configureWithOpaqueBackground];
- appearance.backgroundColor = themeColor;
- appearance.titleTextAttributes = @{NSForegroundColorAttributeName:[NCAppBranding themeTextColor]};
- controller.navigationItem.standardAppearance = appearance;
- controller.navigationItem.compactAppearance = appearance;
- controller.navigationItem.scrollEdgeAppearance = appearance;
- // Fix uisearchcontroller animation
- controller.extendedLayoutIncludesOpaqueBars = YES;
- }
- @end
|