-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathProjectActivityListView.m
executable file
·189 lines (166 loc) · 7.07 KB
/
ProjectActivityListView.m
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
//
// ProjectActivityListView.m
// Coding_iOS
//
// Created by 王 原闯 on 14-8-14.
// Copyright (c) 2014年 Coding. All rights reserved.
//
#import "ProjectActivityListView.h"
#import "ProjectActivityListCell.h"
#import "ODRefreshControl.h"
#import "Coding_NetAPIManager.h"
#import "SVPullToRefresh.h"
@interface ProjectActivityListView ()
@property (nonatomic, strong) ProjectActivities *myProActs;
@property (nonatomic , copy) ProjectActivityBlock block;
@property (nonatomic, strong) UITableView *myTableView;
@property (nonatomic, strong) ODRefreshControl *myRefreshControl;
@property (nonatomic, assign) NSInteger un_read_activities_count;
@end
@implementation ProjectActivityListView
- (id)initWithFrame:(CGRect)frame proAtcs:(ProjectActivities *)proAtcs block:(ProjectActivityBlock)block{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
_myProActs = proAtcs;
_block = block;
_un_read_activities_count = self.myProActs.curProject.un_read_activities_count.intValue;
_myTableView = ({
UITableView *tableView = [[UITableView alloc] initWithFrame:self.bounds style:UITableViewStylePlain];
tableView.backgroundColor = [UIColor clearColor];
tableView.delegate = self;
tableView.dataSource = self;
[tableView registerClass:[ProjectActivityListCell class] forCellReuseIdentifier:kCellIdentifier_ProjectActivityList];
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self addSubview:tableView];
[tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
tableView.estimatedRowHeight = 0;
tableView.estimatedSectionHeaderHeight = 0;
tableView.estimatedSectionFooterHeight = 0;
tableView.estimatedRowHeight = 0;
tableView.estimatedSectionHeaderHeight = 0;
tableView.estimatedSectionFooterHeight = 0;
tableView;
});
_myRefreshControl = [[ODRefreshControl alloc] initInScrollView:self.myTableView];
[_myRefreshControl addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged];
__weak typeof(self) weakSelf = self;
[_myTableView addInfiniteScrollingWithActionHandler:^{
[weakSelf refreshMore];
}];
[self sendRequest];
}
return self;
}
- (void)setProAtcs:(ProjectActivities *)proAtcs{
if (_myProActs != proAtcs) {
self.myProActs = proAtcs;
[_myTableView reloadData];
[_myTableView.infiniteScrollingView stopAnimating];
_myTableView.showsInfiniteScrolling = self.myProActs.canLoadMore;
if (self.myProActs.list.count > 0) {
[self configBlankPage:EaseBlankPageTypeActivity hasData:YES hasError:NO reloadButtonBlock:nil];
}
[self refreshFirst];
}
}
- (void)refreshFirst{
if (_myProActs && (!_myProActs.list || _myProActs.list.count <= 0)) {
[self refresh];
}
}
- (void)refresh{
if (_myProActs.isLoading) {
return;
}
_myProActs.willLoadMore = NO;
[self sendRequest];
}
- (void)refreshMore{
if (_myProActs.isLoading || !_myProActs.canLoadMore) {
return;
}
_myProActs.willLoadMore = YES;
[self sendRequest];
}
- (void)sendRequest{
if (!_myProActs.willLoadMore) {
if (_myProActs.list.count <= 0) {
[self beginLoading];
}
}
__weak typeof(self) weakSelf = self;
[[Coding_NetAPIManager sharedManager] request_ProjectActivityList_WithObj:_myProActs andBlock:^(NSArray *data, NSError *error) {
[weakSelf.myRefreshControl endRefreshing];
[weakSelf endLoading];
[weakSelf.myTableView.infiniteScrollingView stopAnimating];
if (data) {
[weakSelf.myProActs configWithProActList:data];
[weakSelf.myTableView reloadData];
weakSelf.myTableView.showsInfiniteScrolling = weakSelf.myProActs.canLoadMore;
}
[weakSelf configBlankPage:EaseBlankPageTypeActivity hasData:(weakSelf.myProActs.list.count > 0) hasError:(error != nil) reloadButtonBlock:^(id sender) {
[weakSelf refresh];
}];
}];
}
#pragma mark Table M
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return _myProActs.listGroups.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
ListGroupItem *item = [_myProActs.listGroups objectAtIndex:section];
return item.hide? 0 : item.length;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
ListGroupItem *item = [_myProActs.listGroups objectAtIndex:indexPath.section];
NSUInteger row = indexPath.row +item.location;
ProjectActivity *curProAct = [_myProActs.list objectAtIndex:row];
ProjectActivityListCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_ProjectActivityList forIndexPath:indexPath];
BOOL haveRead, isTop, isBottom;
if (_myProActs.isOfUser || ![_myProActs.type isEqualToString:@"all"]) {
haveRead = YES;
isTop = (row == item.location);
isBottom = (row == item.location +item.length -1);
}else{
haveRead = row >= _un_read_activities_count;
isTop = (row == item.location) || (row == _un_read_activities_count);
isBottom = (row == item.location +item.length -1) || (row == _un_read_activities_count-1);
}
[cell configWithProAct:curProAct haveRead:haveRead isTop:isTop isBottom:isBottom];
[cell.userIconView addTapBlock:^(id obj) {
if (_userIconClickedBlock) {
_userIconClickedBlock(curProAct.user);
}
}];
cell.htmlItemClickedBlock = self.htmlItemClickedBlock;
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:
(row == item.location +item.length -1)? 0:85];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
ListGroupItem *item = [_myProActs.listGroups objectAtIndex:indexPath.section];
NSUInteger row = indexPath.row +item.location;
return [ProjectActivityListCell cellHeightWithObj:[_myProActs.list objectAtIndex:row]];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
ListGroupItem *item = [_myProActs.listGroups objectAtIndex:indexPath.section];
NSUInteger row = indexPath.row +item.location;
if (_block) {
_block([self.myProActs.list objectAtIndex:row]);
}
}
#pragma mark TableViewHeader
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return kScaleFrom_iPhone5_Desgin(24);
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
ListGroupItem *item = [_myProActs.listGroups objectAtIndex:section];
return [tableView getHeaderViewWithStr:[item.date string_yyyy_MM_dd_EEE] andBlock:^(id obj) {
DebugLog(@"\nitem.date.description :%@", item.date.description);
}];
}
@end