JLChen
2021-04-30 a5247b61d585627a1a7b1e1f35f34de9f0af9fba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
//
//  Copyright © 2017年 Zhejiang Dahua Technology Co.,Ltd. All rights reserved.
//
#import "DHModuleConfig.h"
#import "UIColor+LeChange.h"
#import "UIColor+HexString.h"
 
int g_configDistributionVersion = -1;
 
@interface DHModuleConfig()
@end
 
@implementation DHModuleConfig
 
+ (instancetype)shareInstance
{
    static dispatch_once_t onceToken;
    static DHModuleConfig *instance = nil;
    dispatch_once(&onceToken, ^{
        instance = [[DHModuleConfig alloc] init];
    });
    
    return instance;
}
 
- (instancetype)init
{
    if (self = [super init]) {
        [self loadConfigPlist];
    }
    
    return self;
}
 
- (void)loadConfigPlist
{
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"DHModuleConfig" ofType:@"plist"];
    NSDictionary *dic = [NSDictionary dictionaryWithContentsOfFile:filePath];
    _dicConfigs = [[NSMutableDictionary alloc] initWithDictionary:dic];
}
 
 
- (NSDictionary *)shareSheetType
{
    NSDictionary *dicConfig = [_dicConfigs objectForKey:@"ShareSheetType"];
    return [self generateDictionaryContainColor:dicConfig];
}
 
- (BOOL)isDistributionVersion
{
    if (g_configDistributionVersion == -1) {
         NSDictionary *bundleDic = [[NSBundle mainBundle] infoDictionary];
        BOOL bDistributionVersion = [bundleDic[@"LCDistributionVersion"] boolValue];
        g_configDistributionVersion = bDistributionVersion ? 1 : 0;
    }
    
    return g_configDistributionVersion == 1;
}
 
- (BOOL)isShareEnable {
 
    
    return ![self isGeneralVersion];
}
 
- (BOOL)isLeChange {
    NSInteger index = [[NSUserDefaults standardUserDefaults] integerForKey:@"GLOBAL_JOINT_CURRENT_MODE"];
    return index == 0;
}
 
- (BOOL)isShowAllRecord {
    id value = [_dicConfigs valueForKey:@"isShowAllRecord"];
    return [value boolValue];
}
 
- (BOOL)isShowCollectionMaskView {
    NSDictionary *maskView = [_dicConfigs valueForKey:@"MaskView"];
    id value = [maskView valueForKey:@"isShowCollection"];
    
    return [value boolValue];
}
 
- (BOOL)isShowAllRecordMaskView {
    NSDictionary *maskView = [_dicConfigs valueForKey:@"MaskView"];
    id value = [maskView valueForKey:@"isShowAllRecord"];
    
    return [value boolValue];
}
 
- (BOOL)isShowMoveAreaMaskView {
    NSDictionary *maskView = [_dicConfigs valueForKey:@"MaskView"];
    id value = [maskView valueForKey:@"isShowMoveArea"];
    
    return [value boolValue];
}
 
- (BOOL)isShowLinkAgeMaskView {
    NSDictionary *maskView = [_dicConfigs valueForKey:@"MaskView"];
    id value = [maskView valueForKey:@"isShowLinkage"];
    
    return [value boolValue];
}
 
- (BOOL)isShowWeatherMaskView {
    NSDictionary *maskView = [_dicConfigs valueForKey:@"MaskView"];
    id value = [maskView valueForKey:@"isShowWeather"];
    
    return [value boolValue];
}
 
- (BOOL)isShowDialogMaskView {
    NSDictionary *maskView = [_dicConfigs valueForKey:@"MaskView"];
    id value = [maskView valueForKey:@"isShowDialog"];
    
    return [value boolValue];
}
 
- (NSInteger)ptzPanelStyle {
    id value = [_dicConfigs valueForKey:@"PTZPanelStyle"];
    return [value integerValue];
}
 
- (UIColor *)playOperateBgColor {
    return [self private_colorWithKey:@"PlayOperateBgColor"];
}
 
- (UIColor *)liveMonitorDateBarColor {
    return [self private_colorWithKey:@"LiveMonitorDateBarColor"];
}
 
- (UIColor *)navigationTextColor
{
    return [self private_colorWithKey:@"NavigationTextColor"];
}
 
- (UIColor *)navigationBarColor
{
    return [self private_colorWithKey:@"NavigationBarColor"];
}
 
 
- (UIColor *)themeColor {
    return [self private_colorWithKey:@"ThemeColor"];
}
 
- (UIColor *)buyCloudTipColor {
    return [self private_colorWithKey:@"BuyCloudTipColor"];
}
 
- (UIColor *)zoomFocusProgressBarColor {
    return [self private_colorWithKey:@"ZoomFocusProgressBarColor"];
}
 
- (UIColor *)confirmButtonColor {
    return [self private_colorWithKey:@"ConfirmButtonColor"];
}
 
- (UIColor *)themeSecondColor {
    return [self private_colorWithKey:@"ThemeSecondColor"];
}
 
- (NSDictionary *)commonButtonConfig
{
    NSDictionary *dicConfig = [_dicConfigs objectForKey:@"CommonButtonConfig"];
    return [self generateDictionaryContainColor:dicConfig];
}
 
- (NSDictionary *)generateDictionaryContainColor:(NSDictionary *)dicOrigin
{
    NSMutableDictionary *dicResult = [NSMutableDictionary dictionaryWithCapacity:2];
    
    for (NSString *key in dicOrigin.allKeys) {
        UIColor *color = [self private_colorWithKey:key value:dicOrigin[key]];
        
        if (color) {
            [dicResult setObject:color forKey:key];
        } else {
            [dicResult setObject:dicOrigin[key] forKey:key];
        }
    }
    return dicResult;
}
 
 
 
#pragma mark - Prvivate
- (UIColor *)private_colorWithKey:(NSString *)key value:(id)value
{
    UIColor *color;
    NSString *uppercaseString = [key uppercaseString];
    
    //将带有Color的转换成Color
    if ([uppercaseString containsString:@"COLOR"] && [value isKindOfClass:[NSString class]]) {
        color = [UIColor lc_colorWithHexString:(NSString *)value];
        
        //兼容颜色转换错误
        if (color == nil) {
            color = [UIColor dhcolor_c43];
        }
    }
    
    return color;
}
 
- (UIColor *)private_colorWithKey:(NSString *)key
{
    NSDictionary *colors = [_dicConfigs valueForKey:@"Color"];
    NSString *colorString = [colors valueForKey:key];
    
    return [UIColor lc_colorWithHexString:colorString];
}
 
//MARK: - Extension
- (CGFloat)commonButtonCornerRadius
{
    NSNumber *radius = [self commonButtonConfig][@"cornerRadius"];
    return radius ? radius.floatValue : 5;
}
 
- (UIColor *)commonButtonColor
{
    UIColor *color = [self commonButtonConfig][@"backgroundColor"];
    return color ? : [UIColor dhcolor_c1];
}
 
- (NSString *)serviceCall
{
    //SMB Todo::
    return @"0123456789";
}
 
@end