NCAppBranding.m 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /**
  2. * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-License-Identifier: GPL-3.0-or-later
  4. */
  5. #import "NCAppBranding.h"
  6. #import "NCDatabaseManager.h"
  7. #import "NextcloudTalk-Swift.h"
  8. typedef enum NCTextColorStyle {
  9. NCTextColorStyleLight = 0,
  10. NCTextColorStyleDark
  11. } NCTextColorStyle;
  12. @implementation NCAppBranding
  13. #pragma mark - App configuration
  14. NSString * const talkAppName = @"SX Rooms";
  15. NSString * const filesAppName = @"SX Space";
  16. NSString * const copyright = @"© 2024 ShariX";
  17. NSString * const bundleIdentifier = @"com.sharix.sxrooms";
  18. NSString * const groupIdentifier = @"group.com.sharix.sxrooms";
  19. NSString * const appsGroupIdentifier = @"group.com.sharix.apps";
  20. NSString * const pushNotificationServer = @"https://push-notifications.nextcloud.com";
  21. NSString * const privacyURL = @"https://wiki.sharix-app.org/doku.php/sharix/legal/politika_konfidencialnosti_platformy_sharix";
  22. BOOL const isBrandedApp = YES;
  23. BOOL const multiAccountEnabled = NO;
  24. BOOL const useAppsGroup = YES;
  25. BOOL const forceDomain = YES;
  26. NSString * const domain = @"https://nc.sharix-app.org";
  27. NSString * const appAlternateVersion = @"SX Edition";
  28. + (NSString *)getAppVersionString
  29. {
  30. if ([appAlternateVersion length] > 0) {
  31. return appAlternateVersion;
  32. }
  33. NSString *appVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
  34. return appVersion;
  35. }
  36. #pragma mark - Theming
  37. NSString * const brandColorHex = @"#39b54a";
  38. NSString * const brandTextColorHex = @"#FFFFFF";
  39. BOOL const customNavigationLogo = NO;
  40. BOOL const useServerThemimg = NO;
  41. + (UIColor *)brandColor
  42. {
  43. return [NCUtils colorFromHexString:brandColorHex];
  44. }
  45. + (UIColor *)brandTextColor
  46. {
  47. return [NCUtils colorFromHexString:brandTextColorHex];
  48. }
  49. + (UIColor *)themeColor
  50. {
  51. UIColor *color = [NCUtils colorFromHexString:brandColorHex];
  52. if (useServerThemimg) {
  53. TalkAccount *activeAccount = [[NCDatabaseManager sharedInstance] activeAccount];
  54. ServerCapabilities *serverCapabilities = [[NCDatabaseManager sharedInstance] serverCapabilitiesForAccountId:activeAccount.accountId];
  55. if (serverCapabilities && serverCapabilities.color) {
  56. UIColor *themeColor = [NCUtils colorFromHexString:serverCapabilities.color];
  57. if (themeColor) {
  58. color = themeColor;
  59. }
  60. }
  61. }
  62. return color;
  63. }
  64. + (UIColor *)themeTextColor
  65. {
  66. UIColor *textColor = [NCUtils colorFromHexString:brandTextColorHex];
  67. if (useServerThemimg) {
  68. TalkAccount *activeAccount = [[NCDatabaseManager sharedInstance] activeAccount];
  69. ServerCapabilities *serverCapabilities = [[NCDatabaseManager sharedInstance] serverCapabilitiesForAccountId:activeAccount.accountId];
  70. if (serverCapabilities && serverCapabilities.colorText) {
  71. UIColor *themeTextColor = [NCUtils colorFromHexString:serverCapabilities.colorText];
  72. if (themeTextColor) {
  73. textColor = themeTextColor;
  74. }
  75. }
  76. }
  77. return textColor;
  78. }
  79. + (UIColor *)elementColor
  80. {
  81. // Do not check if using server theming or not for now
  82. // We could check it once we calculate color element locally
  83. TalkAccount *activeAccount = [[NCDatabaseManager sharedInstance] activeAccount];
  84. ServerCapabilities *serverCapabilities = [[NCDatabaseManager sharedInstance] serverCapabilitiesForAccountId:activeAccount.accountId];
  85. if (serverCapabilities) {
  86. UIColor *elementColorBright = [NCUtils colorFromHexString:serverCapabilities.colorElementBright];
  87. UIColor *elementColorDark = [NCUtils colorFromHexString:serverCapabilities.colorElementDark];
  88. if (elementColorBright && elementColorDark) {
  89. return [self getDynamicColor:elementColorBright withDarkMode:elementColorDark];
  90. }
  91. UIColor *color = [NCUtils colorFromHexString:serverCapabilities.colorElement];
  92. if (color) {
  93. return color;
  94. }
  95. }
  96. UIColor *elementColor = [NCUtils colorFromHexString:brandColorHex];
  97. return elementColor;
  98. }
  99. + (UIColor *)getDynamicColor:(UIColor *)lightModeColor withDarkMode:(UIColor *)darkModeColor
  100. {
  101. return [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traits) {
  102. if (traits.userInterfaceStyle == UIUserInterfaceStyleDark) {
  103. return darkModeColor;
  104. }
  105. return lightModeColor;
  106. }];
  107. }
  108. + (NSString *)navigationLogoImageName
  109. {
  110. NSString *imageName = @"navigationLogo";
  111. if (!customNavigationLogo) {
  112. if (useServerThemimg && [self textColorStyleForBackgroundColor:[self themeColor]] == NCTextColorStyleDark) {
  113. imageName = @"navigationLogoDark";
  114. } else if ([self brandTextColorStyle] == NCTextColorStyleDark) {
  115. imageName = @"navigationLogoDark";
  116. }
  117. }
  118. return imageName;
  119. }
  120. + (UIColor *)placeholderColor
  121. {
  122. return [UIColor placeholderTextColor];
  123. }
  124. + (UIColor *)backgroundColor
  125. {
  126. return [UIColor systemBackgroundColor];
  127. }
  128. + (UIColor *)avatarPlaceholderColor
  129. {
  130. UIColor *light = [NCUtils colorFromHexString:@"#dbdbdb"];
  131. UIColor *dark = [NCUtils colorFromHexString:@"#3b3b3b"];
  132. return [self getDynamicColor:light withDarkMode:dark];
  133. }
  134. + (UIColor *)chatForegroundColor
  135. {
  136. return [self getDynamicColor:[UIColor darkGrayColor] withDarkMode:[UIColor labelColor]];
  137. }
  138. + (UIStatusBarStyle)statusBarStyleForBrandColor
  139. {
  140. return [self statusBarStyleForTextColorStyle:[self brandTextColorStyle]];
  141. }
  142. + (UIStatusBarStyle)statusBarStyleForThemeColor
  143. {
  144. if (useServerThemimg) {
  145. NCTextColorStyle style = [self textColorStyleForBackgroundColor:[self themeColor]];
  146. return [self statusBarStyleForTextColorStyle:style];
  147. }
  148. return [self statusBarStyleForBrandColor];
  149. }
  150. + (UIStatusBarStyle)statusBarStyleForTextColorStyle:(NCTextColorStyle)style
  151. {
  152. if (style == NCTextColorStyleDark) {
  153. return UIStatusBarStyleDarkContent;
  154. }
  155. return UIStatusBarStyleLightContent;
  156. }
  157. + (NCTextColorStyle)brandTextColorStyle
  158. {
  159. // Dark style when brand text color is black
  160. if ([brandTextColorHex isEqualToString:@"#000000"]) {
  161. return NCTextColorStyleDark;
  162. }
  163. // Light style when brand text color is white
  164. if ([brandTextColorHex isEqualToString:@"#FFFFFF"]) {
  165. return NCTextColorStyleLight;
  166. }
  167. // Check brand-color luma when brand-text-color is neither black nor white
  168. return [self textColorStyleForBackgroundColor:[self brandColor]];
  169. }
  170. + (NCTextColorStyle)textColorStyleForBackgroundColor:(UIColor *)color
  171. {
  172. CGFloat luma = [NCUtils calculateLumaFromColor:color];
  173. return (luma > 0.6) ? NCTextColorStyleDark : NCTextColorStyleLight;
  174. }
  175. + (void)styleViewController:(UIViewController *)controller {
  176. [controller.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[NCAppBranding themeTextColor]}];
  177. controller.navigationController.navigationBar.barTintColor = [NCAppBranding themeColor];
  178. controller.navigationController.navigationBar.tintColor = [NCAppBranding themeTextColor];
  179. controller.navigationController.navigationBar.translucent = NO;
  180. controller.tabBarController.tabBar.tintColor = [NCAppBranding themeColor];
  181. UIColor *themeColor = [NCAppBranding themeColor];
  182. UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
  183. [appearance configureWithOpaqueBackground];
  184. appearance.backgroundColor = themeColor;
  185. appearance.titleTextAttributes = @{NSForegroundColorAttributeName:[NCAppBranding themeTextColor]};
  186. controller.navigationItem.standardAppearance = appearance;
  187. controller.navigationItem.compactAppearance = appearance;
  188. controller.navigationItem.scrollEdgeAppearance = appearance;
  189. // Fix uisearchcontroller animation
  190. controller.extendedLayoutIncludesOpaqueBars = YES;
  191. }
  192. @end