forked from coding/Coding-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMeDisplayViewController.m
More file actions
298 lines (258 loc) · 10 KB
/
MeDisplayViewController.m
File metadata and controls
298 lines (258 loc) · 10 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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
//
// MeDisplayViewController.m
// Coding_iOS
//
// Created by Ease on 2016/9/9.
// Copyright © 2016年 Coding. All rights reserved.
//
#import "MeDisplayViewController.h"
#import "EaseUserHeaderView.h"
#import "StartImagesManager.h"
#import "Login.h"
#import "UsersViewController.h"
#import "MJPhotoBrowser.h"
#import <APParallaxHeader/UIScrollView+APParallaxHeader.h>
#import "XTSegmentControl.h"
#import "CSHotTopicView.h"
#import "CSTopicDetailVC.h"
#import "SVPullToRefresh.h"
#import "Coding_NetAPIManager.h"
#import "SettingMineInfoViewController.h"
#import "EaseUserInfoCell.h"
#import "UserActiveGraphCell.h"
@interface MeDisplayViewController ()
@property (strong, nonatomic) EaseUserHeaderView *eaV;
@property (strong, nonatomic) UIView *sectionHeaderView;
@property (strong, nonatomic) User *curUser;
@property (assign, nonatomic) NSInteger dataIndex;
@property (strong, nonatomic) NSMutableArray *dataList;//特指「话题列表」的数据
@property (assign, nonatomic) BOOL canLoadMore, willLoadMore, isLoading;
@property (nonatomic, assign) NSInteger curPage;
@property (nonatomic, strong) EaseUserInfoCell *userInfoCell;
@property (nonatomic, strong) ActivenessModel *activenessModel;
@end
@implementation MeDisplayViewController
- (void)viewDidLoad{
_dataIndex = 0;
_dataList = @[].mutableCopy;
_canLoadMore = YES;
_willLoadMore = _isLoading = NO;
_curPage = 0;
[super viewDidLoad];
self.title = @"个人主页";
[self.myTableView registerClass:[CSTopicCell class] forCellReuseIdentifier:kCellIdentifier_TopicCell];
[self.myTableView registerClass:[UserActiveGraphCell class] forCellReuseIdentifier:kCellIdentifier_UserActiveGraphCell];
[self setupHeaderV];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
_curUser = [Login curLoginUser];
[self.myTableView reloadData];
}
- (void)setupHeaderV{
__weak typeof(self) weakSelf = self;
_userInfoCell = [[EaseUserInfoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellIdentifier_EaseUserInfoCell];
_userInfoCell.userIconClicked = ^(){
[weakSelf userIconClicked]; //用户头像点击
};
_userInfoCell.fansCountBtnClicked = ^(){
[weakSelf fansCountBtnClicked]; //粉丝
};
_userInfoCell.followsCountBtnClicked = ^(){
[weakSelf followsCountBtnClicked]; //关注
};
_userInfoCell.editButtonClicked = ^(){
[weakSelf goToSettingInfo]; //编辑
};
[[Coding_NetAPIManager sharedManager] request_Users_activenessWithGlobalKey:_curUser.global_key andBlock:^(ActivenessModel *data, NSError *error) {
weakSelf.activenessModel = data;
[weakSelf.myTableView reloadData];
}];
if (!_sectionHeaderView) {
_sectionHeaderView = [[XTSegmentControl alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, 44.0) Items:@[@"冒泡", @"话题"] selectedBlock:^(NSInteger index) {
weakSelf.dataIndex = index;
}];
_sectionHeaderView.backgroundColor = kColorTableBG;
}
[self.myTableView bringSubviewToFront:self.refreshControl];
}
- (void)setDataIndex:(NSInteger)dataIndex{
_dataIndex = dataIndex;
[self.myTableView reloadData];
if ((_dataIndex == 0 && self.curTweets.list.count <= 0) ||
(_dataIndex == 1 && _dataList.count <= 0)) {
[self refresh];
}
}
#pragma mark Refresh M
- (void)refresh{
if (_dataIndex == 0) {
_curUser = [Login curLoginUser];
[self.myTableView reloadData];
__weak typeof(self) weakSelf = self;
[[Coding_NetAPIManager sharedManager] request_Users_activenessWithGlobalKey:_curUser.global_key andBlock:^(ActivenessModel *data, NSError *error) {
weakSelf.activenessModel = data;
[weakSelf.myTableView reloadData];
}];
[super refresh];
}else{
if (!_isLoading) {
[self requestTopicsMore:NO];
}
}
}
- (void)refreshMore{
if (_dataIndex == 0) {
[super refreshMore];
}else{
if (!_isLoading && _canLoadMore) {
[self requestTopicsMore:YES];
}else{
[self.myTableView.infiniteScrollingView stopAnimating];
}
}
}
- (void)requestTopicsMore:(BOOL)loadMore{
_willLoadMore = loadMore;
_curPage = _willLoadMore? _curPage + 1: 0;
__weak typeof(self) weakSelf = self;
[[Coding_NetAPIManager sharedManager] request_JoinedTopicsWithUserGK:_curUser.global_key page:weakSelf.curPage block:^(id data, BOOL hasMoreData, NSError *error) {
[weakSelf.refreshControl endRefreshing];
[weakSelf.view endLoading];
[weakSelf.myTableView.infiniteScrollingView stopAnimating];
if (data) {
if (weakSelf.willLoadMore) {
[weakSelf.dataList addObjectsFromArray:data[@"list"]];
}else{
weakSelf.dataList = data[@"list"]? [data[@"list"] mutableCopy]: @[].mutableCopy;
}
[weakSelf.myTableView reloadData];
weakSelf.myTableView.showsInfiniteScrolling = hasMoreData;
}
CGFloat offsetY = _userInfoCell.frame.size.height + [UserActiveGraphCell cellHeight] + 80;
[weakSelf.view configBlankPage:EaseBlankPageTypeMyJoinedTopic hasData:weakSelf.dataList.count > 0 hasError:error != nil offsetY:offsetY reloadButtonBlock:^(id sender) {
[weakSelf refresh];
}];
}];
}
#pragma mark headerV
- (void)fansCountBtnClicked{
UsersViewController *vc = [[UsersViewController alloc] init];
vc.curUsers = [Users usersWithOwner:_curUser Type:UsersTypeFollowers];
[self.navigationController pushViewController:vc animated:YES];
}
- (void)followsCountBtnClicked{
UsersViewController *vc = [[UsersViewController alloc] init];
vc.curUsers = [Users usersWithOwner:_curUser Type:UsersTypeFriends_Attentive];
[self.navigationController pushViewController:vc animated:YES];
}
- (void)userIconClicked{
// 显示大图
MJPhoto *photo = [[MJPhoto alloc] init];
photo.url = [_curUser.avatar urlWithCodePath];
MJPhotoBrowser *browser = [[MJPhotoBrowser alloc] init];
browser.currentPhotoIndex = 0;
browser.photos = [NSArray arrayWithObject:photo];
[browser show];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
if (scrollView == self.myTableView) {
CGFloat offsetY = scrollView.contentOffset.y;
CGFloat originalHeight = [_eaV originalHeight];
CGRect eaFrame = CGRectMake(0, MIN(0, offsetY), _eaV.width, MAX(originalHeight, originalHeight - offsetY));
_eaV.frame = eaFrame;
}
}
#pragma mark TableM
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 3;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
if (section < 2) {
return 0.0;
}
return 44.0;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
if (section < 2) {
return [UIView new];
}
return self.sectionHeaderView;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
if (section < 2) {
return 20;
}else{
if (_dataIndex == 0) {
return 0;
}else{
return _dataList.count == 0? self.view.height - self.sectionHeaderView.height: 0;
}
}
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
return [UIView new];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (section < 2) {
return 1;
}
if (_dataIndex == 0) {
return [super tableView:tableView numberOfRowsInSection:section];
}else{
return _dataList.count;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section == 0) {
EaseUserInfoCell *cell = self.userInfoCell;
cell.user = _curUser;
return cell;
} else if (indexPath.section == 1) {
UserActiveGraphCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_UserActiveGraphCell forIndexPath:indexPath];
cell.activenessModel = _activenessModel;
return cell;
} else if (_dataIndex == 0) {
return [super tableView:tableView cellForRowAtIndexPath:indexPath];
} else{
NSDictionary *topic = _dataList[indexPath.row];
CSTopicCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_TopicCell forIndexPath:indexPath];
[cell updateDisplayByTopic:topic];
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:kPaddingLeftWidth];
return cell;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section == 0) {
return [tableView cellHeightForIndexPath:indexPath model:_curUser keyPath:@"user" cellClass:[EaseUserInfoCell class] contentViewWidth:kScreen_Width];
} else if (indexPath.section == 1) {
return [UserActiveGraphCell cellHeight];
} else if (_dataIndex == 0) {
return [super tableView:tableView heightForRowAtIndexPath:indexPath];
}else{
NSDictionary *topic = _dataList[indexPath.row];
return [CSTopicCell cellHeightWithData:topic];
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section < 2) {
return;
}
if (_dataIndex == 0) {
[super tableView:tableView didSelectRowAtIndexPath:indexPath];
}else{
NSDictionary *topic = _dataList[indexPath.row];
[self goToTopic:topic];
}
}
#pragma mark goTo
- (void)goToTopic:(NSDictionary*)topic{
CSTopicDetailVC *vc = [[CSTopicDetailVC alloc] init];
vc.topicID = [topic[@"id"] intValue];
[self.navigationController pushViewController:vc animated:YES];
}
- (void)goToSettingInfo{
SettingMineInfoViewController *vc = [[SettingMineInfoViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
}
@end