forked from coding/Coding-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMRPRListViewController.m
More file actions
232 lines (200 loc) · 8.17 KB
/
MRPRListViewController.m
File metadata and controls
232 lines (200 loc) · 8.17 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
//
// MRPRListViewController.m
// Coding_iOS
//
// Created by Ease on 2017/2/14.
// Copyright © 2017年 Coding. All rights reserved.
//
#import "MRPRListViewController.h"
#import "ODRefreshControl.h"
#import "SVPullToRefresh.h"
#import "MRPRS.h"
#import "Coding_NetAPIManager.h"
#import "MRPRListCell.h"
#import "PRDetailViewController.h"
#import "MRDetailViewController.h"
#import "EAFliterMenu.h"
@interface MRPRListViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (strong, nonatomic) NSMutableDictionary *dataDict;
@property (strong, nonatomic) UITableView *myTableView;
@property (nonatomic, strong) ODRefreshControl *myRefreshControl;
@property (nonatomic, assign) NSInteger selectedIndex;
@property (strong, nonatomic) UIButton *titleBtn;
@property (nonatomic, strong) EAFliterMenu *myFliterMenu;
@end
@implementation MRPRListViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[super viewDidLoad];
self.view.backgroundColor = kColorTableBG;
_dataDict = [NSMutableDictionary new];
_myTableView = ({
UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
tableView.backgroundColor = [UIColor clearColor];
tableView.dataSource = self;
tableView.delegate = self;
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[tableView registerClass:[MRPRListCell class] forCellReuseIdentifier:kCellIdentifier_MRPRListCell];
[self.view addSubview:tableView];
[tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
UIEdgeInsets insets = UIEdgeInsetsMake(0, 0, 0, 0);
tableView.contentInset = insets;
tableView.scrollIndicatorInsets = insets;
tableView;
});
_myRefreshControl = [[ODRefreshControl alloc] initInScrollView:self.myTableView];
[_myRefreshControl addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged];
__weak typeof(self) weakSelf = self;
[_myTableView addInfiniteScrollingWithActionHandler:^{
[weakSelf refreshMore:YES];
}];
self.selectedIndex = 0;
//初始化过滤目录
_myFliterMenu = [[EAFliterMenu alloc] initWithFrame:CGRectMake(0, 64, kScreen_Width, kScreen_Height - 64) items:[self titleList]];
_myFliterMenu.clickBlock = ^(NSInteger selectIndex){
if (weakSelf.selectedIndex != selectIndex) {
weakSelf.selectedIndex = selectIndex;
}
};
[self refresh];
}
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
if (_myFliterMenu.isShowing) {
[_myFliterMenu dismissMenu];
}
}
#pragma mark Fliter
- (void)setSelectedIndex:(NSInteger)selectedIndex{
_selectedIndex = selectedIndex;
[self setupTitleBtn];
[self.myTableView reloadData];
__weak typeof(self) weakSelf = self;
[self.view configBlankPage:EaseBlankPageTypeView hasData:YES hasError:NO reloadButtonBlock:^(id sender) {
[weakSelf refreshMore:NO];
}];
if ([self curMRPRS].list.count <= 0) {
[self refresh];
}else{
self.myTableView.showsInfiniteScrolling = [self curMRPRS].canLoadMore;
}
}
- (NSArray *)titleList{
NSArray *titleList = (_isMR? @[@"默认",
@"可合并",
@"不可自动合并",
@"已拒绝",
@"已合并",
]:
@[@"未处理",
@"已处理",
@"全部",
]);
return titleList;
}
- (void)setupTitleBtn{
if (!_titleBtn) {
_titleBtn = [UIButton new];
[_titleBtn setTitleColor:kColorNavTitle forState:UIControlStateNormal];
[_titleBtn.titleLabel setFont:[UIFont systemFontOfSize:kNavTitleFontSize]];
[_titleBtn addTarget:self action:@selector(fliterClicked) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.titleView = _titleBtn;
}
NSString *titleStr = [self titleList][_selectedIndex];
CGFloat titleWidth = [titleStr getWidthWithFont:_titleBtn.titleLabel.font constrainedToSize:CGSizeMake(kScreen_Width, 30)];
CGFloat imageWidth = 12;
CGFloat btnWidth = titleWidth +imageWidth;
_titleBtn.frame = CGRectMake((kScreen_Width-btnWidth)/2, (44-30)/2, btnWidth, 30);
_titleBtn.titleEdgeInsets = UIEdgeInsetsMake(0, -imageWidth, 0, imageWidth);
_titleBtn.imageEdgeInsets = UIEdgeInsetsMake(0, titleWidth, 0, -titleWidth);
[_titleBtn setTitle:titleStr forState:UIControlStateNormal];
[_titleBtn setImage:[UIImage imageNamed:@"btn_fliter_down"] forState:UIControlStateNormal];
}
-(void)fliterClicked{
if (_myFliterMenu.isShowing) {
[_myFliterMenu dismissMenu];
}else{
_myFliterMenu.selectIndex = self.selectedIndex;
[_myFliterMenu showMenuInView:kKeyWindow];
}
}
#pragma mark Data
- (MRPRS *)curMRPRS{
MRPRS *curMRPRS = [_dataDict objectForKey:@(_selectedIndex)];
if (!curMRPRS) {
curMRPRS = [[MRPRS alloc] initWithType:_isMR? _selectedIndex: _selectedIndex + MRPRSTypePROpen userGK:_curProject.owner_user_name projectName:_curProject.name];
[_dataDict setObject:curMRPRS forKey:@(_selectedIndex)];
}
return curMRPRS;
}
- (void)refresh{
[self refreshMore:NO];
}
- (void)refreshMore:(BOOL)willLoadMore{
MRPRS *curMRPRS = [self curMRPRS];
if (curMRPRS.isLoading) {
return;
}
if (willLoadMore && !curMRPRS.canLoadMore) {
[_myTableView.infiniteScrollingView stopAnimating];
return;
}
curMRPRS.willLoadMore = willLoadMore;
[self sendRequest:curMRPRS];
}
- (void)sendRequest:(MRPRS *)curMRPRS{
if (curMRPRS.list.count <= 0) {
[self.view beginLoading];
}
__weak typeof(self) weakSelf = self;
__weak typeof(curMRPRS) weakMRPRS = curMRPRS;
[[Coding_NetAPIManager sharedManager] request_MRPRS_WithObj:curMRPRS andBlock:^(MRPRS *data, NSError *error) {
[weakSelf.view endLoading];
[weakSelf.myRefreshControl endRefreshing];
[weakSelf.myTableView.infiniteScrollingView stopAnimating];
if (data) {
[weakMRPRS configWithMRPRS:data];
[weakSelf.myTableView reloadData];
weakSelf.myTableView.showsInfiniteScrolling = [weakSelf curMRPRS].canLoadMore;
}
[weakSelf.view configBlankPage:EaseBlankPageTypeView hasData:([weakSelf curMRPRS].list.count > 0) hasError:(error != nil) reloadButtonBlock:^(id sender) {
[weakSelf refreshMore:NO];
}];
}];
}
#pragma mark TableM
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [self curMRPRS].list.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
MRPR *curMRPR = [[self curMRPRS].list objectAtIndex:indexPath.row];
MRPRListCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_MRPRListCell forIndexPath:indexPath];
cell.curMRPR = curMRPR;
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:kPaddingLeftWidth];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return [MRPRListCell cellHeight];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
MRPR *curMRPR = [[self curMRPRS].list objectAtIndex:indexPath.row];
if(curMRPR.isPR) {
PRDetailViewController *vc = [PRDetailViewController new];
vc.curMRPR = curMRPR;
vc.curProject = _curProject;
[self.navigationController pushViewController:vc animated:YES];
} else {
MRDetailViewController *vc = [MRDetailViewController new];
vc.curMRPR = curMRPR;
vc.curProject = _curProject;
[self.navigationController pushViewController:vc animated:YES];
}
}
@end