WFCUConfigManager.m 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. //
  2. // WFCUConfigManager.m
  3. // WFChatUIKit
  4. //
  5. // Created by heavyrain lee on 2019/9/22.
  6. // Copyright © 2019 WF Chat. All rights reserved.
  7. //
  8. #import "WFCUConfigManager.h"
  9. #import "UIColor+YH.h"
  10. #import <WFChatClient/WFCChatClient.h>
  11. static WFCUConfigManager *sharedSingleton = nil;
  12. @implementation WFCUConfigManager
  13. + (WFCUConfigManager *)globalManager {
  14. if (sharedSingleton == nil) {
  15. @synchronized (self) {
  16. if (sharedSingleton == nil) {
  17. sharedSingleton = [[WFCUConfigManager alloc] init];
  18. sharedSingleton.conversationFilesDir = @"ConversationResource";
  19. }
  20. }
  21. }
  22. return sharedSingleton;
  23. }
  24. - (instancetype)init {
  25. self = [super init];
  26. if (self) {
  27. _selectedTheme = [[NSUserDefaults standardUserDefaults] integerForKey:@"WFC_THEME_TYPE"];
  28. }
  29. return self;
  30. }
  31. -(void)setSelectedTheme:(WFCUThemeType)themeType {
  32. _selectedTheme = themeType;
  33. [[NSUserDefaults standardUserDefaults] setInteger:themeType forKey:@"WFC_THEME_TYPE"];
  34. [[NSUserDefaults standardUserDefaults] synchronize];
  35. [self setupNavBar];
  36. }
  37. - (void)setupNavBar {
  38. [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
  39. UINavigationBar *bar = [UINavigationBar appearance];
  40. bar.barTintColor = [WFCUConfigManager globalManager].naviBackgroudColor;
  41. bar.tintColor = [WFCUConfigManager globalManager].naviTextColor;
  42. bar.titleTextAttributes = @{NSForegroundColorAttributeName : [WFCUConfigManager globalManager].naviTextColor};
  43. bar.barStyle = UIBarStyleDefault;
  44. if (@available(iOS 13, *)) {
  45. UINavigationBarAppearance *navBarAppearance = [[UINavigationBarAppearance alloc] init];
  46. bar.standardAppearance = navBarAppearance;
  47. bar.scrollEdgeAppearance = navBarAppearance;
  48. navBarAppearance.backgroundColor = [WFCUConfigManager globalManager].naviBackgroudColor;
  49. navBarAppearance.titleTextAttributes = @{NSForegroundColorAttributeName:[WFCUConfigManager globalManager].naviTextColor};
  50. }
  51. [[UITabBar appearance] setBarTintColor:[WFCUConfigManager globalManager].frameBackgroudColor];
  52. [UITabBar appearance].translucent = YES;
  53. }
  54. - (UIColor *)backgroudColor {
  55. if (_backgroudColor) {
  56. return _backgroudColor;
  57. }
  58. BOOL darkModel = NO;
  59. if (@available(iOS 13.0, *)) {
  60. if(UITraitCollection.currentTraitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
  61. darkModel = YES;
  62. }
  63. }
  64. if (darkModel) {
  65. return [UIColor colorWithRed:33/255.f green:33/255.f blue:33/255.f alpha:1.0f];
  66. } else {
  67. if (self.selectedTheme == ThemeType_WFChat) {
  68. return [UIColor colorWithRed:243/255.f green:243/255.f blue:243/255.f alpha:1.0f];
  69. } else if (self.selectedTheme == ThemeType_White) {
  70. return [UIColor colorWithHexString:@"0xededed"];
  71. }
  72. return [UIColor whiteColor];
  73. }
  74. }
  75. - (UIColor *)frameBackgroudColor {
  76. if (_frameBackgroudColor) {
  77. return _frameBackgroudColor;
  78. }
  79. BOOL darkModel = NO;
  80. if (@available(iOS 13.0, *)) {
  81. if(UITraitCollection.currentTraitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
  82. darkModel = YES;
  83. }
  84. }
  85. if (darkModel) {
  86. return [UIColor colorWithRed:39/255.f green:39/255.f blue:39/255.f alpha:1.0f];
  87. } else {
  88. return [UIColor colorWithRed:239/255.f green:239/255.f blue:239/255.f alpha:1.0f];
  89. }
  90. }
  91. - (UIColor *)textColor {
  92. if (_textColor) {
  93. return _textColor;
  94. }
  95. BOOL darkModel = NO;
  96. if (@available(iOS 13.0, *)) {
  97. if(UITraitCollection.currentTraitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
  98. darkModel = YES;
  99. }
  100. }
  101. if (darkModel) {
  102. return [UIColor whiteColor];
  103. } else {
  104. return [UIColor colorWithHexString:@"0x1d1d1d"];
  105. }
  106. }
  107. - (UIColor *)naviBackgroudColor {
  108. if (_naviBackgroudColor) {
  109. return _naviBackgroudColor;
  110. }
  111. BOOL darkModel = NO;
  112. if (@available(iOS 13.0, *)) {
  113. if(UITraitCollection.currentTraitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
  114. darkModel = YES;
  115. }
  116. }
  117. if (darkModel) {
  118. return [UIColor colorWithRed:39/255.f green:39/255.f blue:39/255.f alpha:1.0f];
  119. } else {
  120. if (self.selectedTheme == ThemeType_WFChat) {
  121. return [UIColor colorWithRed:0.1 green:0.27 blue:0.9 alpha:1];
  122. } else if(self.selectedTheme == ThemeType_White) {
  123. return [UIColor colorWithHexString:@"0xededed"];;
  124. }
  125. return [UIColor colorWithRed:239/255.f green:239/255.f blue:239/255.f alpha:1.0f];
  126. }
  127. }
  128. - (UIColor *)naviTextColor {
  129. if (_naviTextColor) {
  130. return _naviTextColor;
  131. }
  132. BOOL darkModel = NO;
  133. if (@available(iOS 13.0, *)) {
  134. if(UITraitCollection.currentTraitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
  135. darkModel = YES;
  136. }
  137. }
  138. if (darkModel) {
  139. return [UIColor whiteColor];
  140. } else {
  141. if (self.selectedTheme == ThemeType_WFChat) {
  142. return [UIColor blackColor];
  143. } else if(self.selectedTheme == ThemeType_White) {
  144. [UIColor colorWithHexString:@"0c0c0c"];
  145. }
  146. return [UIColor blackColor];
  147. }
  148. }
  149. - (UIColor *)separateColor {
  150. if (_separateColor) {
  151. return _separateColor;
  152. }
  153. BOOL darkModel = NO;
  154. if (@available(iOS 13.0, *)) {
  155. if(UITraitCollection.currentTraitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
  156. darkModel = YES;
  157. }
  158. }
  159. if (darkModel) {
  160. return [UIColor colorWithHexString:@"0x3f3f3f"];
  161. } else {
  162. return [UIColor colorWithHexString:@"0xe7e7e7"];
  163. }
  164. }
  165. - (UIColor *)externalNameColor {
  166. if(_externalNameColor) {
  167. return _externalNameColor;
  168. }
  169. return [UIColor colorWithHexString:@"0xF0A040"];
  170. }
  171. //file path document/conversationresource/conv_line/conv_type/conv_target/mediatype/
  172. - (NSString *)cachePathOf:(WFCCConversation *)conversation mediaType:(WFCCMediaType)mediaType {
  173. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
  174. NSUserDomainMask, YES);
  175. NSString *documentDirectory = [paths objectAtIndex:0];
  176. NSString *path = [documentDirectory stringByAppendingPathComponent:self.conversationFilesDir];
  177. path = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"%d/%d/%@", conversation.line, (int)conversation.type, conversation.target]];
  178. NSString *type = @"general";
  179. if(mediaType == Media_Type_IMAGE) type = @"image";
  180. else if(mediaType == Media_Type_VOICE) type = @"voice";
  181. else if(mediaType == Media_Type_VIDEO) type = @"video";
  182. else if(mediaType == Media_Type_PORTRAIT) type = @"portrait";
  183. else if(mediaType == Media_Type_FAVORITE) type = @"favorite";
  184. else if(mediaType == Media_Type_STICKER) type = @"sticker";
  185. else if(mediaType == Media_Type_MOMENTS) type = @"moments";
  186. path = [path stringByAppendingPathComponent:type];
  187. if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
  188. [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
  189. }
  190. return path;
  191. }
  192. @end