-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathProjectListView.m
executable file
·612 lines (570 loc) · 26.1 KB
/
ProjectListView.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
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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
//
// ProjectListView.m
// Coding_iOS
//
// Created by 王 原闯 on 14-8-11.
// Copyright (c) 2014年 Coding. All rights reserved.
//
#import "ProjectListView.h"
#import "ProjectListCell.h"
#import "ProjectListTaCell.h"
#import "ODRefreshControl.h"
#import "Coding_NetAPIManager.h"
//新系列 cell
#import "ProjectAboutMeListCell.h"
#import "ProjectAboutOthersListCell.h"
#import "ProjectPublicListCell.h"
#import "SVPullToRefresh.h"
#import "CategorySearchBar.h"
@interface ProjectListView ()<UISearchBarDelegate, SWTableViewCellDelegate>
@property (nonatomic, strong) Projects *myProjects;
@property (nonatomic , copy) ProjectListViewBlock block;
@property (nonatomic, strong) UITableView *myTableView;
@property (nonatomic, strong) ODRefreshControl *myRefreshControl;
@property (strong, nonatomic) NSMutableArray *dataList;
@property (strong, nonatomic) UISearchBar *mySearchBar;
@property (copy, nonatomic) void(^searchBlock)();
@property (copy, nonatomic) void(^scanBlock)();
@property (assign, nonatomic) BOOL isHeaderClosed, isNewerVersionAvailable;
@end
@implementation ProjectListView
static NSString *const kTitleKey = @"kTitleKey";
static NSString *const kValueKey = @"kValueKey";
#pragma TabBar
- (void)tabBarItemClicked{
if (_myTableView.contentOffset.y > 0) {
[_myTableView setContentOffset:CGPointZero animated:YES];
}else if (!self.myRefreshControl.isAnimating){
[self.myRefreshControl beginRefreshing];
[self.myTableView setContentOffset:CGPointMake(0, -44)];
[self refresh];
}
}
- (id)initWithFrame:(CGRect)frame projects:(Projects *)projects block:(ProjectListViewBlock)block tabBarHeight:(CGFloat)tabBarHeight{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
_myProjects = projects;
_block = block;
_myTableView = ({
UITableView *tableView = [[UITableView alloc] init];
tableView.backgroundColor = [UIColor clearColor];
tableView.delegate = self;
tableView.dataSource = self;
[tableView registerClass:[ProjectListCell class] forCellReuseIdentifier:kCellIdentifier_ProjectList];
[tableView registerClass:[ProjectListTaCell class] forCellReuseIdentifier:kCellIdentifier_ProjectListTaCell];
[tableView registerClass:[ProjectAboutMeListCell class] forCellReuseIdentifier:@"ProjectAboutMeListCell"];
[tableView registerClass:[ProjectAboutOthersListCell class] forCellReuseIdentifier:@"ProjectAboutOthersListCell"];
[tableView registerClass:[ProjectPublicListCell class] forCellReuseIdentifier:@"ProjectPublicListCell"];
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self addSubview:tableView];
[tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
if (tabBarHeight != 0 && projects.type < ProjectsTypeTaProject) {
UIEdgeInsets insets = UIEdgeInsetsMake(0, 0, tabBarHeight, 0);
tableView.contentInset = insets;
tableView.scrollIndicatorInsets = insets;
}
tableView.estimatedRowHeight = 0;
tableView.estimatedSectionHeaderHeight = 0;
tableView.estimatedSectionFooterHeight = 0;
tableView;
});
if ((projects.type < ProjectsTypeToChoose && !kTarget_Enterprise) || projects.type == ProjectsTypeAllPublic) {
_mySearchBar = nil;
_myTableView.tableHeaderView = nil;
}else{
_mySearchBar = ({
UISearchBar *searchBar = [[UISearchBar alloc] init];
searchBar.delegate = self;
[searchBar sizeToFit];
[searchBar setPlaceholder:kTarget_Enterprise? @"项目名称/描述": @"项目名称/创建人"];
[searchBar setPlaceholderColor:kColorDarkA];
[searchBar setSearchIcon:[UIImage imageNamed:@"icon_search_searchbar"]];
searchBar;
});
_myTableView.tableHeaderView = _mySearchBar;
}
_myRefreshControl = [[ODRefreshControl alloc] initInScrollView:self.myTableView];
[_myRefreshControl addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged];
__weak typeof(self) weakSelf = self;
[_myTableView addInfiniteScrollingWithActionHandler:^{
[weakSelf refreshMore];
}];
if (_myProjects.list.count > 0) {
[_myTableView reloadData];
}else{
[self sendRequest];
}
}
return self;
}
- (void)setProjects:(Projects *)projects{
self.myProjects = projects;
[self setupDataList];
[self refreshUI];
}
-(void)setUseNewStyle:(BOOL)useNewStyle{
_useNewStyle = useNewStyle;
if (_useNewStyle && _myProjects.type == ProjectsTypeAllPublic) {
[_myTableView mas_updateConstraints:^(MASConstraintMaker *make) {
make.left.bottom.right.equalTo(self);
make.top.equalTo(@(44));
}];
}
[_myTableView reloadData];
[self p_checkIfNewVersionTip];
}
- (void)setSearchBlock:(void(^)())searchBlock andScanBlock:(void(^)())scanBlock{
_searchBlock = searchBlock;
_scanBlock = scanBlock;
if (_searchBlock || _scanBlock) {
_mySearchBar = ({
MainSearchBar *searchBar = [MainSearchBar new];
[searchBar setPlaceholder:@"搜索"];
[searchBar setPlaceholderColor:kColorDarkA];
[searchBar setSearchIcon:[UIImage imageNamed:@"icon_search_searchbar"]];
searchBar.delegate = self;
[searchBar sizeToFit];
[searchBar.scanBtn addTarget:self action:@selector(scanBtnClicked) forControlEvents:UIControlEventTouchUpInside];
searchBar;
});
_myTableView.tableHeaderView = _mySearchBar;
}else{
_myTableView.tableHeaderView = nil;
}
}
- (void)scanBtnClicked{
if (_scanBlock) {
_scanBlock();
}
}
- (void)setupDataList{
if (!_dataList) {
_dataList = [[NSMutableArray alloc] initWithCapacity:2];
}
[_dataList removeAllObjects];
// if (_myProjects.type < ProjectsTypeToChoose) {
//// NSArray *pinList = _myProjects.pinList, *noPinList = _myProjects.noPinList;
//// if (pinList.count > 0) {
//// [_dataList addObject:@{kTitleKey : @"常用项目",
//// kValueKey : pinList}];
//// }
//// if (noPinList.count > 0) {
//// [_dataList addObject:@{kTitleKey : @"一般项目",
//// kValueKey : noPinList}];
//// }
// NSMutableArray *list = _myProjects.list.mutableCopy;
// if (list.count > 0) {
// [list sortUsingComparator:^NSComparisonResult(Project *obj1, Project *obj2) {
// return (obj1.pin.integerValue < obj2.pin.integerValue);
// }];
// [_dataList addObject:@{kTitleKey : @"全部项目",
// kValueKey : list}];
// }
// }else{
// NSMutableArray *list = [self updateFilteredContentForSearchString:self.mySearchBar.text];
// if (list.count > 0) {
// [list sortUsingComparator:^NSComparisonResult(Project *obj1, Project *obj2) {
// return (obj1.pin.integerValue < obj2.pin.integerValue);
// }];
// [_dataList addObject:@{kTitleKey : @"一般项目",
// kValueKey : list}];
// }
// }
// 特么真搞不清上面那一坨是干嘛的了
NSMutableArray *list = [self updateFilteredContentForSearchString:self.mySearchBar.text];
if (list.count > 0) {
[list sortUsingComparator:^NSComparisonResult(Project *obj1, Project *obj2) {
return (obj1.pin.integerValue < obj2.pin.integerValue);
}];
[_dataList addObject:@{kTitleKey : @"项目",
kValueKey : list}];
}
}
- (NSString *)titleForSection:(NSUInteger)section{
if (section < self.dataList.count) {
return [[self.dataList objectAtIndex:section] valueForKey:kTitleKey];
}
return nil;
}
- (NSArray *)valueForSection:(NSUInteger)section{
if (section < self.dataList.count) {
return [[self.dataList objectAtIndex:section] valueForKey:kValueKey];
}
return nil;
}
- (void)setIsNewerVersionAvailable:(BOOL)isNewerVersionAvailable{
if (_isNewerVersionAvailable != isNewerVersionAvailable) {
_isNewerVersionAvailable = isNewerVersionAvailable;
[self.myTableView reloadData];
}
}
- (void)setIsHeaderClosed:(BOOL)isHeaderClosed{
_isHeaderClosed = isHeaderClosed;
[self.myTableView reloadData];
}
- (void)p_checkIfNewVersionTip{
if ([self p_needToCheckIfNewVersion]) {
NSString *appStoreCountry = [(NSLocale *)[NSLocale currentLocale] objectForKey:NSLocaleCountryCode];
if ([appStoreCountry isEqualToString:@"150"]){
appStoreCountry = @"eu";
}else if ([[appStoreCountry stringByReplacingOccurrencesOfString:@"[A-Za-z]{2}" withString:@"" options:NSRegularExpressionSearch range:NSMakeRange(0, 2)] length]){
appStoreCountry = @"us";
}
__weak typeof(self) weakSelf = self;
NSURLSessionTask *task = [[NSURLSession sharedSession] dataTaskWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/%@/lookup?id=%@", appStoreCountry, self.p_appID]] completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (!error && data) {
NSDictionary *result = [[NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingOptions)0 error:&error][@"results"] lastObject];
NSString *latestVersion = result[@"version"];
NSString *minimumSupportedOSVersion = result[@"minimumOsVersion"];
if (latestVersion && minimumSupportedOSVersion) {
BOOL osVersionSupported = ([[UIDevice currentDevice].systemVersion compare:minimumSupportedOSVersion options:NSNumericSearch] != NSOrderedAscending);
BOOL isNewerVersionAvailable = ([kVersion_Coding compare:latestVersion options:NSNumericSearch] == NSOrderedAscending);
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.isNewerVersionAvailable = (osVersionSupported && isNewerVersionAvailable);
});
}
}
}];
[task resume];
}
}
- (NSString *)p_appID{
return kTarget_Enterprise? @"1191398741": @"923676989";
}
- (BOOL)p_needToCheckIfNewVersion{
return (!_isHeaderClosed &&
(_useNewStyle && _myProjects.type == ProjectsTypeAll) &&
!self.isNewerVersionAvailable);
}
- (BOOL)p_needToShowVersionTip{
return (!_isHeaderClosed &&
(_useNewStyle && _myProjects.type == ProjectsTypeAll) &&
self.isNewerVersionAvailable);
}
- (BOOL)p_needToShowHeaderTip{
return (!_isHeaderClosed &&
(_useNewStyle && _myProjects.type == ProjectsTypeAll) &&
(self.isNewerVersionAvailable || ![NSObject isPrivateCloud].boolValue));
}
- (void)refreshUI{
[_myTableView reloadData];
[self refreshFirst];
}
- (void)refreshToQueryData{
[self refresh];
}
- (void)refresh{
if (!_myProjects.isLoading) {
[self sendRequest];
[self p_checkIfNewVersionTip];
}
}
- (void)refreshFirst{
if (_myProjects && !_myProjects.list) {
[self performSelector:@selector(refresh) withObject:nil afterDelay:0.3];
}
}
- (void)refreshMore{
if (_myProjects.isLoading || !_myProjects.canLoadMore) {
[_myTableView.infiniteScrollingView stopAnimating];
return;
}
_myProjects.willLoadMore = YES;
[self sendRequest];
}
- (void)sendRequest{
if (_myProjects.list.count <= 0) {
[self beginLoading];
}
//都先隐藏~后续根据数据状态显示~
self.blankPageView.hidden=TRUE;
__weak typeof(self) weakSelf = self;
[[Coding_NetAPIManager sharedManager] request_Projects_WithObj:_myProjects andBlock:^(Projects *data, NSError *error) {
[weakSelf.myRefreshControl endRefreshing];
[weakSelf endLoading];
[weakSelf.myTableView.infiniteScrollingView stopAnimating];
if (data) {
[weakSelf.myProjects configWithProjects:data];
[weakSelf setupDataList];
[weakSelf.myTableView reloadData];
}
EaseBlankPageType blankPageType;
if (weakSelf.myProjects.type < ProjectsTypeTaProject
|| [weakSelf.myProjects.curUser.global_key isEqualToString:[Login curLoginUser].global_key]) {
// blankPageType = EaseBlankPageTypeProject;
//再做细分 全部,创建,参与,关注,收藏
switch (weakSelf.myProjects.type) {
case ProjectsTypeAll:
blankPageType = EaseBlankPageTypeProject_ALL;
break;
case ProjectsTypeCreated:
case ProjectsTypeCreatedPrivate:
case ProjectsTypeCreatedPublic:
blankPageType = EaseBlankPageTypeProject_CREATE;
break;
case ProjectsTypeJoined:
blankPageType = EaseBlankPageTypeProject_JOIN;
break;
case ProjectsTypeWatched:
blankPageType = EaseBlankPageTypeProject_WATCHED;
break;
case ProjectsTypeStared:
blankPageType = EaseBlankPageTypeProject_STARED;
break;
default:
blankPageType = EaseBlankPageTypeProject;
break;
}
}else{
blankPageType = EaseBlankPageTypeProjectOther;
}
[weakSelf configBlankPage:blankPageType hasData:(weakSelf.myProjects.list.count > 0) hasError:(error != nil) reloadButtonBlock:^(id sender) {
[weakSelf refresh];
}];
//空白页按钮事件
self.blankPageView.clickButtonBlock=^(EaseBlankPageType curType) {
weakSelf.clickButtonBlock(curType);
};
weakSelf.myTableView.showsInfiniteScrolling = weakSelf.myProjects.canLoadMore;
}];
}
#pragma mark Table M
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return [_dataList count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
if ([self p_needToShowHeaderTip]) {
static UILabel *tipL;
if (!tipL) {
tipL = [UILabel labelWithFont:[UIFont systemFontOfSize:12] textColor:[UIColor colorWithHexString:@"0x136BFB"]];
tipL.numberOfLines = 0;
}
tipL.attributedText = [self p_headerTipStr];
return [tipL sizeThatFits:CGSizeMake(kScreen_Width - 40 * 1, CGFLOAT_MAX)].height + 16;
} else {
return 0;
}
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
if ([self p_needToShowHeaderTip]) {
UIView *headerV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, 40)];
headerV.backgroundColor = [UIColor colorWithHexString:@"0xECF9FF"];
__weak typeof(self) weakSelf = self;
UIButton *closeBtn = [UIButton new];
[closeBtn setImage:[UIImage imageNamed:@"button_tip_close"] forState:UIControlStateNormal];
[closeBtn bk_addEventHandler:^(id sender) {
weakSelf.isHeaderClosed = YES;
} forControlEvents:UIControlEventTouchUpInside];
[headerV addSubview:closeBtn];
[closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.right.equalTo(headerV);
make.width.mas_equalTo(40);
make.height.mas_equalTo(36); // 文字单行显示时的高度
}];
// UIImageView *noticeV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"button_tip_notice"]];
// noticeV.contentMode = UIViewContentModeCenter;
// [headerV addSubview:noticeV];
// [noticeV mas_makeConstraints:^(MASConstraintMaker *make) {
// make.top.bottom.left.equalTo(headerV);
// make.width.mas_equalTo(0);
// }];
UILabel *tipL = [UILabel labelWithFont:[UIFont systemFontOfSize:12] textColor:[UIColor colorWithHexString:@"0x136BFB"]];
tipL.numberOfLines = 0;
tipL.userInteractionEnabled = YES;
tipL.attributedText = [self p_headerTipStr];
if ([self p_needToShowVersionTip]) {
[tipL bk_whenTapped:^{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:kAppUrl]];
}];
}
[headerV addSubview:tipL];
[tipL mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(headerV).mas_offset(3);
make.left.equalTo(headerV).offset(15);
make.right.equalTo(closeBtn.mas_left);
}];
return headerV;
} else {
return nil;
}
}
- (NSAttributedString *)p_headerTipStr{
if ([self p_needToShowHeaderTip]) {
NSString *tipStr;
if ([self p_needToShowVersionTip]) {
tipStr = kTarget_Enterprise? @"立即升级最新 CODING 企业版客户端": @"立即升级最新 Coding 客户端";
} else {
tipStr = @"温馨提示:出于实际使用场景限制的考虑,该 App ���再进行更多新功能开发,建议您前往 PC 端网页版体验更完整的产品功能。";
}
NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
paragraphStyle.lineSpacing = 6;
NSDictionary *attributes = @{NSParagraphStyleAttributeName: paragraphStyle};
return [[NSAttributedString alloc] initWithString:tipStr attributes:attributes];
} else {
return nil;
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [[self valueForSection:section] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
Project *curPro = [[self valueForSection:indexPath.section] objectAtIndex:indexPath.row];
if (_useNewStyle) {
if (_myProjects.type < ProjectsTypeWatched) {
ProjectAboutMeListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ProjectAboutMeListCell" forIndexPath:indexPath];
[cell setProject:curPro hasSWButtons:self.myProjects.type == ProjectActivityTypeAll?YES:NO hasBadgeTip:YES hasIndicator:NO];
cell.delegate = self;
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpaceAndSectionLine:kPaddingLeftWidth];
return cell;
}else if (_myProjects.type==ProjectsTypeWatched||_myProjects.type==ProjectsTypeStared){
ProjectAboutOthersListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ProjectAboutOthersListCell" forIndexPath:indexPath];
[cell setProject:curPro hasSWButtons:self.myProjects.type == ProjectActivityTypeAll?YES:NO hasBadgeTip:YES hasIndicator:NO];
cell.delegate = self;
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpaceAndSectionLine:kPaddingLeftWidth];
return cell;
}else if (_myProjects.type==ProjectsTypeAllPublic){
ProjectPublicListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ProjectPublicListCell" forIndexPath:indexPath];
[cell setProject:curPro hasSWButtons:self.myProjects.type == ProjectActivityTypeAll?YES:NO hasBadgeTip:YES hasIndicator:NO];
cell.delegate = self;
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpaceAndSectionLine:kPaddingLeftWidth];
return cell;
}
else{
ProjectListTaCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_ProjectListTaCell forIndexPath:indexPath];
cell.project = curPro;
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpaceAndSectionLine:kPaddingLeftWidth];
return cell;
}
}else
{
if (_myProjects.type < ProjectsTypeTaProject) {
ProjectListCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_ProjectList forIndexPath:indexPath];
if (self.myProjects.type == ProjectsTypeToChoose) {
[cell setProject:curPro hasSWButtons:NO hasBadgeTip:NO hasIndicator:NO];
}else{
[cell setProject:curPro hasSWButtons:YES hasBadgeTip:YES hasIndicator:YES];
}
cell.delegate = self;
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:kPaddingLeftWidth];
return cell;
}else{
ProjectListTaCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_ProjectListTaCell forIndexPath:indexPath];
cell.project = curPro;
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:kPaddingLeftWidth];
return cell;
}
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (_useNewStyle) {
if (_myProjects.type < ProjectsTypeTaProject) {
return kProjectAboutMeListCellHeight;
}else if (_myProjects.type==ProjectsTypeAllPublic){
return kProjectPublicListCellHeight;
}else{
return [ProjectListTaCell cellHeight];
}
}else{
return (_myProjects.type < ProjectsTypeTaProject)?[ProjectListCell cellHeight]:[ProjectListTaCell cellHeight];
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (_block) {
_block([[self valueForSection:indexPath.section] objectAtIndex:indexPath.row]);
}
}
- (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex:(NSInteger)index {
[cell hideUtilityButtonsAnimated:YES];
NSIndexPath *indexPath = [self.myTableView indexPathForCell:cell];
Project *curPro = [[self valueForSection:indexPath.section] objectAtIndex:indexPath.row];
__weak typeof(curPro) weakPro = curPro;
__weak typeof(self) weakSelf = self;
[[Coding_NetAPIManager sharedManager] request_Project_Pin:curPro andBlock:^(id data, NSError *error) {
if (data) {
weakPro.pin = @(!weakPro.pin.boolValue);
[weakSelf setupDataList];
[weakSelf.myTableView reloadData];
}
}];
}
#pragma mark SWTableViewCellDelegate
- (BOOL)swipeableTableViewCellShouldHideUtilityButtonsOnSwipe:(SWTableViewCell *)cell{
return YES;
}
#pragma mark ScrollView Delegate
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
if (scrollView == _myTableView) {
[self.mySearchBar resignFirstResponder];
}
}
#pragma mark UISearchBarDelegate
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar{
if (_searchBlock) {
_searchBlock();
}
return _searchBlock == nil;
}
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
[self searchProjectWithStr:searchText];
}
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
[searchBar resignFirstResponder];
[self searchProjectWithStr:searchBar.text];
}
- (void)searchProjectWithStr:(NSString *)string{
[self setupDataList];
[self.myTableView reloadData];
}
- (NSMutableArray *)updateFilteredContentForSearchString:(NSString *)searchString{
// start out with the entire list
NSMutableArray *searchResults = [self.myProjects.list mutableCopy];
// strip out all the leading and trailing spaces
NSString *strippedStr = [searchString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
if (strippedStr.length <= 0) {
return searchResults;
}
// break up the search terms (separated by spaces)
NSArray *searchItems = nil;
if (strippedStr.length > 0)
{
searchItems = [strippedStr componentsSeparatedByString:@" "];
}
// build all the "AND" expressions for each value in the searchString
NSMutableArray *andMatchPredicates = [NSMutableArray array];
for (NSString *searchString in searchItems)
{
// each searchString creates an OR predicate for: name, global_key
NSMutableArray *searchItemsPredicate = [NSMutableArray array];
// name field matching
NSExpression *lhs = [NSExpression expressionForKeyPath:@"name"];
NSExpression *rhs = [NSExpression expressionForConstantValue:searchString];
NSPredicate *finalPredicate = [NSComparisonPredicate
predicateWithLeftExpression:lhs
rightExpression:rhs
modifier:NSDirectPredicateModifier
type:NSContainsPredicateOperatorType
options:NSCaseInsensitivePredicateOption];
[searchItemsPredicate addObject:finalPredicate];
// owner_user_name field matching
lhs = [NSExpression expressionForKeyPath:kTarget_Enterprise? @"description_mine": @"owner_user_name"];
rhs = [NSExpression expressionForConstantValue:searchString];
finalPredicate = [NSComparisonPredicate
predicateWithLeftExpression:lhs
rightExpression:rhs
modifier:NSDirectPredicateModifier
type:NSContainsPredicateOperatorType
options:NSCaseInsensitivePredicateOption];
[searchItemsPredicate addObject:finalPredicate];
// at this OR predicate to ourr master AND predicate
NSCompoundPredicate *orMatchPredicates = (NSCompoundPredicate *)[NSCompoundPredicate orPredicateWithSubpredicates:searchItemsPredicate];
[andMatchPredicates addObject:orMatchPredicates];
}
NSCompoundPredicate *finalCompoundPredicate = (NSCompoundPredicate *)[NSCompoundPredicate andPredicateWithSubpredicates:andMatchPredicates];
[searchResults filterUsingPredicate:finalCompoundPredicate];
return searchResults;
}
@end