Commit 5cc9773c6d0a86e66862d362f0ce9c3874b0b04c
1 parent
73a5aaa681
Exists in
master
and in
1 other branch
Move fill data code from parent table view to child tableview cell
Showing 5 changed files with 41 additions and 63 deletions Inline Diff
LifeLog/LifeLog/GroupDetailViewController.m
| 1 | // | 1 | // |
| 2 | // GroupDetailViewController.m | 2 | // GroupDetailViewController.m |
| 3 | // LifeLog | 3 | // LifeLog |
| 4 | // | 4 | // |
| 5 | // Created by nvtu on 8/13/17. | 5 | // Created by nvtu on 8/13/17. |
| 6 | // Copyright © 2017 PhongNV. All rights reserved. | 6 | // Copyright © 2017 PhongNV. All rights reserved. |
| 7 | // | 7 | // |
| 8 | 8 | ||
| 9 | #import "GroupDetailViewController.h" | 9 | #import "GroupDetailViewController.h" |
| 10 | #import <SDWebImage/UIImageView+WebCache.h> | 10 | #import <SDWebImage/UIImageView+WebCache.h> |
| 11 | 11 | ||
| 12 | #import "Utilities.h" | 12 | #import "Utilities.h" |
| 13 | #import "ServerAPI.h" | 13 | #import "ServerAPI.h" |
| 14 | #import "SNSRecentTopicTableViewCell.h" | 14 | #import "SNSRecentTopicTableViewCell.h" |
| 15 | 15 | ||
| 16 | @interface GroupDetailViewController () | 16 | @interface GroupDetailViewController () |
| 17 | 17 | ||
| 18 | @end | 18 | @end |
| 19 | 19 | ||
| 20 | @implementation GroupDetailViewController | 20 | @implementation GroupDetailViewController |
| 21 | 21 | ||
| 22 | - (void)viewDidLoad { | 22 | - (void)viewDidLoad { |
| 23 | [super viewDidLoad]; | 23 | [super viewDidLoad]; |
| 24 | isMemberList = false; | 24 | isMemberList = false; |
| 25 | //register nib for table view | 25 | //register nib for table view |
| 26 | [self.tableBase registerNib:[UINib nibWithNibName:@"SNSRecentTopicTableViewCell" bundle:nil] forCellReuseIdentifier:@"RecentTopicCell"]; | 26 | [self.tableBase registerNib:[UINib nibWithNibName:@"SNSRecentTopicTableViewCell" bundle:nil] forCellReuseIdentifier:@"RecentTopicCell"]; |
| 27 | if(_curGroup != nil) { | 27 | if(_curGroup != nil) { |
| 28 | [self requestGroupDetail]; | 28 | [self requestGroupDetail]; |
| 29 | } | 29 | } |
| 30 | // Do any additional setup after loading the view from its nib. | 30 | // Do any additional setup after loading the view from its nib. |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | - (void)didReceiveMemoryWarning { | 33 | - (void)didReceiveMemoryWarning { |
| 34 | [super didReceiveMemoryWarning]; | 34 | [super didReceiveMemoryWarning]; |
| 35 | // Dispose of any resources that can be recreated. | 35 | // Dispose of any resources that can be recreated. |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | - (void) setGroup : (GroupObject *) object { | 38 | - (void) setGroup : (GroupObject *) object { |
| 39 | _curGroup = object; | 39 | _curGroup = object; |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | - (void)setupView { | 42 | - (void)setupView { |
| 43 | if(_curGroup != nil) { | 43 | if(_curGroup != nil) { |
| 44 | if(self.imgAva != nil && _curGroup.avatar && ![_curGroup.avatar isKindOfClass:[NSNull class]]) { | 44 | if(self.imgAva != nil && _curGroup.avatar && ![_curGroup.avatar isKindOfClass:[NSNull class]]) { |
| 45 | [self.imgAva sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:_curGroup.avatar]]]; | 45 | [self.imgAva sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:_curGroup.avatar]]]; |
| 46 | } | 46 | } |
| 47 | if(self.lblGrpName != nil) { | 47 | if(self.lblGrpName != nil) { |
| 48 | [self.lblGrpName setText:_curGroup.name]; | 48 | [self.lblGrpName setText:_curGroup.name]; |
| 49 | } | 49 | } |
| 50 | if(self.btJoinGrp != nil) { | 50 | if(self.btJoinGrp != nil) { |
| 51 | [self.btJoinGrp setHidden:false]; | 51 | [self.btJoinGrp setHidden:false]; |
| 52 | } | 52 | } |
| 53 | NSString *mode = @""; | 53 | NSString *mode = @""; |
| 54 | NSString *goalText = [NSString stringWithFormat:@"%@\n", _curGroup.goal]; | 54 | NSString *goalText = [NSString stringWithFormat:@"%@\n", _curGroup.goal]; |
| 55 | if(_curGroup.runMode || _curGroup.walkMode || _curGroup.bikeMode) { | 55 | if(_curGroup.runMode || _curGroup.walkMode || _curGroup.bikeMode) { |
| 56 | goalText = [goalText stringByAppendingString:@"1日 目標 "]; | 56 | goalText = [goalText stringByAppendingString:@"1日 目標 "]; |
| 57 | } | 57 | } |
| 58 | if(_curGroup.runMode) { | 58 | if(_curGroup.runMode) { |
| 59 | mode = [mode stringByAppendingString:NSLocalizedString(@"lifelog.grDetail.mode.running", nil)]; | 59 | mode = [mode stringByAppendingString:NSLocalizedString(@"lifelog.grDetail.mode.running", nil)]; |
| 60 | mode = [mode stringByAppendingString:@"\n"]; | 60 | mode = [mode stringByAppendingString:@"\n"]; |
| 61 | goalText = [goalText stringByAppendingFormat:@"RUN %dm, ", _curGroup.runGoal]; | 61 | goalText = [goalText stringByAppendingFormat:@"RUN %dm, ", _curGroup.runGoal]; |
| 62 | } | 62 | } |
| 63 | if(_curGroup.walkMode) { | 63 | if(_curGroup.walkMode) { |
| 64 | mode = [mode stringByAppendingString:NSLocalizedString(@"lifelog.grDetail.mode.walking", nil)]; | 64 | mode = [mode stringByAppendingString:NSLocalizedString(@"lifelog.grDetail.mode.walking", nil)]; |
| 65 | mode = [mode stringByAppendingString:@"\n"]; | 65 | mode = [mode stringByAppendingString:@"\n"]; |
| 66 | goalText = [goalText stringByAppendingFormat:@"WALK %dm, ", _curGroup.walkGoal]; | 66 | goalText = [goalText stringByAppendingFormat:@"WALK %dm, ", _curGroup.walkGoal]; |
| 67 | } | 67 | } |
| 68 | if(_curGroup.bikeMode) { | 68 | if(_curGroup.bikeMode) { |
| 69 | mode = [mode stringByAppendingString:NSLocalizedString(@"lifelog.grDetail.mode.bike", nil)]; | 69 | mode = [mode stringByAppendingString:NSLocalizedString(@"lifelog.grDetail.mode.bike", nil)]; |
| 70 | mode = [mode stringByAppendingString:@"\n"]; | 70 | mode = [mode stringByAppendingString:@"\n"]; |
| 71 | goalText = [goalText stringByAppendingFormat:@"BIKE %dm, ", _curGroup.bikeGoal]; | 71 | goalText = [goalText stringByAppendingFormat:@"BIKE %dm, ", _curGroup.bikeGoal]; |
| 72 | } | 72 | } |
| 73 | if(_curGroup.stepMode) { | 73 | if(_curGroup.stepMode) { |
| 74 | mode = [mode stringByAppendingString:NSLocalizedString(@"lifelog.grDetail.mode.step", nil)]; | 74 | mode = [mode stringByAppendingString:NSLocalizedString(@"lifelog.grDetail.mode.step", nil)]; |
| 75 | mode = [mode stringByAppendingString:@"\n"]; | 75 | mode = [mode stringByAppendingString:@"\n"]; |
| 76 | } | 76 | } |
| 77 | if(_curGroup.beginMode) { | 77 | if(_curGroup.beginMode) { |
| 78 | mode = [mode stringByAppendingString:NSLocalizedString(@"lifelog.grDetail.mode.begin", nil)]; | 78 | mode = [mode stringByAppendingString:NSLocalizedString(@"lifelog.grDetail.mode.begin", nil)]; |
| 79 | mode = [mode stringByAppendingString:@"\n"]; | 79 | mode = [mode stringByAppendingString:@"\n"]; |
| 80 | } | 80 | } |
| 81 | if(_curGroup.gymMode) { | 81 | if(_curGroup.gymMode) { |
| 82 | mode = [mode stringByAppendingString:NSLocalizedString(@"lifelog.grDetail.mode.gym", nil)]; | 82 | mode = [mode stringByAppendingString:NSLocalizedString(@"lifelog.grDetail.mode.gym", nil)]; |
| 83 | mode = [mode stringByAppendingString:@"\n"]; | 83 | mode = [mode stringByAppendingString:@"\n"]; |
| 84 | } | 84 | } |
| 85 | NSRange range = [mode rangeOfString:@"\n" options:NSBackwardsSearch]; | 85 | NSRange range = [mode rangeOfString:@"\n" options:NSBackwardsSearch]; |
| 86 | if(range.length > 0) { | 86 | if(range.length > 0) { |
| 87 | mode = [mode stringByReplacingOccurrencesOfString:@"\n" withString:@"" options:NSBackwardsSearch range:range]; | 87 | mode = [mode stringByReplacingOccurrencesOfString:@"\n" withString:@"" options:NSBackwardsSearch range:range]; |
| 88 | } | 88 | } |
| 89 | range = [goalText rangeOfString:@", " options:NSBackwardsSearch]; | 89 | range = [goalText rangeOfString:@", " options:NSBackwardsSearch]; |
| 90 | if(range.length > 0) { | 90 | if(range.length > 0) { |
| 91 | goalText = [goalText stringByReplacingOccurrencesOfString:@", " withString:@"" options:NSBackwardsSearch range:range]; | 91 | goalText = [goalText stringByReplacingOccurrencesOfString:@", " withString:@"" options:NSBackwardsSearch range:range]; |
| 92 | } | 92 | } |
| 93 | [self.lbbGrpActiveMode setText:mode]; | 93 | [self.lbbGrpActiveMode setText:mode]; |
| 94 | [self.lblGrpGoal setText:goalText]; | 94 | [self.lblGrpGoal setText:goalText]; |
| 95 | } | 95 | } |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | - (void) requestGroupDetail { | 98 | - (void) requestGroupDetail { |
| 99 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; | 99 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; |
| 100 | MBProgressHUD *hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; | 100 | MBProgressHUD *hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; |
| 101 | [[ServerAPI server] getGroupDetail:token withGroupID:_curGroup.groupID CompletionHandler:^(GroupObject *object, NSError *error) { | 101 | [[ServerAPI server] getGroupDetail:token withGroupID:_curGroup.groupID CompletionHandler:^(GroupObject *object, NSError *error) { |
| 102 | GroupDetailViewController __weak *weakSelf = self; | 102 | GroupDetailViewController __weak *weakSelf = self; |
| 103 | [_curGroup updateDate:object]; | 103 | [_curGroup updateDate:object]; |
| 104 | dispatch_async(dispatch_get_main_queue(), ^{ | 104 | dispatch_async(dispatch_get_main_queue(), ^{ |
| 105 | [hudView hideAnimated:true]; | 105 | [hudView hideAnimated:true]; |
| 106 | [weakSelf setupView]; | 106 | [weakSelf setupView]; |
| 107 | [weakSelf callRequestToUpdateData]; | 107 | [weakSelf callRequestToUpdateData]; |
| 108 | }); | 108 | }); |
| 109 | }]; | 109 | }]; |
| 110 | } | 110 | } |
| 111 | 111 | ||
| 112 | #pragma mark IBAction | 112 | #pragma mark IBAction |
| 113 | 113 | ||
| 114 | - (IBAction)clickBack:(id)sender { | 114 | - (IBAction)clickBack:(id)sender { |
| 115 | [self.navigationController popViewControllerAnimated:true]; | 115 | [self.navigationController popViewControllerAnimated:true]; |
| 116 | } | 116 | } |
| 117 | 117 | ||
| 118 | - (IBAction)clickSwitch:(AutoTransButton *)sender { | 118 | - (IBAction)clickSwitch:(AutoTransButton *)sender { |
| 119 | isMemberList = !isMemberList; | 119 | isMemberList = !isMemberList; |
| 120 | if(isMemberList) { | 120 | if(isMemberList) { |
| 121 | [sender setTitle:NSLocalizedString(@"lifelog.grDetail.bt.viewTweet", nil) forState:UIControlStateNormal]; | 121 | [sender setTitle:NSLocalizedString(@"lifelog.grDetail.bt.viewTweet", nil) forState:UIControlStateNormal]; |
| 122 | } | 122 | } |
| 123 | else { | 123 | else { |
| 124 | [sender setTitle:NSLocalizedString(@"lifelog.grDetail.bt.viewMem", nil) forState:UIControlStateNormal]; | 124 | [sender setTitle:NSLocalizedString(@"lifelog.grDetail.bt.viewMem", nil) forState:UIControlStateNormal]; |
| 125 | } | 125 | } |
| 126 | [sender setUserInteractionEnabled:false]; | 126 | [sender setUserInteractionEnabled:false]; |
| 127 | [self resetData]; | 127 | [self resetData]; |
| 128 | } | 128 | } |
| 129 | 129 | ||
| 130 | - (IBAction)clickJoin:(AutoTransButton *)sender { | 130 | - (IBAction)clickJoin:(AutoTransButton *)sender { |
| 131 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; | 131 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; |
| 132 | MBProgressHUD *hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; | 132 | MBProgressHUD *hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; |
| 133 | [[ServerAPI server] requestJoinGroup:token groupID:_curGroup.groupID CompletionHandler:^(NSError *error){ | 133 | [[ServerAPI server] requestJoinGroup:token groupID:_curGroup.groupID CompletionHandler:^(NSError *error){ |
| 134 | GroupDetailViewController __weak *weakSelf = self; | 134 | GroupDetailViewController __weak *weakSelf = self; |
| 135 | dispatch_async(dispatch_get_main_queue(), ^{ | 135 | dispatch_async(dispatch_get_main_queue(), ^{ |
| 136 | [hudView hideAnimated:true]; | 136 | [hudView hideAnimated:true]; |
| 137 | if(error == nil) { | 137 | if(error == nil) { |
| 138 | _curGroup.isJoin = true; | 138 | _curGroup.isJoin = true; |
| 139 | [weakSelf.btJoinGrp setHidden:_curGroup.isJoin]; | 139 | [weakSelf.btJoinGrp setHidden:_curGroup.isJoin]; |
| 140 | [Utilities showMessage:@"Join successfully" withViewController:weakSelf]; | 140 | [Utilities showMessage:@"Join successfully" withViewController:weakSelf]; |
| 141 | } | 141 | } |
| 142 | }); | 142 | }); |
| 143 | }]; | 143 | }]; |
| 144 | 144 | ||
| 145 | } | 145 | } |
| 146 | 146 | ||
| 147 | 147 | ||
| 148 | 148 | ||
| 149 | #pragma mark UITableView Delegate | 149 | #pragma mark UITableView Delegate |
| 150 | - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | 150 | - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
| 151 | SNSRecentTopicTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"RecentTopicCell"]; | 151 | SNSRecentTopicTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"RecentTopicCell"]; |
| 152 | if(isMemberList) { | 152 | if(isMemberList) { |
| 153 | MemberObject *object = [_curDataList objectAtIndex:indexPath.row]; | 153 | MemberObject *object = [_curDataList objectAtIndex:indexPath.row]; |
| 154 | if(object.avatar && ![object.avatar isKindOfClass:[NSNull class]]) { | 154 | [cell setMemberData:object]; |
| 155 | [cell.imgAvatar sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:object.avatar]]]; | ||
| 156 | } | ||
| 157 | else { | ||
| 158 | [cell.imgAvatar setImage:[UIImage imageNamed:@"avatar_default"]]; | ||
| 159 | } | ||
| 160 | cell.lblUsername.text = @""; | ||
| 161 | cell.lblDateTime.text = @""; | ||
| 162 | cell.lblDes.text = object.userName; | ||
| 163 | cell.lblMode.text = @""; | ||
| 164 | cell.lblDistance.text = @""; | ||
| 165 | cell.lblDuration.text = @""; | ||
| 166 | } | 155 | } |
| 167 | else { | 156 | else { |
| 168 | TweetObject *object = [_curDataList objectAtIndex:indexPath.row]; | 157 | TweetObject *object = [_curDataList objectAtIndex:indexPath.row]; |
| 169 | if(object.avatar && ![object.avatar isKindOfClass:[NSNull class]]) { | 158 | [cell setTweetsData:object]; |
| 170 | [cell.imgAvatar sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:object.avatar]]]; | ||
| 171 | } | ||
| 172 | else { | ||
| 173 | [cell.imgAvatar setImage:[UIImage imageNamed:@"avatar_default"]]; | ||
| 174 | } | ||
| 175 | cell.lblDateTime.text = [Utilities stringFromDate:object.createDate withFormat:@"YYYY/MM/dd hh:mm" locale:@""]; | ||
| 176 | cell.lblUsername.text = object.userName; | ||
| 177 | cell.lblDes.text = object.content; | ||
| 178 | cell.lblMode.text = object.mode; | ||
| 179 | cell.lblDistance.text = [NSString stringWithFormat:@"%.0f m", object.distance]; | ||
| 180 | cell.lblDuration.text = object.time; | ||
| 181 | } | 159 | } |
| 182 | 160 | ||
| 183 | return cell; | 161 | return cell; |
| 184 | } | 162 | } |
| 185 | 163 | ||
| 186 | #pragma mark Private Function | 164 | #pragma mark Private Function |
| 187 | 165 | ||
| 188 | -(void) callRequestToUpdateData { | 166 | -(void) callRequestToUpdateData { |
| 189 | [super callRequestToUpdateData]; | 167 | [super callRequestToUpdateData]; |
| 190 | 168 | ||
| 191 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; | 169 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; |
| 192 | MBProgressHUD *hudView = nil; | 170 | MBProgressHUD *hudView = nil; |
| 193 | if(_curPage == 1 && !self.refreshControl.isRefreshing) { | 171 | if(_curPage == 1 && !self.refreshControl.isRefreshing) { |
| 194 | hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; | 172 | hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; |
| 195 | } | 173 | } |
| 196 | if(isMemberList) { | 174 | if(isMemberList) { |
| 197 | [[ServerAPI server] requestMemberList:token groupID:_curGroup.groupID withPage:_curPage CompletionHandler:^(NSArray *array, NSError *error){ | 175 | [[ServerAPI server] requestMemberList:token groupID:_curGroup.groupID withPage:_curPage CompletionHandler:^(NSArray *array, NSError *error){ |
| 198 | dispatch_async(dispatch_get_main_queue(), ^{ | 176 | dispatch_async(dispatch_get_main_queue(), ^{ |
| 199 | if(hudView != nil) { | 177 | if(hudView != nil) { |
| 200 | [hudView hideAnimated:true]; | 178 | [hudView hideAnimated:true]; |
| 201 | } | 179 | } |
| 202 | }); | 180 | }); |
| 203 | GroupDetailViewController __weak *weakSelf = self; | 181 | GroupDetailViewController __weak *weakSelf = self; |
| 204 | [weakSelf updateTableData:array error:error]; | 182 | [weakSelf updateTableData:array error:error]; |
| 205 | [weakSelf.btSwitch setUserInteractionEnabled:true]; | 183 | [weakSelf.btSwitch setUserInteractionEnabled:true]; |
| 206 | }]; | 184 | }]; |
| 207 | } | 185 | } |
| 208 | else { | 186 | else { |
| 209 | [[ServerAPI server] requestTweetsList:token groupID:_curGroup.groupID withPage:_curPage CompletionHandler:^(NSArray *array, NSError *error){ | 187 | [[ServerAPI server] requestTweetsList:token groupID:_curGroup.groupID withPage:_curPage CompletionHandler:^(NSArray *array, NSError *error){ |
| 210 | dispatch_async(dispatch_get_main_queue(), ^{ | 188 | dispatch_async(dispatch_get_main_queue(), ^{ |
| 211 | if(hudView != nil) { | 189 | if(hudView != nil) { |
| 212 | [hudView hideAnimated:true]; | 190 | [hudView hideAnimated:true]; |
| 213 | } | 191 | } |
| 214 | }); | 192 | }); |
| 215 | GroupDetailViewController __weak *weakSelf = self; | 193 | GroupDetailViewController __weak *weakSelf = self; |
| 216 | [weakSelf updateTableData:array error:error]; | 194 | [weakSelf updateTableData:array error:error]; |
| 217 | [weakSelf.btSwitch setUserInteractionEnabled:true]; | 195 | [weakSelf.btSwitch setUserInteractionEnabled:true]; |
| 218 | }]; | 196 | }]; |
| 219 | } | 197 | } |
| 220 | } | 198 | } |
| 221 | 199 | ||
| 222 | @end | 200 | @end |
| 223 | 201 |
LifeLog/LifeLog/MyGroupViewController.m
| 1 | // | 1 | // |
| 2 | // MyGroupViewController.m | 2 | // MyGroupViewController.m |
| 3 | // LifeLog | 3 | // LifeLog |
| 4 | // | 4 | // |
| 5 | // Created by nvtu on 8/20/17. | 5 | // Created by nvtu on 8/20/17. |
| 6 | // Copyright © 2017 PhongNV. All rights reserved. | 6 | // Copyright © 2017 PhongNV. All rights reserved. |
| 7 | // | 7 | // |
| 8 | 8 | ||
| 9 | #import "MyGroupViewController.h" | 9 | #import "MyGroupViewController.h" |
| 10 | #import <SDWebImage/UIImageView+WebCache.h> | ||
| 11 | 10 | ||
| 12 | #import "Utilities.h" | 11 | #import "Utilities.h" |
| 13 | #import "ServerAPI.h" | 12 | #import "ServerAPI.h" |
| 14 | #import "SNSRecentTopicTableViewCell.h" | 13 | #import "SNSRecentTopicTableViewCell.h" |
| 15 | 14 | ||
| 16 | @interface MyGroupViewController () | 15 | @interface MyGroupViewController () |
| 17 | 16 | ||
| 18 | @end | 17 | @end |
| 19 | 18 | ||
| 20 | @implementation MyGroupViewController | 19 | @implementation MyGroupViewController |
| 21 | 20 | ||
| 22 | - (void)viewDidLoad { | 21 | - (void)viewDidLoad { |
| 23 | [super viewDidLoad]; | 22 | [super viewDidLoad]; |
| 24 | isMemberList = false; | 23 | isMemberList = false; |
| 25 | _curListGrp = [[NSMutableArray alloc] init]; | 24 | _curListGrp = [[NSMutableArray alloc] init]; |
| 26 | [self.tableBase registerNib:[UINib nibWithNibName:@"SNSRecentTopicTableViewCell" bundle:nil] forCellReuseIdentifier:@"RecentTopicCell"]; | 25 | [self.tableBase registerNib:[UINib nibWithNibName:@"SNSRecentTopicTableViewCell" bundle:nil] forCellReuseIdentifier:@"RecentTopicCell"]; |
| 27 | 26 | ||
| 28 | [self requestGroupList]; | 27 | [self requestGroupList]; |
| 29 | // Do any additional setup after loading the view from its nib. | 28 | // Do any additional setup after loading the view from its nib. |
| 30 | } | 29 | } |
| 31 | 30 | ||
| 32 | - (void)didReceiveMemoryWarning { | 31 | - (void)didReceiveMemoryWarning { |
| 33 | [super didReceiveMemoryWarning]; | 32 | [super didReceiveMemoryWarning]; |
| 34 | // Dispose of any resources that can be recreated. | 33 | // Dispose of any resources that can be recreated. |
| 35 | } | 34 | } |
| 36 | 35 | ||
| 37 | #pragma mark IBAction | 36 | #pragma mark IBAction |
| 38 | 37 | ||
| 39 | - (IBAction)clickBack:(id)sender { | 38 | - (IBAction)clickBack:(id)sender { |
| 40 | [self.navigationController popViewControllerAnimated:true]; | 39 | [self.navigationController popViewControllerAnimated:true]; |
| 41 | } | 40 | } |
| 42 | 41 | ||
| 43 | - (IBAction)clickShowGrp:(id)sender { | 42 | - (IBAction)clickShowGrp:(id)sender { |
| 44 | self.tableGrp.hidden = !self.tableGrp.isHidden; | 43 | self.tableGrp.hidden = !self.tableGrp.isHidden; |
| 45 | } | 44 | } |
| 46 | 45 | ||
| 47 | - (IBAction)clickSwitch:(id)sender { | 46 | - (IBAction)clickSwitch:(id)sender { |
| 48 | isMemberList = !isMemberList; | 47 | isMemberList = !isMemberList; |
| 49 | if(isMemberList) { | 48 | if(isMemberList) { |
| 50 | [sender setTitle:NSLocalizedString(@"lifelog.grDetail.bt.viewTweet", nil) forState:UIControlStateNormal]; | 49 | [sender setTitle:NSLocalizedString(@"lifelog.grDetail.bt.viewTweet", nil) forState:UIControlStateNormal]; |
| 51 | } | 50 | } |
| 52 | else { | 51 | else { |
| 53 | [sender setTitle:NSLocalizedString(@"lifelog.grDetail.bt.viewMem", nil) forState:UIControlStateNormal]; | 52 | [sender setTitle:NSLocalizedString(@"lifelog.grDetail.bt.viewMem", nil) forState:UIControlStateNormal]; |
| 54 | } | 53 | } |
| 55 | [sender setUserInteractionEnabled:false]; | 54 | [sender setUserInteractionEnabled:false]; |
| 56 | [self resetData]; | 55 | [self resetData]; |
| 57 | } | 56 | } |
| 58 | 57 | ||
| 59 | #pragma mark UITableView Delegate | 58 | #pragma mark UITableView Delegate |
| 60 | -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { | 59 | -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
| 61 | if(tableView == self.tableGrp) | 60 | if(tableView == self.tableGrp) |
| 62 | return 1; | 61 | return 1; |
| 63 | else | 62 | else |
| 64 | return [super numberOfSectionsInTableView:tableView]; | 63 | return [super numberOfSectionsInTableView:tableView]; |
| 65 | } | 64 | } |
| 66 | 65 | ||
| 67 | - (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { | 66 | - (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
| 68 | if(tableView == self.tableGrp) | 67 | if(tableView == self.tableGrp) |
| 69 | return _curListGrp.count; | 68 | return _curListGrp.count; |
| 70 | else | 69 | else |
| 71 | return [super tableView:tableView numberOfRowsInSection:section]; | 70 | return [super tableView:tableView numberOfRowsInSection:section]; |
| 72 | } | 71 | } |
| 73 | 72 | ||
| 74 | - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | 73 | - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
| 75 | if(tableView == self.tableGrp) { | 74 | if(tableView == self.tableGrp) { |
| 76 | UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"GroupCell"]; | 75 | UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"GroupCell"]; |
| 77 | if(cell == nil) { | 76 | if(cell == nil) { |
| 78 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"GroupCell"]; | 77 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"GroupCell"]; |
| 79 | } | 78 | } |
| 80 | GroupObject *object = [_curListGrp objectAtIndex:indexPath.row]; | 79 | GroupObject *object = [_curListGrp objectAtIndex:indexPath.row]; |
| 81 | cell.textLabel.text = object.name; | 80 | cell.textLabel.text = object.name; |
| 82 | return cell; | 81 | return cell; |
| 83 | } | 82 | } |
| 84 | else { | 83 | else { |
| 85 | SNSRecentTopicTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"RecentTopicCell"]; | 84 | SNSRecentTopicTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"RecentTopicCell"]; |
| 86 | if(isMemberList) { | 85 | if(isMemberList) { |
| 87 | MemberObject *object = [_curDataList objectAtIndex:indexPath.row]; | 86 | MemberObject *object = [_curDataList objectAtIndex:indexPath.row]; |
| 88 | if(object.avatar && ![object.avatar isKindOfClass:[NSNull class]]) { | 87 | [cell setMemberData:object]; |
| 89 | [cell.imgAvatar sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:object.avatar]]]; | ||
| 90 | } | ||
| 91 | else { | ||
| 92 | [cell.imgAvatar setImage:[UIImage imageNamed:@"avatar_default"]]; | ||
| 93 | } | ||
| 94 | cell.lblUsername.text = @""; | ||
| 95 | cell.lblDateTime.text = @""; | ||
| 96 | cell.lblDes.text = object.userName; | ||
| 97 | cell.lblMode.text = @""; | ||
| 98 | cell.lblDistance.text = @""; | ||
| 99 | cell.lblDuration.text = @""; | ||
| 100 | } | 88 | } |
| 101 | else { | 89 | else { |
| 102 | TweetObject *object = [_curDataList objectAtIndex:indexPath.row]; | 90 | TweetObject *object = [_curDataList objectAtIndex:indexPath.row]; |
| 103 | if(object.avatar && ![object.avatar isKindOfClass:[NSNull class]]) { | 91 | [cell setTweetsData:object]; |
| 104 | [cell.imgAvatar sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:object.avatar]]]; | ||
| 105 | } | ||
| 106 | else { | ||
| 107 | [cell.imgAvatar setImage:[UIImage imageNamed:@"avatar_default"]]; | ||
| 108 | } | ||
| 109 | cell.lblDateTime.text = [Utilities stringFromDate:object.createDate withFormat:@"YYYY/MM/dd hh:mm" locale:@""]; | ||
| 110 | cell.lblUsername.text = object.userName; | ||
| 111 | cell.lblDes.text = object.content; | ||
| 112 | cell.lblMode.text = object.mode; | ||
| 113 | cell.lblDistance.text = [NSString stringWithFormat:@"%.0f m", object.distance]; | ||
| 114 | cell.lblDuration.text = object.time; | ||
| 115 | } | 92 | } |
| 116 | return cell; | 93 | return cell; |
| 117 | } | 94 | } |
| 118 | } | 95 | } |
| 119 | 96 | ||
| 120 | - (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { | 97 | - (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { |
| 121 | if(tableView == self.tableGrp) { | 98 | if(tableView == self.tableGrp) { |
| 122 | return; | 99 | return; |
| 123 | } | 100 | } |
| 124 | [super tableView:tableView willDisplayCell:cell forRowAtIndexPath:indexPath]; | 101 | [super tableView:tableView willDisplayCell:cell forRowAtIndexPath:indexPath]; |
| 125 | } | 102 | } |
| 126 | 103 | ||
| 127 | -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { | 104 | -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
| 128 | if(tableView == self.tableGrp) { | 105 | if(tableView == self.tableGrp) { |
| 129 | [tableView setHidden:true]; | 106 | [tableView setHidden:true]; |
| 130 | [self resetGroupData:indexPath.row]; | 107 | [self resetGroupData:indexPath.row]; |
| 131 | } | 108 | } |
| 132 | } | 109 | } |
| 133 | 110 | ||
| 134 | #pragma mark Private Function | 111 | #pragma mark Private Function |
| 135 | 112 | ||
| 136 | - (void) resetGroupData : (int) index { | 113 | - (void) resetGroupData : (int) index { |
| 137 | _curGroup = [_curListGrp objectAtIndex:index]; | 114 | _curGroup = [_curListGrp objectAtIndex:index]; |
| 138 | self.lblGrpName.text = _curGroup.name; | 115 | self.lblGrpName.text = _curGroup.name; |
| 139 | [_curDataList removeAllObjects]; | 116 | [_curDataList removeAllObjects]; |
| 140 | [self.tableBase reloadData]; | 117 | [self.tableBase reloadData]; |
| 141 | [self requestGroupDetail]; | 118 | [self requestGroupDetail]; |
| 142 | } | 119 | } |
| 143 | 120 | ||
| 144 | - (void) requestGroupList { | 121 | - (void) requestGroupList { |
| 145 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; | 122 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; |
| 146 | MBProgressHUD *hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; | 123 | MBProgressHUD *hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; |
| 147 | [[ServerAPI server] requestGroupList:token CompletionHandler:^(NSArray *array, NSError *error) { | 124 | [[ServerAPI server] requestGroupList:token CompletionHandler:^(NSArray *array, NSError *error) { |
| 148 | dispatch_async(dispatch_get_main_queue(), ^{ | 125 | dispatch_async(dispatch_get_main_queue(), ^{ |
| 149 | [hudView hideAnimated:true]; | 126 | [hudView hideAnimated:true]; |
| 150 | }); | 127 | }); |
| 151 | if(error == nil) { | 128 | if(error == nil) { |
| 152 | [_curListGrp removeAllObjects]; | 129 | [_curListGrp removeAllObjects]; |
| 153 | [_curListGrp addObjectsFromArray:array]; | 130 | [_curListGrp addObjectsFromArray:array]; |
| 154 | MyGroupViewController __weak *weakSelf = self; | 131 | MyGroupViewController __weak *weakSelf = self; |
| 155 | dispatch_async(dispatch_get_main_queue(), ^{ | 132 | dispatch_async(dispatch_get_main_queue(), ^{ |
| 156 | [hudView hideAnimated:true]; | 133 | [hudView hideAnimated:true]; |
| 157 | [self.tableGrp reloadData]; | 134 | [self.tableGrp reloadData]; |
| 158 | if(_curListGrp.count > 0) { | 135 | if(_curListGrp.count > 0) { |
| 159 | [weakSelf resetGroupData:0]; | 136 | [weakSelf resetGroupData:0]; |
| 160 | } | 137 | } |
| 161 | else { | 138 | else { |
| 162 | weakSelf.lblGrpName.text = @"No Group"; | 139 | weakSelf.lblGrpName.text = @"No Group"; |
| 163 | } | 140 | } |
| 164 | [weakSelf.btShowGrp setEnabled:(_curListGrp.count > 0)]; | 141 | [weakSelf.btShowGrp setEnabled:(_curListGrp.count > 0)]; |
| 165 | }); | 142 | }); |
| 166 | } | 143 | } |
| 167 | }]; | 144 | }]; |
| 168 | } | 145 | } |
| 169 | 146 | ||
| 170 | @end | 147 | @end |
| 171 | 148 |
LifeLog/LifeLog/SNSRecentTopicTableViewCell.h
| 1 | // | 1 | // |
| 2 | // SNSRecentTopicTableViewCell.h | 2 | // SNSRecentTopicTableViewCell.h |
| 3 | // LifeLog | 3 | // LifeLog |
| 4 | // | 4 | // |
| 5 | // Created by nvtu on 8/10/17. | 5 | // Created by nvtu on 8/10/17. |
| 6 | // Copyright © 2017 PhongNV. All rights reserved. | 6 | // Copyright © 2017 PhongNV. All rights reserved. |
| 7 | // | 7 | // |
| 8 | 8 | ||
| 9 | #import <UIKit/UIKit.h> | 9 | #import <UIKit/UIKit.h> |
| 10 | #import "Entities.h" | ||
| 10 | 11 | ||
| 11 | @interface SNSRecentTopicTableViewCell : UITableViewCell | 12 | @interface SNSRecentTopicTableViewCell : UITableViewCell |
| 12 | 13 | ||
| 13 | @property (weak, nonatomic) IBOutlet UIImageView *imgAvatar; | 14 | @property (weak, nonatomic) IBOutlet UIImageView *imgAvatar; |
| 14 | @property (weak, nonatomic) IBOutlet UILabel *lblDateTime; | 15 | @property (weak, nonatomic) IBOutlet UILabel *lblDateTime; |
| 15 | @property (weak, nonatomic) IBOutlet UILabel *lblUsername; | 16 | @property (weak, nonatomic) IBOutlet UILabel *lblUsername; |
| 16 | @property (weak, nonatomic) IBOutlet UILabel *lblDes; | 17 | @property (weak, nonatomic) IBOutlet UILabel *lblDes; |
| 17 | @property (weak, nonatomic) IBOutlet UILabel *lblMode; | 18 | @property (weak, nonatomic) IBOutlet UILabel *lblMode; |
| 18 | @property (weak, nonatomic) IBOutlet UILabel *lblDistance; | 19 | @property (weak, nonatomic) IBOutlet UILabel *lblDistance; |
| 19 | @property (weak, nonatomic) IBOutlet UILabel *lblDuration; | 20 | @property (weak, nonatomic) IBOutlet UILabel *lblDuration; |
| 20 | 21 | ||
| 22 | -(void) setMemberData : (MemberObject *) object; | ||
| 23 | -(void) setTweetsData : (TweetObject *) object; | ||
| 21 | @end | 24 | @end |
| 22 | 25 |
LifeLog/LifeLog/SNSRecentTopicTableViewCell.m
| 1 | // | 1 | // |
| 2 | // SNSRecentTopicTableViewCell.m | 2 | // SNSRecentTopicTableViewCell.m |
| 3 | // LifeLog | 3 | // LifeLog |
| 4 | // | 4 | // |
| 5 | // Created by nvtu on 8/10/17. | 5 | // Created by nvtu on 8/10/17. |
| 6 | // Copyright © 2017 PhongNV. All rights reserved. | 6 | // Copyright © 2017 PhongNV. All rights reserved. |
| 7 | // | 7 | // |
| 8 | 8 | ||
| 9 | #import "SNSRecentTopicTableViewCell.h" | 9 | #import "SNSRecentTopicTableViewCell.h" |
| 10 | #import <SDWebImage/UIImageView+WebCache.h> | ||
| 10 | 11 | ||
| 12 | #import "Utilities.h" | ||
| 13 | |||
| 11 | @implementation SNSRecentTopicTableViewCell | 14 | @implementation SNSRecentTopicTableViewCell |
| 12 | 15 | ||
| 13 | - (void)awakeFromNib { | 16 | - (void)awakeFromNib { |
| 14 | [super awakeFromNib]; | 17 | [super awakeFromNib]; |
| 15 | // Initialization code | 18 | // Initialization code |
| 16 | } | 19 | } |
| 17 | 20 | ||
| 18 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated { | 21 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated { |
| 19 | [super setSelected:selected animated:animated]; | 22 | [super setSelected:selected animated:animated]; |
| 20 | 23 | ||
| 21 | // Configure the view for the selected state | 24 | // Configure the view for the selected state |
| 25 | } | ||
| 26 | |||
| 27 | -(void) setMemberData : (MemberObject *) object { | ||
| 28 | if(object.avatar && ![object.avatar isKindOfClass:[NSNull class]]) { | ||
| 29 | [self.imgAvatar sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:object.avatar]]]; | ||
| 30 | } | ||
| 31 | else { | ||
| 32 | [self.imgAvatar setImage:[UIImage imageNamed:@"avatar_default"]]; | ||
| 33 | } | ||
| 34 | self.lblUsername.text = @""; | ||
| 35 | self.lblDateTime.text = @""; | ||
| 36 | self.lblDes.text = object.userName; | ||
| 37 | self.lblMode.text = @""; | ||
| 38 | self.lblDistance.text = @""; | ||
| 39 | self.lblDuration.text = @""; | ||
| 40 | } | ||
| 41 | |||
| 42 | -(void) setTweetsData : (TweetObject *) object { | ||
| 43 | if(object.avatar && ![object.avatar isKindOfClass:[NSNull class]]) { | ||
| 44 | [self.imgAvatar sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:object.avatar]]]; | ||
| 45 | } | ||
| 46 | else { | ||
| 47 | [self.imgAvatar setImage:[UIImage imageNamed:@"avatar_default"]]; | ||
| 48 | } | ||
| 49 | self.lblDateTime.text = [Utilities stringFromDate:object.createDate withFormat:@"YYYY/MM/dd hh:mm" locale:@""]; | ||
| 50 | self.lblUsername.text = object.userName; | ||
| 51 | self.lblDes.text = object.content; | ||
| 52 | self.lblMode.text = object.mode; | ||
| 53 | self.lblDistance.text = [NSString stringWithFormat:@"%.0f m", object.distance]; | ||
| 54 | self.lblDuration.text = object.time; | ||
| 22 | } | 55 | } |
| 23 | 56 | ||
| 24 | @end | 57 | @end |
| 25 | 58 |
LifeLog/LifeLog/SNSViewController.m
| 1 | // | 1 | // |
| 2 | // SNSViewController.m | 2 | // SNSViewController.m |
| 3 | // LifeLog | 3 | // LifeLog |
| 4 | // | 4 | // |
| 5 | // Created by Nguyen Van Phong on 7/25/17. | 5 | // Created by Nguyen Van Phong on 7/25/17. |
| 6 | // Copyright © 2017 PhongNV. All rights reserved. | 6 | // Copyright © 2017 PhongNV. All rights reserved. |
| 7 | // | 7 | // |
| 8 | 8 | ||
| 9 | #import "SNSViewController.h" | 9 | #import "SNSViewController.h" |
| 10 | 10 | ||
| 11 | #import <SDWebImage/UIImageView+WebCache.h> | ||
| 12 | |||
| 13 | #import "ServerAPI.h" | 11 | #import "ServerAPI.h" |
| 14 | #import "Utilities.h" | 12 | #import "Utilities.h" |
| 15 | 13 | ||
| 16 | #import "SNSRecentTopicTableViewCell.h" | 14 | #import "SNSRecentTopicTableViewCell.h" |
| 17 | #import "MyGroupViewController.h" | 15 | #import "MyGroupViewController.h" |
| 18 | #import "SearchGroupViewController.h" | 16 | #import "SearchGroupViewController.h" |
| 19 | #import "GroupDetailViewController.h" | 17 | #import "GroupDetailViewController.h" |
| 20 | 18 | ||
| 21 | @interface SNSViewController () | 19 | @interface SNSViewController () |
| 22 | 20 | ||
| 23 | @end | 21 | @end |
| 24 | 22 | ||
| 25 | @implementation SNSViewController | 23 | @implementation SNSViewController |
| 26 | 24 | ||
| 27 | - (void)viewDidLoad { | 25 | - (void)viewDidLoad { |
| 28 | [super viewDidLoad]; | 26 | [super viewDidLoad]; |
| 29 | // Do any additional setup after loading the view from its nib. | 27 | // Do any additional setup after loading the view from its nib. |
| 30 | self.title = NSLocalizedString(@"lifelog.tapbar.sns", nil); | 28 | self.title = NSLocalizedString(@"lifelog.tapbar.sns", nil); |
| 31 | 29 | ||
| 32 | [self callRequestToUpdateData]; | 30 | [self callRequestToUpdateData]; |
| 33 | 31 | ||
| 34 | //register nib for table view | 32 | //register nib for table view |
| 35 | [self.tableBase registerNib:[UINib nibWithNibName:@"SNSRecentTopicTableViewCell" bundle:nil] forCellReuseIdentifier:@"RecentTopicCell"]; | 33 | [self.tableBase registerNib:[UINib nibWithNibName:@"SNSRecentTopicTableViewCell" bundle:nil] forCellReuseIdentifier:@"RecentTopicCell"]; |
| 36 | } | 34 | } |
| 37 | 35 | ||
| 38 | - (void)didReceiveMemoryWarning { | 36 | - (void)didReceiveMemoryWarning { |
| 39 | [super didReceiveMemoryWarning]; | 37 | [super didReceiveMemoryWarning]; |
| 40 | // Dispose of any resources that can be recreated. | 38 | // Dispose of any resources that can be recreated. |
| 41 | } | 39 | } |
| 42 | 40 | ||
| 43 | #pragma mark IBAction | 41 | #pragma mark IBAction |
| 44 | - (IBAction)clickRecommendGroup:(id)sender { | 42 | - (IBAction)clickRecommendGroup:(id)sender { |
| 45 | SearchGroupViewController * search = [[SearchGroupViewController alloc] init]; | 43 | SearchGroupViewController * search = [[SearchGroupViewController alloc] init]; |
| 46 | [self.navigationController pushViewController:search animated:true]; | 44 | [self.navigationController pushViewController:search animated:true]; |
| 47 | } | 45 | } |
| 48 | 46 | ||
| 49 | - (IBAction)clickMyGroup:(id)sender { | 47 | - (IBAction)clickMyGroup:(id)sender { |
| 50 | MyGroupViewController * myGrp = [[MyGroupViewController alloc] init]; | 48 | MyGroupViewController * myGrp = [[MyGroupViewController alloc] init]; |
| 51 | [self.navigationController pushViewController:myGrp animated:true]; | 49 | [self.navigationController pushViewController:myGrp animated:true]; |
| 52 | } | 50 | } |
| 53 | 51 | ||
| 54 | #pragma mark UITableView Delegate | 52 | #pragma mark UITableView Delegate |
| 55 | - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | 53 | - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
| 56 | SNSRecentTopicTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"RecentTopicCell"]; | 54 | SNSRecentTopicTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"RecentTopicCell"]; |
| 57 | TweetObject *object = [_curDataList objectAtIndex:indexPath.row]; | 55 | TweetObject *object = [_curDataList objectAtIndex:indexPath.row]; |
| 58 | if(object.avatar && ![object.avatar isKindOfClass:[NSNull class]]) { | 56 | [cell setTweetsData:object]; |
| 59 | [cell.imgAvatar sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:object.avatar]]]; | ||
| 60 | } | ||
| 61 | else { | ||
| 62 | [cell.imgAvatar setImage:[UIImage imageNamed:@"avatar_default"]]; | ||
| 63 | } | ||
| 64 | cell.lblDateTime.text = [Utilities stringFromDate:object.createDate withFormat:@"YYYY/MM/dd hh:mm" locale:@""]; | ||
| 65 | cell.lblUsername.text = object.userName; | ||
| 66 | cell.lblDes.text = object.content; | ||
| 67 | cell.lblMode.text = object.mode; | ||
| 68 | cell.lblDistance.text = [NSString stringWithFormat:@"%.0f m", object.distance]; | ||
| 69 | cell.lblDuration.text = object.time; | ||
| 70 | return cell; | 57 | return cell; |
| 71 | } | 58 | } |
| 72 | 59 | ||
| 73 | #pragma mark Private Function | 60 | #pragma mark Private Function |
| 74 | 61 | ||
| 75 | -(void) callRequestToUpdateData { | 62 | -(void) callRequestToUpdateData { |
| 76 | [super callRequestToUpdateData]; | 63 | [super callRequestToUpdateData]; |
| 77 | 64 | ||
| 78 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; | 65 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; |
| 79 | MBProgressHUD *hudView = nil; | 66 | MBProgressHUD *hudView = nil; |
| 80 | if(_curPage == 1 && !self.refreshControl.isRefreshing) { | 67 | if(_curPage == 1 && !self.refreshControl.isRefreshing) { |
| 81 | hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; | 68 | hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; |
| 82 | } | 69 | } |
| 83 | [[ServerAPI server] requestTweetsList:token groupID:-1 withPage:_curPage CompletionHandler:^(NSArray *array, NSError *error){ | 70 | [[ServerAPI server] requestTweetsList:token groupID:-1 withPage:_curPage CompletionHandler:^(NSArray *array, NSError *error){ |
| 84 | dispatch_async(dispatch_get_main_queue(), ^{ | 71 | dispatch_async(dispatch_get_main_queue(), ^{ |
| 85 | if(hudView != nil) { | 72 | if(hudView != nil) { |
| 86 | [hudView hideAnimated:true]; | 73 | [hudView hideAnimated:true]; |
| 87 | } | 74 | } |
| 88 | }); | 75 | }); |
| 89 | SNSViewController __weak *weakSelf = self; | 76 | SNSViewController __weak *weakSelf = self; |
| 90 | [weakSelf updateTableData:array error:error]; | 77 | [weakSelf updateTableData:array error:error]; |
| 91 | }]; | 78 | }]; |
| 92 | } | 79 | } |
| 93 | 80 | ||
| 94 | @end | 81 | @end |
| 95 | 82 |