IVTMeManagerViewController.m
8.33 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
//
// IVTMeManagerViewController.m
// IVTMeLiveTwo
//
// Created by xrg on 16/9/8.
// Copyright © 2016年 QLQ. All rights reserved.
//
#import "IVTMeManagerViewController.h"
#import "Masonry.h"
#import "UIColor+IVTMeColor.h"
#import "UIFont+IVTMeFont.h"
#import "IVTMeManageCell.h"
#import "SVProgressHUD.h"
@interface IVTMeManagerViewController ()<UITableViewDataSource,UITableViewDelegate,XMPPManagerDelegate>
@property (nonatomic, retain) UITableView *hintTable;
@property (nonatomic, retain) NSMutableArray *dataArray;
@end
@implementation IVTMeManagerViewController
- (void)viewDidLoad {
[super viewDidLoad];
_dataArray = [[NSMutableArray alloc] initWithCapacity:10];
self.view.backgroundColor = [UIColor IVTBackgroundColor];
// [self setNavigationBar];
[self buildHintTable];
[XMPPManager sharedInstance].delegate = self;
[[XMPPManager sharedInstance] getManagersList];
// Do any additional setup after loading the view.
}
//- (void)setNavigationBar{
// self.navigationItem.title = @"昵称";
// UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc]initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(backToTopPage:)];
// rightBarButton.tintColor = [UIColor whiteColor];
// self.navigationItem.rightBarButtonItem = rightBarButton;
//}
- (void)buildHintTable
{
if (_hintTable==nil) {
self.hintTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 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)didGetManagersList:(NSArray *)list
{
if (_dataArray.count > 4) {
[SVProgressHUD setMinimumDismissTimeInterval:2];
[SVProgressHUD showSuccessWithStatus:@"管理员人数已达到上线"];
}else{
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];
if (![currentUserId isEqualToString:[IVTAccountTool getUserId]]) {
[_dataArray addObject:[NSDictionary dictionaryWithObject:currentUserId forKey:@"userID"]];
[self getUserInfoForUserInCurrentRoom:currentUserId];
}
}
}
}
- (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:[[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:^(NSDictionary *successData) {
} 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
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 59;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
if (editingStyle == UITableViewCellEditingStyleDelete) {
if (self.delegate && [self.delegate respondsToSelector:@selector(canncelAsAdministrator:)]) {
[self.delegate canncelAsAdministrator:[_dataArray objectAtIndex:indexPath.row]];
}
[_dataArray removeObjectAtIndex:indexPath.row];
[_hintTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
dispatch_async(dispatch_get_main_queue(), ^{
self.title = [NSString stringWithFormat:@"当前管理员:(%ld / 5)",_dataArray.count];
});
[self.hintTable reloadData];
}
}
- (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 = [NSString stringWithFormat:@"当前管理员:(%ld / 5)",_dataArray.count];
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