-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathProject_RootViewController.m
More file actions
654 lines (622 loc) · 27.1 KB
/
Copy pathProject_RootViewController.m
File metadata and controls
654 lines (622 loc) · 27.1 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
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
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
//
// Project_RootViewController.m
// Coding_iOS
//
// Created by 王 原闯 on 14-7-29.
// Copyright (c) 2014年 Coding. All rights reserved.
//
#import "Project_RootViewController.h"
#import "Coding_NetAPIManager.h"
#import "LoginViewController.h"
#import "ProjectListView.h"
#import "ProjectViewController.h"
#import "HtmlMedia.h"
#import "UnReadManager.h"
#import "RDVTabBarController.h"
#import "RDVTabBarItem.h"
#import "NProjectViewController.h"
#import "ProjectListCell.h"
#import "TweetSendViewController.h"
#import "EditTaskViewController.h"
#import "AddUserViewController.h"
#import "UsersViewController.h"
#import "Ease_2FA.h"
#import "PopMenu.h"
#import "PopFliterMenu.h"
#import "ProjectSquareViewController.h"
#import "SearchViewController.h"
#import "pop.h"
#import "FRDLivelyButton.h"
#import "StartImagesManager.h"
#import "ZXScanCodeViewController.h"
#import "OTPListViewController.h"
#import "WebViewController.h"
#import "ProjectToChooseListViewController.h"
@interface Project_RootViewController ()<UISearchBarDelegate, UITableViewDataSource, UITableViewDelegate>
@property (strong, nonatomic) NSMutableDictionary *myProjectsDict;
@property (strong, nonatomic) UISearchDisplayController *mySearchDisplayController;
@property (strong, nonatomic) NSMutableArray *searchResults;
@property (strong, nonatomic) NSString *searchString;
@property (nonatomic, strong) PopMenu *myPopMenu;
@property (nonatomic, strong) PopFliterMenu *myFliterMenu;
@property (nonatomic,assign) NSInteger selectNum; //筛选状态
@property (nonatomic,strong)UIButton *leftNavBtn;
@property (nonatomic,strong)FRDLivelyButton *rightNavBtn;
@property (nonatomic,strong)UIView *searchView;
@end
@implementation Project_RootViewController
#pragma mark TabBar
- (void)tabBarItemClicked{
[super tabBarItemClicked];
if (_myCarousel.currentItemView && [_myCarousel.currentItemView isKindOfClass:[ProjectListView class]]) {
ProjectListView *listView = (ProjectListView *)_myCarousel.currentItemView;
[listView tabBarItemClicked];
}
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self configSegmentItems];
_useNewStyle=TRUE;
_oldSelectedIndex = 0;
_selectNum=0;
// self.title = @"项目";
_myProjectsDict = [[NSMutableDictionary alloc] initWithCapacity:_segmentItems.count];
//添加myCarousel
_myCarousel = ({
iCarousel *icarousel = [[iCarousel alloc] init];
icarousel.dataSource = self;
icarousel.delegate = self;
icarousel.decelerationRate = 1.0;
icarousel.scrollSpeed = 1.0;
icarousel.type = iCarouselTypeLinear;
icarousel.pagingEnabled = YES;
icarousel.clipsToBounds = YES;
icarousel.bounceDistance = 0.2;
[self.view addSubview:icarousel];
[icarousel mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
icarousel;
});
//添加搜索框
_mySearchBar = ({
MainSearchBar *searchBar = [[MainSearchBar alloc] initWithFrame:CGRectMake(60,7, kScreen_Width-115, 31)];
[searchBar setContentMode:UIViewContentModeLeft];
[searchBar setPlaceholder:@"搜索"];
searchBar.delegate = self;
searchBar.layer.cornerRadius=15;
searchBar.layer.masksToBounds=TRUE;
[searchBar.layer setBorderWidth:8];
[searchBar.layer setBorderColor:[UIColor whiteColor].CGColor];//设置边框为白色
[searchBar sizeToFit];
[searchBar setTintColor:[UIColor whiteColor]];
[searchBar insertBGColor:[UIColor colorWithHexString:@"0xffffff"]];
[searchBar setHeight:30];
[searchBar.scanBtn addTarget:self action:@selector(scanBtnClicked) forControlEvents:UIControlEventTouchUpInside];
searchBar;
});
__weak typeof(_myCarousel) weakCarousel = _myCarousel;
//初始化过滤目录
_myFliterMenu = [[PopFliterMenu alloc] initWithFrame:CGRectMake(0, 64, kScreen_Width, kScreen_Height-64) items:nil];
__weak typeof(self) weakSelf = self;
_myFliterMenu.clickBlock = ^(NSInteger pageIndex){
[weakSelf mobClickFliterMenuIndex:pageIndex];
if (pageIndex==1000) {
[weakSelf goToProjectSquareVC];
}else
{
[weakSelf fliterBtnClose:TRUE];
[weakCarousel scrollToItemAtIndex:pageIndex animated:NO];
weakSelf.selectNum=pageIndex;
}
};
_myFliterMenu.closeBlock=^(){
[weakSelf closeFliter];
};
//初始化弹出菜单
NSArray *menuItems = @[
[MenuItem itemWithTitle:@"项目" iconName:@"pop_Project" index:0],
[MenuItem itemWithTitle:@"任务" iconName:@"pop_Task" index:1],
[MenuItem itemWithTitle:@"冒泡" iconName:@"pop_Tweet" index:2],
[MenuItem itemWithTitle:@"添加好友" iconName:@"pop_User" index:3],
[MenuItem itemWithTitle:@"私信" iconName:@"pop_Message" index:4],
[MenuItem itemWithTitle:@"两步验证" iconName:@"pop_2FA" index:5],
];
if (!_myPopMenu) {
_myPopMenu = [[PopMenu alloc] initWithFrame:CGRectMake(0, 64, kScreen_Width, kScreen_Height-64) items:menuItems];
_myPopMenu.perRowItemCount = 3;
_myPopMenu.menuAnimationType = kPopMenuAnimationTypeSina;
}
@weakify(self);
_myPopMenu.didSelectedItemCompletion = ^(MenuItem *selectedItem){
if (!selectedItem) return;
[weakSelf.myPopMenu.realTimeBlurFooter disMiss];
[MobClick event:kUmeng_Event_Request_ActionOfLocal label:[NSString stringWithFormat:@"首页_添加_%@", selectedItem.title]];
@strongify(self);
//改下显示style
[self.rightNavBtn setStyle:kFRDLivelyButtonStylePlus animated:YES];
switch (selectedItem.index) {
case 0:
[self goToNewProjectVC];
break;
case 1:
[self goToNewTaskVC];
break;
case 2:
[self goToNewTweetVC];
break;
case 3:
[self goToAddUserVC];
break;
case 4:
[self goToMessageVC];
break;
case 5:
[self goTo2FA];
break;
default:
NSLog(@"%@",selectedItem.title);
break;
}
};
[self setupNavBtn];
self.icarouselScrollEnabled = NO;
[[StartImagesManager shareManager] handleStartLink];//如果 start_image 有对应的 link 的话,需要进入到相应的 web 页面
}
- (void)mobClickFliterMenuIndex:(NSInteger)index{
static NSArray *menuList;
if (!menuList) {
menuList = @[@"全部项目",
@"我创建的",
@"我参与的",
@"我关注的",
@"我收藏的",
@"项目广场"];
}
[MobClick event:kUmeng_Event_Request_ActionOfLocal label:[NSString stringWithFormat:@"首页_筛选_%@", menuList.count > index? menuList[index]: menuList.lastObject]];
}
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.navigationController.navigationBar addSubview:_mySearchBar];
if (_myCarousel) {
ProjectListView *listView = (ProjectListView *)_myCarousel.currentItemView;
if (listView) {
[listView refreshToQueryData];
}
}
[_myFliterMenu refreshMenuDate];
}
-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[_mySearchBar removeFromSuperview];
[self closeMenu];
if (_myFliterMenu.showStatus) {
[self fliterBtnClose:TRUE];
[_myFliterMenu dismissMenu];
}
}
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
[[UnReadManager shareManager] updateUnRead];
}
#pragma mark - sub class method
- (void)setIcarouselScrollEnabled:(BOOL)icarouselScrollEnabled{
_myCarousel.scrollEnabled = icarouselScrollEnabled;
}
- (void)configSegmentItems{
_segmentItems = @[@"全部项目",@"我创建的", @"我参与的",@"我关注的",@"我收藏的"];
}
#pragma mark - nav item
- (void)setupNavBtn{
_leftNavBtn=[UIButton new];
[self addImageBarButtonWithImageName:@"filtertBtn_normal_Nav" button:_leftNavBtn action:@selector(fliterClicked:) isRight:NO];
//变化按钮
_rightNavBtn = [[FRDLivelyButton alloc] initWithFrame:CGRectMake(0,0,18.5,18.5)];
[_rightNavBtn setOptions:@{ kFRDLivelyButtonLineWidth: @(1.0f),
kFRDLivelyButtonColor: [UIColor whiteColor]
}];
[_rightNavBtn setStyle:kFRDLivelyButtonStylePlus animated:NO];
[_rightNavBtn addTarget:self action:@selector(addItemClicked:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithCustomView:_rightNavBtn];
self.navigationItem.rightBarButtonItem = buttonItem;
}
-(void)addItemClicked:(id)sender{
if (_rightNavBtn.buttonStyle == kFRDLivelyButtonStylePlus) {
if (_myFliterMenu.showStatus) {
[self fliterBtnClose:TRUE];
[_myFliterMenu dismissMenu];
}
[_rightNavBtn setStyle:kFRDLivelyButtonStyleClose animated:YES];
[_myPopMenu showMenuAtView:kKeyWindow startPoint:CGPointMake(0, -100) endPoint:CGPointMake(0, -100)];
} else{
[self closeMenu];
}
}
-(void)fliterClicked:(id)sender{
[self closeMenu];
if (_myFliterMenu.showStatus) {
[self fliterBtnClose:TRUE];
[_myFliterMenu dismissMenu];
}else
{
[self fliterBtnClose:FALSE];
_myFliterMenu.selectNum=_selectNum>=3?_selectNum+1:_selectNum;
UIView *presentView=[[[UIApplication sharedApplication].keyWindow rootViewController] view];
[_myFliterMenu showMenuAtView:presentView];
}
}
-(void)closeFliter{
if ([_myFliterMenu showStatus]) {
[_myFliterMenu dismissMenu];
[self fliterBtnClose:TRUE];
}
}
-(void)closeMenu{
[_rightNavBtn setStyle:kFRDLivelyButtonStylePlus animated:YES];
if ([_myPopMenu isShowed]) {
[_myPopMenu dismissMenu];
}
}
-(void)fliterBtnClose:(BOOL)status{
[_leftNavBtn setImage:status?[UIImage imageNamed:@"filtertBtn_normal_Nav"]:[UIImage imageNamed:@"filterBtn_selected_Nav"] forState:UIControlStateNormal];
}
//弹出事件
-(void)rotateView:(UIView*)aView
{
POPBasicAnimation* rotateAnimation = ({
POPBasicAnimation* basicAnimation=[POPBasicAnimation animationWithPropertyNamed:kPOPLayerRotation];
basicAnimation.toValue = @(22.5 * (M_PI / 180.0f));
basicAnimation.timingFunction =[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
basicAnimation.duration = 0.2f;
[basicAnimation setCompletionBlock:^(POPAnimation * ani, BOOL fin) {
if (fin) {
}
}];
basicAnimation;
});
[aView.layer pop_addAnimation:rotateAnimation forKey:@"rotateAnimation"];
}
-(void)addImageBarButtonWithImageName:(NSString*)imageName button:(UIButton*)aBtn action:(SEL)action isRight:(BOOL)isR
{
UIImage *image = [UIImage imageNamed:imageName];
CGRect frame = CGRectMake(0,0, image.size.width, image.size.height);
aBtn.frame=frame;
[aBtn setImage:image forState:UIControlStateNormal];
[aBtn addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem* barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:aBtn];
if (isR)
{
[self.navigationItem setRightBarButtonItem:barButtonItem];
}else
{
[self.navigationItem setLeftBarButtonItem:barButtonItem];
}
}
#pragma mark iCarousel M
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel{
return _segmentItems.count;
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view{
Projects *curPros = [_myProjectsDict objectForKey:[NSNumber numberWithUnsignedInteger:index]];
if (!curPros) {
curPros = [self projectsWithIndex:index];
[_myProjectsDict setObject:curPros forKey:[NSNumber numberWithUnsignedInteger:index]];
}
ProjectListView *listView = (ProjectListView *)view;
if (listView) {
[listView setProjects:curPros];
}else{
__weak Project_RootViewController *weakSelf = self;
listView = [[ProjectListView alloc] initWithFrame:carousel.bounds projects:curPros block:^(Project *project) {
[weakSelf goToProject:project];
DebugLog(@"\n=====%@", project.name);
} tabBarHeight:CGRectGetHeight(self.rdv_tabBarController.tabBar.frame)];
listView.clickButtonBlock=^(EaseBlankPageType curType) {
switch (curType) {
case EaseBlankPageTypeProject_ALL:
case EaseBlankPageTypeProject_CREATE:
case EaseBlankPageTypeProject_JOIN:
[weakSelf goToNewProjectVC];
break;
case EaseBlankPageTypeProject_WATCHED:
case EaseBlankPageTypeProject_STARED:
[weakSelf goToProjectSquareVC];
break;
default:
break;
}
};
//使用新系列Cell样式
listView.useNewStyle=_useNewStyle;
}
[listView setSubScrollsToTop:(index == carousel.currentItemIndex)];
return listView;
}
- (Projects *)projectsWithIndex:(NSUInteger)index{
return [Projects projectsWithType:index andUser:nil];
}
- (void)carouselDidScroll:(iCarousel *)carousel{
[self.view endEditing:YES];
if (_mySegmentControl) {
float offset = carousel.scrollOffset;
if (offset > 0) {
[_mySegmentControl moveIndexWithProgress:offset];
}
}
}
- (void)carouselCurrentItemIndexDidChange:(iCarousel *)carousel
{
if (_mySegmentControl) {
_mySegmentControl.currentIndex = carousel.currentItemIndex;
}
if (_oldSelectedIndex != carousel.currentItemIndex) {
_oldSelectedIndex = carousel.currentItemIndex;
ProjectListView *curView = (ProjectListView *)carousel.currentItemView;
[curView refreshToQueryData];
}
[carousel.visibleItemViews enumerateObjectsUsingBlock:^(UIView *obj, NSUInteger idx, BOOL *stop) {
[obj setSubScrollsToTop:(obj == carousel.currentItemView)];
}];
}
#pragma mark VC
- (void)goToNewProjectVC{
UIStoryboard *newProjectStoryboard = [UIStoryboard storyboardWithName:@"NewProject" bundle:nil];
UIViewController *newProjectVC = [newProjectStoryboard instantiateViewControllerWithIdentifier:@"NewProjectVC"];
[self.navigationController pushViewController:newProjectVC animated:YES];
}
- (void)goToNewTaskVC{
__weak typeof(self) weakSelf = self;
ProjectToChooseListViewController *chooseVC = [[ProjectToChooseListViewController alloc] init];
chooseVC.projectChoosedBlock = ^(ProjectToChooseListViewController *blockChooseVC, Project *project){
[weakSelf goToNewTaskFromVC:blockChooseVC withPro:project];
};
[self.navigationController pushViewController:chooseVC animated:YES];
}
- (void)goToNewTaskFromVC:(ProjectToChooseListViewController *)proListVC withPro:(Project *)project{
EditTaskViewController *taskVC = [EditTaskViewController new];
taskVC.myTask = [Task taskWithProject:project andUser:[Login curLoginUser]];
taskVC.myTask.handleType = TaskHandleTypeAddWithoutProject;
__weak typeof(self) weakSelf = self;
taskVC.doneBlock = ^(EditTaskViewController *vc){
[vc.navigationController popToViewController:weakSelf animated:YES];
};
[proListVC.navigationController pushViewController:taskVC animated:YES];
}
- (void)goToNewTweetVC{
TweetSendViewController *vc = [[TweetSendViewController alloc] init];
vc.sendNextTweet = ^(Tweet *nextTweet){
[nextTweet saveSendData];//发送前保存草稿
[[Coding_NetAPIManager sharedManager] request_Tweet_DoTweet_WithObj:nextTweet andBlock:^(id data, NSError *error) {
if (data) {
[Tweet deleteSendData];//发送成功后删除草稿
}
}];
};
UINavigationController *nav = [[BaseNavigationController alloc] initWithRootViewController:vc];
[self.parentViewController presentViewController:nav animated:YES completion:nil];
}
- (void)goTo2FA{
OTPListViewController *vc = [OTPListViewController new];
[self.navigationController pushViewController:vc animated:YES];
}
- (void)goToProject:(Project *)project{
NProjectViewController *vc = [[NProjectViewController alloc] init];
vc.myProject = project;
[self.navigationController pushViewController:vc animated:YES];
}
- (void)goToAddUserVC{
AddUserViewController *vc = [[AddUserViewController alloc] init];
vc.type = AddUserTypeFollow;
[self.navigationController pushViewController:vc animated:YES];
}
- (void)goToMessageVC{
UsersViewController *vc = [[UsersViewController alloc] init];
vc.curUsers = [Users usersWithOwner:[Login curLoginUser] Type:UsersTypeFriends_Message];
[self.navigationController pushViewController:vc animated:YES];
}
- (void)goToProjectSquareVC{
ProjectSquareViewController *vc=[ProjectSquareViewController new];
[self.navigationController pushViewController:vc animated:YES];
}
#pragma mark Search
- (void)searchItemClicked:(id)sender{
[_mySearchBar setX:20];
if (!_mySearchDisplayController) {
_mySearchDisplayController = ({
UISearchDisplayController *searchVC = [[UISearchDisplayController alloc] initWithSearchBar:_mySearchBar contentsController:self];
searchVC.searchResultsTableView.contentInset = UIEdgeInsetsMake(CGRectGetHeight(self.mySearchBar.frame), 0, CGRectGetHeight(self.rdv_tabBarController.tabBar.frame), 0);
searchVC.searchResultsTableView.tableFooterView = [[UIView alloc] init];
[searchVC.searchResultsTableView registerClass:[ProjectListCell class] forCellReuseIdentifier:kCellIdentifier_ProjectList];
searchVC.searchResultsDataSource = self;
searchVC.searchResultsDelegate = self;
if (kHigher_iOS_6_1) {
searchVC.displaysSearchBarInNavigationBar = NO;
}
searchVC;
});
}
[_mySearchBar becomeFirstResponder];
}
-(void)searchAction{
if (!_mySearchDisplayController) {
_mySearchDisplayController = ({
UISearchDisplayController *searchVC = [[UISearchDisplayController alloc] initWithSearchBar:_mySearchBar contentsController:self];
searchVC.searchResultsTableView.contentInset = UIEdgeInsetsMake(CGRectGetHeight(self.mySearchBar.frame), 0, CGRectGetHeight(self.rdv_tabBarController.tabBar.frame), 0);
searchVC.searchResultsTableView.tableFooterView = [[UIView alloc] init];
[searchVC.searchResultsTableView registerClass:[ProjectListCell class] forCellReuseIdentifier:kCellIdentifier_ProjectList];
searchVC.searchResultsDataSource = self;
searchVC.searchResultsDelegate = self;
if (kHigher_iOS_6_1) {
searchVC.displaysSearchBarInNavigationBar = NO;
}
searchVC;
});
}
}
-(void)goToSearchVC{
[self closeFliter];
[self closeMenu];
SearchViewController *vc=[SearchViewController new];
BaseNavigationController *searchNav=[[BaseNavigationController alloc]initWithRootViewController:vc];
[self.navigationController presentViewController:searchNav animated:NO completion:nil];
}
#pragma mark Table
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (self.searchResults) {
return [self.searchResults count];
}else{
return 0;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
ProjectListCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_ProjectList forIndexPath:indexPath];
[cell setProject:[self.searchResults objectAtIndex:indexPath.row] hasSWButtons:NO hasBadgeTip:YES hasIndicator:YES];
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:kPaddingLeftWidth];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return [ProjectListCell cellHeight];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[self.mySearchBar resignFirstResponder];
[self goToProject:[self.searchResults objectAtIndex:indexPath.row]];
}
#pragma mark UISearchBarDelegate
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar{
[self goToSearchVC];
return NO;
}
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
[self searchProjectWithStr:searchText];
}
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
[self searchProjectWithStr:searchBar.text];
}
- (void)searchProjectWithStr:(NSString *)string{
self.searchString = string;
[self updateFilteredContentForSearchString:string];
[self.mySearchDisplayController.searchResultsTableView reloadData];
}
- (void)updateFilteredContentForSearchString:(NSString *)searchString{
// start out with the entire list
Projects *curPros = [_myProjectsDict objectForKey:@0];
if (curPros) {
self.searchResults = [curPros.list mutableCopy];
}else{
self.searchResults = nil;
}
// strip out all the leading and trailing spaces
NSString *strippedStr = [searchString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
// 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:@"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];
self.searchResults = [[self.searchResults filteredArrayUsingPredicate:finalCompoundPredicate] mutableCopy];
}
#pragma mark scan QR-Code
- (void)scanBtnClicked{
[MobClick event:kUmeng_Event_Request_ActionOfLocal label:@"首页_扫描二维码"];
ZXScanCodeViewController *vc = [ZXScanCodeViewController new];
__weak typeof(self) weakSelf = self;
vc.scanResultBlock = ^(ZXScanCodeViewController *vc, NSString *resultStr){
[weakSelf dealWithScanResult:resultStr ofVC:vc];
};
[self.navigationController pushViewController:vc animated:YES];
}
- (void)dealWithScanResult:(NSString *)resultStr ofVC:(ZXScanCodeViewController *)vc{
if ([OTPListViewController handleScanResult:resultStr ofVC:vc]) {
return;
}
UIViewController *nextVC = [BaseViewController analyseVCFromLinkStr:resultStr];
NSURL *URL = [NSURL URLWithString:resultStr];
if (nextVC) {
[self.navigationController pushViewController:nextVC animated:YES];
}else if ([[URL host] hasSuffix:@"coding.net"]){
//网页
WebViewController *webVc = [WebViewController webVCWithUrlStr:resultStr];
[self.navigationController pushViewController:webVc animated:YES];
}else if ([[UIApplication sharedApplication] canOpenURL:URL]){
UIAlertView *alertV = [UIAlertView bk_alertViewWithTitle:@"提示" message:[NSString stringWithFormat:@"可能存在风险,是否打开此链接?\n「%@」", resultStr]];
[alertV bk_setCancelButtonWithTitle:@"取消" handler:nil];
[alertV bk_addButtonWithTitle:@"打开链接" handler:nil];
[alertV bk_setWillDismissBlock:^(UIAlertView *al, NSInteger index) {
if (index == 1) {
[[UIApplication sharedApplication] openURL:URL];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.navigationController popViewControllerAnimated:YES];
});
}else{
[self.navigationController popViewControllerAnimated:YES];
}
}];
[alertV show];
}else if (resultStr.length > 0){
UIAlertView *alertV = [UIAlertView bk_alertViewWithTitle:@"提示" message:[NSString stringWithFormat:@"已识别此二维码内容为:\n「%@」", resultStr]];
[alertV bk_setCancelButtonWithTitle:@"取消" handler:nil];
[alertV bk_addButtonWithTitle:@"复制链接" handler:nil];
[alertV bk_setWillDismissBlock:^(UIAlertView *al, NSInteger index) {
if (index == 1) {
[[UIPasteboard generalPasteboard] setString:resultStr];
}
[self.navigationController popViewControllerAnimated:YES];
}];
[alertV show];
}else{
UIAlertView *alertV = [UIAlertView bk_alertViewWithTitle:@"无效条码" message:@"未检测到条码信息"];
[alertV bk_addButtonWithTitle:@"重试" handler:^{
if (![vc isScaning]) {
[vc startScan];
}
}];
[alertV show];
}
}
@end