CNTopImageView.m
12.5 KB
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
//
// CNTopImageView.m
// AFNetworking
//
// Created by CNLive on 2022/1/17.
//
#import "CNTopImageView.h"
#import <DSBaseModule/DSBaseModule.h>
#import "CNMinePersonInfoController.h"
// 我的公会信息中公会成员类型
#ifndef CNLiveUnionUserStatusWithSourceForKey
#define CNLiveUnionUserStatusWithSourceForKey @"CNLiveUnionUserStatusWithSourceForKey"
#endif
@interface CNTopImageView()
@property (nonatomic, strong) UILabel *titleLabel;//用户名
@property (nonatomic, strong) UIButton *unionBtn;//我的工会
@property (nonatomic, strong) UIButton *homelandBtn;//我的家园
@property (nonatomic, strong) UIButton *myCommuintyBtn;//我的社区
@property (nonatomic, strong) UIButton *myImage;
@property (nonatomic, strong) CNListCollectionView *mineListView;//我的视频、我的收藏、生活圈、付费记录
@end
@implementation CNTopImageView
- (instancetype)init
{
if (self = [super init]) {
[self addSubview:self.codesView];
[self addSubview:self.iconImage];
[self addSubview:self.titleLabel];
NSString *userStatus = [[NSUserDefaults standardUserDefaults] valueForKey:CNLiveUnionUserStatusWithSourceForKey];
if ([userStatus isNotBlank] && ([userStatus isEqualToString:@"3"]||[userStatus isEqualToString:@"2"])) {
[self addSubview:self.unionBtn];
}
[self addSubview:self.myCommuintyBtn];
if (![CNLiveEnvironmentManager manager].isNewHomePage) {
[self addSubview:self.homelandBtn];
}else{
[self addSubview:self.backBtn];
[self addSubview:self.myImage];
}
[self addSubview:self.mineListView];
[self uploadViewLayout];
weakself
[CNMinePresent requestCommunitySucceed:^(BOOL isCommunity) {
weakSelf.myCommuintyBtn.hidden = !isCommunity;
}];
}
return self;
}
- (void)uploadViewLayout
{
[self.iconImage mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self).offset(kStatusHeight+DS_adapt_length(35));
make.left.equalTo(self).offset(DS_adapt_length(12));
make.width.height.mas_equalTo(DS_adapt_length(60));
}];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(DS_adapt_length(82.5));
make.right.equalTo(self).offset(-10);
make.top.mas_equalTo(kStatusHeight+DS_adapt_length(39));
}];
if ([CNLiveEnvironmentManager manager].isNewHomePage) {
[self.codesView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self).offset(kStatusHeight);
make.right.equalTo(self).offset(-DS_adapt_length(10) );
make.height.mas_equalTo(DS_adapt_length(35));
make.width.mas_equalTo(DS_adapt_length(70));
}];
[self.backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(DS_adapt_length(16));
make.centerY.equalTo(self.codesView);
make.width.mas_equalTo(DS_adapt_length(11));
make.height.mas_equalTo(DS_adapt_length(18));
}];
[self.mineListView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.myImage.mas_bottom).offset(DS_adapt_length(15));
make.left.equalTo(self).offset(DS_adapt_length(10));
make.right.equalTo(self).offset(-DS_adapt_length(10));
make.height.mas_equalTo(DS_adapt_length(70));
}];
[self.myImage mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.titleLabel);
make.top.mas_equalTo(kStatusHeight+DS_adapt_length( 35+30));
make.height.mas_equalTo(DS_adapt_length(26));
make.width.mas_equalTo(DS_adapt_length(86.5));
}];
NSString *userStatus = [[NSUserDefaults standardUserDefaults] valueForKey:CNLiveUnionUserStatusWithSourceForKey];
if ([userStatus isNotBlank] && ([userStatus isEqualToString:@"3"]||[userStatus isEqualToString:@"2"])) {
[self.unionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.myImage.mas_right).offset(10);
make.top.equalTo(self.myImage);
make.height.mas_equalTo(DS_adapt_length(26));
make.width.mas_equalTo(DS_adapt_length(86.5));
}];
[self.myCommuintyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.unionBtn.mas_right).offset(10);
make.top.equalTo(self.myImage);
make.height.mas_equalTo(DS_adapt_length(26));
make.width.mas_equalTo(DS_adapt_length(86.5));
}];
}else{
[self.myCommuintyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.myImage.mas_right).offset(10);
make.top.equalTo(self.myImage);
make.height.mas_equalTo(DS_adapt_length(26));
make.width.mas_equalTo(DS_adapt_length(86.5));
}];
}
}else{
[self.codesView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self).offset(kStatusHeight);
make.right.equalTo(self).offset(-DS_adapt_length(10) );
make.height.mas_equalTo(DS_adapt_length(35));
make.width.mas_equalTo(DS_adapt_length(105));
}];
[self.homelandBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.titleLabel);
make.top.mas_equalTo(kStatusHeight+DS_adapt_length( 35+30));
make.height.mas_equalTo(DS_adapt_length(26));
make.width.mas_equalTo(DS_adapt_length(86.5));
}];
NSString *userStatus = [[NSUserDefaults standardUserDefaults] valueForKey:CNLiveUnionUserStatusWithSourceForKey];
if ([userStatus isNotBlank] && ([userStatus isEqualToString:@"3"]||[userStatus isEqualToString:@"2"])) {
[self.unionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.homelandBtn.mas_right).offset(10);
make.top.equalTo(self.homelandBtn);
make.height.mas_equalTo(DS_adapt_length(26));
make.width.mas_equalTo(DS_adapt_length(86.5));
}];
[self.myCommuintyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.unionBtn.mas_right).offset(10);
make.top.equalTo(self.homelandBtn);
make.height.mas_equalTo(DS_adapt_length(26));
make.width.mas_equalTo(DS_adapt_length(86.5));
}];
}else{
[self.myCommuintyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.homelandBtn.mas_right).offset(10);
make.top.equalTo(self.homelandBtn);
make.height.mas_equalTo(DS_adapt_length(26));
make.width.mas_equalTo(DS_adapt_length(86.5));
}];
}
[self.mineListView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.homelandBtn.mas_bottom).offset(DS_adapt_length(15));
make.left.equalTo(self).offset(DS_adapt_length(10));
make.right.equalTo(self).offset(-DS_adapt_length(10));
make.height.mas_equalTo(DS_adapt_length(70));
}];
}
}
- (void)uploadViews
{
_titleLabel.font = UIFontCNMake(17);
[self.iconImage sd_setImageWithURL:[NSURL URLWithString:CNUserShareModel.faceUrl] placeholderImage:[UIImage imageNamed:@"mine_no_Avatar"]];
if (![NSString isEmpty:CNUserShareModel.nickname]) {
[self.titleLabel setText:CNUserShareModel.nickname];
} else {
self.titleLabel.text = @"昵称";
}
}
#pragma mark - Action
- (void)buttonAction:(UIButton *)sender{
switch (sender.tag - 1001) {
case 0:
{
[[CNLiveCMineService shareMineProtocol] pushCMineContentForCMainPlatWithType:18 param:@{} contentVC:[self displayViewController]];
}
break;
case 1:
{
[[CNLiveCMineService shareMineProtocol] pushCMineContentForCMainPlatWithType:19 param:@{} contentVC:[self displayViewController]];
}
break;
case 2:
{
[[CNLiveCMineService shareMineProtocol] pushCMineContentForCMainPlatWithType:20 param:@{} contentVC:[self displayViewController]];
}
break;
case 3:{
[[BaseAppDelegate sharedAppDelegate] popViewController];
}
break;
case 4:{
[[CNLiveCMineService shareMineProtocol] pushCMineContentForCMainPlatWithType:27 param:@{} contentVC:[self displayViewController]];
break;
}
default:
break;
};
}
#pragma mark - Setting&&getting
- (UIImageView *)iconImage
{
if (!_iconImage) {
_iconImage = [[UIImageView alloc] init];
_iconImage.layer.cornerRadius = DS_adapt_length(30);
_iconImage.contentMode = UIViewContentModeScaleAspectFill;
[_iconImage sd_setImageWithURL:[NSURL URLWithString:CNUserShareModel.faceUrl] placeholderImage:[UIImage imageNamed:@"mine_no_Avatar"]];
_iconImage.userInteractionEnabled = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id _Nonnull sender) {
CNMinePersonInfoController *infoVC = [[CNMinePersonInfoController alloc] init];
[[BaseAppDelegate sharedAppDelegate] pushViewController:infoVC withBackTitle:@" "];
}];
[_iconImage addGestureRecognizer:tap];
}
return _iconImage;
}
- (CNListCollectionView *)codesView
{
if (!_codesView) {
_codesView = [[CNListCollectionView alloc] init];
_codesView.backgroundColor = kClearColor;
_codesView.model = [CNMinePresent dataSourceCodesModel:@"0"];
}
return _codesView;
}
- (UIButton *)backBtn
{
if (!_backBtn) {
_backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
_backBtn.tag = 1004;
[_backBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
[_backBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _backBtn;
}
- (UIButton *)homelandBtn
{
if (!_homelandBtn) {
_homelandBtn = [UIButton buttonWithType:UIButtonTypeCustom];
_homelandBtn.tag = 1001;
[_homelandBtn setBackgroundImage:[UIImage imageNamed:@"mine_my_home"] forState:UIControlStateNormal];
[_homelandBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _homelandBtn;
}
- (UIButton *)unionBtn
{
if (!_unionBtn) {
_unionBtn = [UIButton buttonWithType:UIButtonTypeCustom];
_unionBtn.tag = 1002;
[_unionBtn setBackgroundImage:[UIImage imageNamed:@"mine_my_union"] forState:UIControlStateNormal];
[_unionBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _unionBtn;
}
- (UIButton *)myCommuintyBtn
{
if (!_myCommuintyBtn) {
_myCommuintyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
_myCommuintyBtn.exclusiveTouch = YES;
_myCommuintyBtn.tag = 1003;
[_myCommuintyBtn setBackgroundImage:[UIImage imageNamed:@"mine_my_community"] forState:UIControlStateNormal];
[_myCommuintyBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _myCommuintyBtn;
}
- (UIButton *)myImage
{
if (!_myImage) {
_myImage = [UIButton buttonWithType:UIButtonTypeCustom];
_myImage.exclusiveTouch = YES;
_myImage.tag = 1005;
[_myImage setBackgroundImage:[UIImage imageNamed:@"mine_image"] forState:UIControlStateNormal];
[_myImage addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _myImage;
}
- (UILabel *)titleLabel{
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.textColor = kWhiteColor;
_titleLabel.textAlignment = NSTextAlignmentLeft;
_titleLabel.font = UIFontCNMake(17);
if (![NSString isEmpty:CNUserShareModel.nickname]) {
[_titleLabel setText:CNUserShareModel.nickname];
} else {
_titleLabel.text = @"昵称";
}
}
return _titleLabel;
}
- (CNListCollectionView *)mineListView{
if (!_mineListView) {
_mineListView = [[CNListCollectionView alloc] initWithFrame:CGRectZero];
_mineListView.backgroundColor = kClearColor;
_mineListView.model = [CNMinePresent dataSourceMineModel];
}
return _mineListView;
}
@end