Skip to content

Commit 6bfadbc

Browse files
committed
个人主页
1 parent 7fc9214 commit 6bfadbc

5 files changed

Lines changed: 224 additions & 10 deletions

File tree

Coding_iOS/Controllers/MeDisplayViewController.m

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,215 @@
77
//
88

99
#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
1035

1136
@implementation MeDisplayViewController
1237

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+
13221
@end

Coding_iOS/Controllers/UserOrProjectTweetsViewController.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@
99
#import "BaseViewController.h"
1010
#import "Tweets.h"
1111
#import "UIMessageInputView.h"
12+
#import "ODRefreshControl.h"
13+
1214

1315
@interface UserOrProjectTweetsViewController : BaseViewController<UITableViewDataSource, UITableViewDelegate, UIScrollViewDelegate, UIMessageInputViewDelegate>
1416
@property (strong, nonatomic) Tweets *curTweets;
17+
@property (nonatomic, strong, readonly) UITableView *myTableView;
18+
@property (nonatomic, strong, readonly) ODRefreshControl *refreshControl;
1519

20+
- (void)refresh;
21+
- (void)refreshMore;
1622
@end

Coding_iOS/Controllers/UserOrProjectTweetsViewController.m

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
#import "UserOrProjectTweetsViewController.h"
1212
#import "TweetCell.h"
13-
#import "ODRefreshControl.h"
1413
#import "Coding_NetAPIManager.h"
1514
#import "UserInfoViewController.h"
1615
#import "LikersViewController.h"
@@ -20,8 +19,8 @@
2019
#import "ProjectTweetSendViewController.h"
2120

2221
@interface UserOrProjectTweetsViewController ()
23-
@property (nonatomic, strong) UITableView *myTableView;
24-
@property (nonatomic, strong) ODRefreshControl *refreshControl;
22+
@property (nonatomic, strong, readwrite) UITableView *myTableView;
23+
@property (nonatomic, strong, readwrite) ODRefreshControl *refreshControl;
2524

2625
//评论
2726
@property (nonatomic, strong) UIMessageInputView *myMsgInputView;
@@ -53,7 +52,7 @@ - (void)viewDidLoad
5352
if (_curTweets.tweetType == TweetTypeUserSingle) {
5453
self.title = _curTweets.curUser.name;
5554
}else if (_curTweets.tweetType == TweetTypeProject){
56-
self.title = @"项目内冒泡";
55+
self.title = _curTweets.curPro.name ?: @"项目内冒泡";
5756
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"addBtn_Nav"] style:UIBarButtonItemStylePlain target:self action:@selector(addBtnClicked)];
5857
}else{
5958
self.title = @"冒泡列表";
@@ -234,11 +233,7 @@ - (void)refreshCurUser{
234233

235234
#pragma mark TableM
236235
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
237-
if (_curTweets && _curTweets.list) {
238-
return [_curTweets.list count];
239-
}else{
240-
return 0;
241-
}
236+
return [_curTweets.list count];
242237
}
243238

244239
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

Coding_iOS/Views/EaseUserHeaderView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@
2020

2121
+ (id)userHeaderViewWithUser:(User *)user image:(UIImage *)image;
2222
- (void)updateData;
23-
23+
- (CGFloat)originalHeight;
2424
@end

Coding_iOS/Views/EaseUserHeaderView.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,4 +257,9 @@ - (void)updateData{
257257
}
258258
[_followBtn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
259259
}
260+
- (CGFloat)originalHeight{
261+
BOOL isMe = [_curUser.global_key isEqualToString:[Login curLoginUser].global_key];
262+
CGFloat viewHeight = isMe? EaseUserHeaderView_Height_Me: EaseUserHeaderView_Height_Other;
263+
return viewHeight;
264+
}
260265
@end

0 commit comments

Comments
 (0)