|
7 | 7 | // |
8 | 8 |
|
9 | 9 | #import "MeDisplayViewController.h" |
| 10 | +#import "EaseUserHeaderView.h" |
| 11 | +#import "StartImagesManager.h" |
| 12 | +#import "Login.h" |
| 13 | +#import "UsersViewController.h" |
| 14 | +#import "MJPhotoBrowser.h" |
| 15 | +#import <APParallaxHeader/UIScrollView+APParallaxHeader.h> |
| 16 | +#import "XTSegmentControl.h" |
| 17 | +#import "CSHotTopicView.h" |
| 18 | +#import "CSTopicDetailVC.h" |
| 19 | +#import "SVPullToRefresh.h" |
| 20 | +#import "Coding_NetAPIManager.h" |
| 21 | + |
| 22 | + |
| 23 | +@interface MeDisplayViewController () |
| 24 | +@property (strong, nonatomic) UIView *tableHeaderView; |
| 25 | +@property (strong, nonatomic) EaseUserHeaderView *eaV; |
| 26 | +@property (strong, nonatomic) UIView *sectionHeaderView; |
| 27 | + |
| 28 | +@property (strong, nonatomic) User *curUser; |
| 29 | +@property (assign, nonatomic) NSInteger dataIndex; |
| 30 | +@property (strong, nonatomic) NSMutableArray *dataList;//特指「话题列表」的数据 |
| 31 | +@property (assign, nonatomic) BOOL canLoadMore, willLoadMore, isLoading; |
| 32 | +@property (nonatomic, assign) NSInteger curPage; |
| 33 | + |
| 34 | +@end |
10 | 35 |
|
11 | 36 | @implementation MeDisplayViewController |
12 | 37 |
|
| 38 | +- (void)viewDidLoad{ |
| 39 | + _curUser = [Login curLoginUser]; |
| 40 | + _dataIndex = 0; |
| 41 | + _dataList = @[].mutableCopy; |
| 42 | + _canLoadMore = YES; |
| 43 | + _willLoadMore = _isLoading = NO; |
| 44 | + _curPage = 0; |
| 45 | + |
| 46 | + [super viewDidLoad]; |
| 47 | + self.title = @"个人主页"; |
| 48 | + [self.myTableView registerClass:[CSTopicCell class] forCellReuseIdentifier:kCellIdentifier_TopicCell]; |
| 49 | + [self setupHeaderV]; |
| 50 | +} |
| 51 | + |
| 52 | +- (void)setupHeaderV{ |
| 53 | + __weak typeof(self) weakSelf = self; |
| 54 | + if (!_tableHeaderView) { |
| 55 | + _eaV = [EaseUserHeaderView userHeaderViewWithUser:_curUser image:[StartImagesManager shareManager].curImage.image]; |
| 56 | + _eaV.userIconClicked = ^(){ |
| 57 | + [weakSelf userIconClicked]; |
| 58 | + }; |
| 59 | + _eaV.fansCountBtnClicked = ^(){ |
| 60 | + [weakSelf fansCountBtnClicked]; |
| 61 | + }; |
| 62 | + _eaV.followsCountBtnClicked = ^(){ |
| 63 | + [weakSelf followsCountBtnClicked]; |
| 64 | + }; |
| 65 | + _eaV.clipsToBounds = YES; |
| 66 | + _tableHeaderView = [[UIView alloc] initWithFrame:_eaV.bounds]; |
| 67 | + [_tableHeaderView addSubview:_eaV]; |
| 68 | + self.myTableView.tableHeaderView = _tableHeaderView; |
| 69 | + } |
| 70 | + if (!_sectionHeaderView) { |
| 71 | + _sectionHeaderView = [[XTSegmentControl alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, 44.0) Items:@[@"冒泡", @"话题"] selectedBlock:^(NSInteger index) { |
| 72 | + weakSelf.dataIndex = index; |
| 73 | + }]; |
| 74 | + _sectionHeaderView.backgroundColor = kColorTableBG; |
| 75 | + } |
| 76 | + [self.myTableView bringSubviewToFront:self.refreshControl]; |
| 77 | +} |
| 78 | + |
| 79 | +- (void)setDataIndex:(NSInteger)dataIndex{ |
| 80 | + _dataIndex = dataIndex; |
| 81 | + [self.myTableView reloadData]; |
| 82 | + if ((_dataIndex == 0 && self.curTweets.list.count <= 0) || |
| 83 | + (_dataIndex == 1 && _dataList.count <= 0)) { |
| 84 | + [self refresh]; |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +#pragma mark Refresh M |
| 89 | + |
| 90 | +- (void)refresh{ |
| 91 | + if (_dataIndex == 0) { |
| 92 | + [super refresh]; |
| 93 | + }else{ |
| 94 | + if (!_isLoading) { |
| 95 | + [self requestTopicsMore:NO]; |
| 96 | + } |
| 97 | + } |
| 98 | +} |
| 99 | + |
| 100 | +- (void)refreshMore{ |
| 101 | + if (_dataIndex == 0) { |
| 102 | + [super refreshMore]; |
| 103 | + }else{ |
| 104 | + if (!_isLoading && _canLoadMore) { |
| 105 | + [self requestTopicsMore:YES]; |
| 106 | + }else{ |
| 107 | + [self.myTableView.infiniteScrollingView stopAnimating]; |
| 108 | + } |
| 109 | + } |
| 110 | +} |
| 111 | + |
| 112 | +- (void)requestTopicsMore:(BOOL)loadMore{ |
| 113 | + _willLoadMore = loadMore; |
| 114 | + _curPage = _willLoadMore? _curPage + 1: 0; |
| 115 | + if (_dataList.count <= 0) { |
| 116 | + [self.view beginLoading]; |
| 117 | + } |
| 118 | + __weak typeof(self) weakSelf = self; |
| 119 | + [[Coding_NetAPIManager sharedManager] request_JoinedTopicsWithUserGK:_curUser.global_key page:weakSelf.curPage block:^(id data, BOOL hasMoreData, NSError *error) { |
| 120 | + [weakSelf.refreshControl endRefreshing]; |
| 121 | + [weakSelf.view endLoading]; |
| 122 | + [weakSelf.myTableView.infiniteScrollingView stopAnimating]; |
| 123 | + if (data) { |
| 124 | + [weakSelf.dataList addObjectsFromArray:data[@"list"]]; |
| 125 | + [weakSelf.myTableView reloadData]; |
| 126 | + weakSelf.myTableView.showsInfiniteScrolling = hasMoreData; |
| 127 | + } |
| 128 | + [weakSelf.view configBlankPage:EaseBlankPageTypeMyJoinedTopic hasData:weakSelf.dataList.count > 0 hasError:error != nil reloadButtonBlock:^(id sender) { |
| 129 | + [weakSelf refresh]; |
| 130 | + }]; |
| 131 | + |
| 132 | + }]; |
| 133 | +} |
| 134 | + |
| 135 | +#pragma mark headerV |
| 136 | +- (void)fansCountBtnClicked{ |
| 137 | + UsersViewController *vc = [[UsersViewController alloc] init]; |
| 138 | + vc.curUsers = [Users usersWithOwner:_curUser Type:UsersTypeFollowers]; |
| 139 | + [self.navigationController pushViewController:vc animated:YES]; |
| 140 | +} |
| 141 | +- (void)followsCountBtnClicked{ |
| 142 | + UsersViewController *vc = [[UsersViewController alloc] init]; |
| 143 | + vc.curUsers = [Users usersWithOwner:_curUser Type:UsersTypeFriends_Attentive]; |
| 144 | + [self.navigationController pushViewController:vc animated:YES]; |
| 145 | +} |
| 146 | + |
| 147 | +- (void)userIconClicked{ |
| 148 | + // 显示大图 |
| 149 | + MJPhoto *photo = [[MJPhoto alloc] init]; |
| 150 | + photo.url = [_curUser.avatar urlWithCodePath]; |
| 151 | + |
| 152 | + MJPhotoBrowser *browser = [[MJPhotoBrowser alloc] init]; |
| 153 | + browser.currentPhotoIndex = 0; |
| 154 | + browser.photos = [NSArray arrayWithObject:photo]; |
| 155 | + [browser show]; |
| 156 | +} |
| 157 | + |
| 158 | +- (void)scrollViewDidScroll:(UIScrollView *)scrollView{ |
| 159 | + if (scrollView == self.myTableView) { |
| 160 | + CGFloat offsetY = scrollView.contentOffset.y; |
| 161 | + CGFloat originalHeight = [_eaV originalHeight]; |
| 162 | + CGRect eaFrame = CGRectMake(0, MIN(0, offsetY), _eaV.width, MAX(originalHeight, originalHeight - offsetY)); |
| 163 | + _eaV.frame = eaFrame; |
| 164 | + } |
| 165 | +} |
| 166 | + |
| 167 | +#pragma mark TableM |
| 168 | +- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ |
| 169 | + return self.sectionHeaderView; |
| 170 | +} |
| 171 | + |
| 172 | +- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ |
| 173 | + return 44.0; |
| 174 | +} |
| 175 | + |
| 176 | +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ |
| 177 | + if (_dataIndex == 0) { |
| 178 | + return [super tableView:tableView numberOfRowsInSection:section]; |
| 179 | + }else{ |
| 180 | + return _dataList.count; |
| 181 | + } |
| 182 | +} |
| 183 | + |
| 184 | +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ |
| 185 | + if (_dataIndex == 0) { |
| 186 | + return [super tableView:tableView cellForRowAtIndexPath:indexPath]; |
| 187 | + }else{ |
| 188 | + NSDictionary *topic = _dataList[indexPath.row]; |
| 189 | + CSTopicCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_TopicCell forIndexPath:indexPath]; |
| 190 | + [cell updateDisplayByTopic:topic]; |
| 191 | + [tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:kPaddingLeftWidth]; |
| 192 | + return cell; |
| 193 | + } |
| 194 | +} |
| 195 | + |
| 196 | +- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ |
| 197 | + if (_dataIndex == 0) { |
| 198 | + return [super tableView:tableView heightForRowAtIndexPath:indexPath]; |
| 199 | + }else{ |
| 200 | + NSDictionary *topic = _dataList[indexPath.row]; |
| 201 | + return [CSTopicCell cellHeightWithData:topic]; |
| 202 | + } |
| 203 | +} |
| 204 | + |
| 205 | +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ |
| 206 | + if (_dataIndex == 0) { |
| 207 | + [super tableView:tableView didSelectRowAtIndexPath:indexPath]; |
| 208 | + }else{ |
| 209 | + NSDictionary *topic = _dataList[indexPath.row]; |
| 210 | + [self goToTopic:topic]; |
| 211 | + } |
| 212 | +} |
| 213 | + |
| 214 | +#pragma mark goTo |
| 215 | +- (void)goToTopic:(NSDictionary*)topic{ |
| 216 | + CSTopicDetailVC *vc = [[CSTopicDetailVC alloc] init]; |
| 217 | + vc.topicID = [topic[@"id"] intValue]; |
| 218 | + [self.navigationController pushViewController:vc animated:YES]; |
| 219 | +} |
| 220 | + |
13 | 221 | @end |
0 commit comments