MyGroupViewController.m
4.64 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
//
// MyGroupViewController.m
// LifeLog
//
// Created by nvtu on 8/20/17.
// Copyright © 2017 PhongNV. All rights reserved.
//
#import "MyGroupViewController.h"
#import "Utilities.h"
#import "ServerAPI.h"
#import "SNSRecentTopicTableViewCell.h"
@interface MyGroupViewController ()
@end
@implementation MyGroupViewController
- (void)viewDidLoad {
[super viewDidLoad];
isMemberList = false;
_curListGrp = [[NSMutableArray alloc] init];
[self.tableBase registerNib:[UINib nibWithNibName:@"SNSRecentTopicTableViewCell" bundle:nil] forCellReuseIdentifier:@"RecentTopicCell"];
[self requestGroupList];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark IBAction
- (IBAction)clickBack:(id)sender {
[self.navigationController popViewControllerAnimated:true];
}
- (IBAction)clickShowGrp:(id)sender {
self.tableGrp.hidden = !self.tableGrp.isHidden;
}
- (IBAction)clickSwitch:(id)sender {
isMemberList = !isMemberList;
if(isMemberList) {
[sender setTitle:NSLocalizedString(@"lifelog.grDetail.bt.viewTweet", nil) forState:UIControlStateNormal];
}
else {
[sender setTitle:NSLocalizedString(@"lifelog.grDetail.bt.viewMem", nil) forState:UIControlStateNormal];
}
[sender setUserInteractionEnabled:false];
[self resetData];
}
#pragma mark UITableView Delegate
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
if(tableView == self.tableGrp)
return 1;
else
return [super numberOfSectionsInTableView:tableView];
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if(tableView == self.tableGrp)
return _curListGrp.count;
else
return [super tableView:tableView numberOfRowsInSection:section];
}
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if(tableView == self.tableGrp) {
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"GroupCell"];
if(cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"GroupCell"];
}
GroupObject *object = [_curListGrp objectAtIndex:indexPath.row];
cell.textLabel.text = object.name;
return cell;
}
else {
SNSRecentTopicTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"RecentTopicCell"];
if(isMemberList) {
MemberObject *object = [_curDataList objectAtIndex:indexPath.row];
[cell setMemberData:object];
}
else {
TweetObject *object = [_curDataList objectAtIndex:indexPath.row];
[cell setTweetsData:object];
}
return cell;
}
}
- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if(tableView == self.tableGrp) {
return;
}
[super tableView:tableView willDisplayCell:cell forRowAtIndexPath:indexPath];
}
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(tableView == self.tableGrp) {
[tableView setHidden:true];
[self resetGroupData:indexPath.row];
}
}
#pragma mark Private Function
- (void) resetGroupData : (int) index {
_curGroup = [_curListGrp objectAtIndex:index];
self.lblGrpName.text = _curGroup.name;
[_curDataList removeAllObjects];
[self.tableBase reloadData];
[self requestGroupDetail];
}
- (void) requestGroupList {
NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken];
MBProgressHUD *hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true];
[[ServerAPI server] requestGroupList:token CompletionHandler:^(NSArray *array, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
[hudView hideAnimated:true];
});
if(error == nil) {
[_curListGrp removeAllObjects];
[_curListGrp addObjectsFromArray:array];
MyGroupViewController __weak *weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
[hudView hideAnimated:true];
[self.tableGrp reloadData];
if(_curListGrp.count > 0) {
[weakSelf resetGroupData:0];
}
else {
weakSelf.lblGrpName.text = @"No Group";
}
[weakSelf.btShowGrp setEnabled:(_curListGrp.count > 0)];
});
}
}];
}
@end