IVTMeManageVC.m
8.66 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
//
// IVTMeManageVC.m
// IVTMeLive
//
// Created by XRG on 16/5/13.
// Copyright © 2016年 Joky. All rights reserved.
//
#import "IVTMeManageVC.h"
#import "Masonry.h"
#import "UIColor+IVTMeColor.h"
#import "UIFont+IVTMeFont.h"
#import "IVTMeManageCell.h"
#import "SVProgressHUD.h"
#define userInfoUrl [NSString stringWithFormat:@"%@%@",BaseURL,@"user/requestUserInfo.json"]
@interface IVTMeManageVC ()<UITableViewDataSource,UITableViewDelegate,XMPPManagerDelegate>
@property (nonatomic, retain) UITableView *hintTable;
@property (nonatomic, retain) NSMutableArray *dataArray;
@end
@implementation IVTMeManageVC
- (void)viewDidLoad {
[super viewDidLoad];
_dataArray = [[NSMutableArray alloc] initWithCapacity:10];
self.view.backgroundColor = [UIColor IVTBackgroundColor];
[self initNav];
[self buildHintTable];
[XMPPManager sharedInstance].delegate = self;
[[XMPPManager sharedInstance] getManagersList];
}
-(void)initNav{
//整体背景nav view
UIView* navBgView = [[UIView alloc] init];
[self.view addSubview:navBgView];
navBgView.backgroundColor = [UIColor IVTLightRedColor];
__unsafe_unretained typeof (self) wself = self;
[navBgView mas_makeConstraints:^(MASConstraintMaker* make) {
make.left.equalTo(wself.view.mas_left);
make.right.equalTo(wself.view.mas_right);
make.top.equalTo(@0);
make.height.equalTo(@58);
}];
UILabel *setting = [[UILabel alloc]init];
[navBgView addSubview:setting];
setting.text = @"管理员列表";
setting.textColor = [UIColor YXColorWithHexCode:@"#FFFFFF"];
setting.font = [UIFont YXFontOfSize:19];
setting.textAlignment = NSTextAlignmentCenter;
[setting mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(navBgView.mas_centerX);
make.top.equalTo(wself.view.mas_top).with.offset(29);
make.size.mas_equalTo(CGSizeMake(100.0f, 19.0f));
}];
//背景nav 返回上级页面按钮
UIButton* backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[navBgView addSubview:backButton];
UIImage* navImage = [UIImage imageNamed:@"返回按钮点击"];
[backButton mas_makeConstraints:^(MASConstraintMaker* make) {
make.left.equalTo(wself.view);
make.top.equalTo(wself.view.mas_top).with.offset(18);
make.size.mas_equalTo(CGSizeMake(40, 40));
}];
[backButton setImage:navImage forState:UIControlStateNormal];
backButton.imageEdgeInsets = UIEdgeInsetsMake(5,5,5,5);
[backButton addTarget:self action:@selector(backToTopPage:) forControlEvents:UIControlEventTouchUpInside];
}
- (void)buildHintTable
{
if (_hintTable==nil) {
self.hintTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 58, kScreenWidth, kScreenHeight-58) style:UITableViewStyleGrouped];
_hintTable.backgroundColor = [UIColor IVTBackgroundColor];
_hintTable.delegate = self;
_hintTable.dataSource = self;
_hintTable.showsHorizontalScrollIndicator = NO;
_hintTable.showsVerticalScrollIndicator = NO;
_hintTable.separatorStyle = UITableViewCellSeparatorStyleNone;
// _hintTable.sectionHeaderHeight = 20;
[self.view addSubview:_hintTable];
}
}
- (void)didGetModeratorsList:(NSArray *)list{
for (NSInteger i=0; i<list.count; i++) {
DDXMLElement *element = [list objectAtIndex:i];
DDXMLNode *node = [element attributeForName:@"jid"];
NSString *currentJid = node.stringValue;
NSRange range = [currentJid rangeOfString:@"@"];
NSString *currentUserId = [currentJid substringToIndex:range.location];
[_dataArray addObject:[NSDictionary dictionaryWithObject:currentUserId forKey:@"userID"]];
[self getUserInfoForUserInCurrentRoom:currentUserId];
}
}
- (void)didNotGetModeratorsList{
}
- (void)getUserInfoForUserInCurrentRoom:(NSString *)userId{
NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
NSDictionary *dicInfo = [[NSBundle mainBundle] infoDictionary];
[dict setObject:userId forKey:@"userid"];
[dict setObject:[IVTAccountTool getUserName] forKey:@"username"];
[dict setObject:[IVTAccountTool getPassword] forKey:@"captcha"];
// [dict setObject:[IVTAccountTool get] forKey:@"deviceID"];
[dict setObject:[[UIDevice currentDevice] model] forKey:@"model"];
[dict setObject:[[UIDevice currentDevice] identifierForVendor] forKey:@"deviceID"];
[dict setObject:[NSString stringWithFormat:@"%f",kScreenWidth] forKey:@"width"];
[dict setObject:[NSString stringWithFormat:@"%f",kScreenHeight] forKey:@"heigth"];
[dict setObject:[dicInfo objectForKey:@"CFBundleShortVersionString"] forKey:@"appversion"];
[dict setObject:@"apple" forKey:@"brand"];
[dict setObject:@"" forKey:@"msisdn"];
[dict setObject:@"" forKey:@"otherinfo"];
[dict setObject:@"iOS" forKey:@"platform"];
[[IVTNetworkAPIClient sharedClient] getUserInfoForUserId:userId success:^(NSDictionary *successData) {
NSDictionary *userInfo = [successData objectForKey:@"data"];
for (NSInteger i=0; i<_dataArray.count; i++) {
if ([[[_dataArray objectAtIndex:i] valueForKey:@"userID"] integerValue] == [[userInfo valueForKey:@"id"] integerValue]) {
NSMutableDictionary *dict = [[_dataArray objectAtIndex:i] mutableCopy];
[dict addEntriesFromDictionary:userInfo];
[_dataArray replaceObjectAtIndex:i withObject:[dict copy]];
}
}
dispatch_async(dispatch_get_main_queue(), ^{
[self.hintTable reloadData];
});
} error:^(ErrorCode errorCode) {
} failure:^(NSError *failureError) {
}];
}
#pragma mark - table datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [_dataArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
IVTMeManageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"blackListCell"];
if (!cell) {
cell = [[IVTMeManageCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"blackListCell"];
cell.backgroundColor =[UIColor IVTTitleColor];
[cell addSubview:[self addLineView]];
}
cell.entity = [_dataArray objectAtIndex:indexPath.row];
return cell;
}
#pragma mark - table delegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 59;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
if (editingStyle == UITableViewCellEditingStyleDelete) {
[[XMPPManager sharedInstance] setManagerForUserId:[_dataArray objectAtIndex:indexPath.row][@"id"] block:^(BOOL isSuccess) {
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[_dataArray removeObjectAtIndex:indexPath.row];
if (self.delegate && [self.delegate respondsToSelector:@selector(cancelAdmin:)]) {
[self.delegate cancelAdmin:[_dataArray objectAtIndex:indexPath.row]];
}
}];
}
}
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{
return @"取消管理";
}
//- ( CGFloat )tableView:( UITableView *)tableView heightForHeaderInSection:( NSInteger )section
//
//{
//
// return 30.0 ;
//
//}
//-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(nonnull NSIndexPath *)indexPath
//{
// if (editingStyle == UITableViewCellEditingStyleDelete) {
// [_dataArray removeObjectAtIndex:indexPath.row];
// [_hintTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
//
// }
//}
// 设置标题
//- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
//{
//
// self.title = @"当前管理员:(2/5)";
// return self.title;
//}
- (UIView*)addLineView
{
UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 59.0-0.5, kScreenWidth, 0.5)];
line.backgroundColor = [UIColor IVTSeparatorColor];
return line;
}
//返回按钮点击
-(void)backToTopPage:(id)sender{
[self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end