-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathProject_RootViewController.m
More file actions
893 lines (845 loc) · 36.5 KB
/
Copy pathProject_RootViewController.m
File metadata and controls
893 lines (845 loc) · 36.5 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
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
//
// 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 "StartImagesManager.h"
#import "ZXScanCodeViewController.h"
#import "OTPListViewController.h"
#import "WebViewController.h"
#import "ProjectToChooseListViewController.h"
#import "EATerminalViewController.h"
#import "KxMenu.h"
#ifdef Target_Enterprise
@interface Project_RootViewController ()
@property (strong, nonatomic) NSMutableDictionary *myProjectsDict;
//@property (nonatomic, strong) PopMenu *myPopMenu;
//@property (nonatomic, strong) PopFliterMenu *myFliterMenu;
@property (strong, nonatomic) UIButton *titleBtn;
@property (nonatomic,assign) NSInteger selectNum; //筛选状态
@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];
}
}
- (BOOL)isRoot{
return [self isMemberOfClass:[Project_RootViewController class]];
}
- (void)viewDidLoad{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.title = @"项目";
[self configSegmentItems];
_useNewStyle = TRUE;
_oldSelectedIndex = 0;
_selectNum = 0;
_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;
});
// __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{
// [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_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){
// @strongify(self);
// if (!selectedItem) return;
// [MobClick event:kUmeng_Event_Request_ActionOfLocal label:[NSString stringWithFormat:@"首页_添加_%@", selectedItem.title]];
// switch (selectedItem.index) {
// case 0:
// [self goToNewProjectVC];
// break;
// case 1:
// [self goToNewTaskVC];
// break;
// case 2:
// [self goToMessageVC];
// break;
// case 3:
// [self goTo2FA];
// break;
// default:
// NSLog(@"%@",selectedItem.title);
// break;
// }
// };
// if ([self isRoot]) {
// [self setupTitleBtn];
// }
[self setupNavBtn];
self.icarouselScrollEnabled = NO;
[[StartImagesManager shareManager] handleStartLink];//如果 start_image 有对应的 link 的话,需要进入到相应的 web 页面
[self checkToShowLockedTip];
}
- (void)checkToShowLockedTip{
if ([Login curLoginCompany].locked.boolValue) {
[[UIAlertController ea_alertViewWithTitle:@"服务已暂停" message:@"您订购的服务已过期,项目、任务等功能操作与高级权限将会失效。如需正常使用,请前往企业版网站订购。" buttonTitles:nil destructiveTitle:nil cancelTitle:@"知道了" andDidDismissBlock:nil] show];
}
}
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
if (_myCarousel) {
ProjectListView *listView = (ProjectListView *)_myCarousel.currentItemView;
if (listView) {
[listView refreshToQueryData];
}
}
// [_myFliterMenu refreshMenuDate];
}
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
// [self closeMenu];
// if (_myFliterMenu.showStatus) {
// [_myFliterMenu dismissMenu];
// }
}
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
[[UnReadManager shareManager] updateUnRead];
}
- (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]];
}
#pragma mark - sub class method
- (void)setIcarouselScrollEnabled:(BOOL)icarouselScrollEnabled{
_myCarousel.scrollEnabled = icarouselScrollEnabled;
}
- (void)configSegmentItems{
_segmentItems = @[@"全部项目",@"我创建的", @"我参与的",@"我关注的",@"我收藏的"];
}
#pragma mark - nav item
- (void)setupNavBtn{
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"addBtn_Nav"] style:UIBarButtonItemStylePlain target:self action:@selector(addItemClicked:)];
}
//- (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;
// [self setTitleBtnStr:@"全部项目"];
// }
//}
- (void)setTitleBtnStr:(NSString *)titleStr{
if (_titleBtn) {
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)setSelectNum:(NSInteger)selectNum{
_selectNum = selectNum;
[self setTitleBtnStr:_segmentItems[_selectNum]];
}
-(void)addItemClicked:(id)sender{
if ([KxMenu isShowingInView:kKeyWindow]) {
[KxMenu dismissMenu:YES];
}else{
[KxMenu setTitleFont:[UIFont systemFontOfSize:14]];
[KxMenu setTintColor:[UIColor whiteColor]];
[KxMenu setLineColor:kColorDDD];
[KxMenu setYOffset:CGRectGetMaxY(self.navigationController.navigationBar.frame)];
NSMutableArray *menuItems = [@[
[KxMenuItem menuItem:@"新项目" image:[UIImage imageNamed:@"quick_menu_icon_project"] target:self action:@selector(goToNewProjectVC)],
[KxMenuItem menuItem:@"新任务" image:[UIImage imageNamed:@"quick_menu_icon_task"] target:self action:@selector(goToNewTaskVC)],
[KxMenuItem menuItem:@"新私信" image:[UIImage imageNamed:@"quick_menu_icon_message"] target:self action:@selector(goToMessageVC)],
[KxMenuItem menuItem:@"两步验证" image:[UIImage imageNamed:@"quick_menu_icon_2fa"] target:self action:@selector(goTo2FA)],
] mutableCopy];
[menuItems setValue:kColor222 forKey:@"foreColor"];
CGRect senderFrame = CGRectMake(kScreen_Width - (kDevice_Is_iPhone6Plus? 30: 26), 5, 0, 0);
[KxMenu showMenuInView:kKeyWindow
fromRect:senderFrame
menuItems:menuItems];
}
// [self closeFliter];
// if (!_myPopMenu.isShowed) {
// [_myPopMenu showMenuAtView:kKeyWindow startPoint:CGPointMake(0, -100) endPoint:CGPointMake(0, -100)];
// } else{
// [self closeMenu];
// }
}
//-(void)fliterClicked:(id)sender{
// [self closeMenu];
// if (_myFliterMenu.showStatus == YES) {
// [_myFliterMenu dismissMenu];
// }else {
// _myFliterMenu.selectNum = _selectNum >= 3? _selectNum + 1: _selectNum;
// [_myFliterMenu showMenuAtView:kKeyWindow];
// }
//}
//-(void)closeFliter{
// if ([_myFliterMenu showStatus]) {
// [_myFliterMenu dismissMenu];
// }
//}
//-(void)closeMenu{
// if ([_myPopMenu isShowed]) {
// [_myPopMenu dismissMenu];
// }
//}
#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;
// if ([self isRoot]) {//根视图设置,子类不设置
// [listView setSearchBlock:^{
// [weakSelf goToSearchVC];
// } andScanBlock:^{
// [weakSelf scanBtnClicked];
// }];
// }
}
[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{
ProjectToChooseListViewController *chooseVC = [[ProjectToChooseListViewController alloc] init];
[self.navigationController pushViewController:chooseVC animated:YES];
}
- (void)goToNewTweetVC{
TweetSendViewController *vc = [[TweetSendViewController alloc] init];
vc.sendNextTweet = ^(Tweet *nextTweet){
[[Coding_NetAPIManager sharedManager] request_Tweet_DoTweet_WithObj:nextTweet andBlock:^(id data, NSError *error) {
if (data) {
[Tweet deleteSendData];//发送成功后删除草稿
}else{
[nextTweet saveSendData];//发送失败,保存草稿
}
}];
};
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:UsersType_CompanyMember];
[self.navigationController pushViewController:vc animated:YES];
}
- (void)goToProjectSquareVC{
ProjectSquareViewController *vc=[ProjectSquareViewController new];
[self.navigationController pushViewController:vc animated:YES];
}
-(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 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]){
[[UIAlertController ea_alertViewWithTitle:@"提示" message:[NSString stringWithFormat:@"可能存在风险,是否打开此链接?\n「%@」", resultStr] buttonTitles:@[@"打开链接"] destructiveTitle:nil cancelTitle:@"取消" andDidDismissBlock:^(UIAlertAction *action, NSInteger index) {
if (index == 0) {
[[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];
}
}] show];
}else if (resultStr.length > 0){
[[UIAlertController ea_alertViewWithTitle:@"提示" message:[NSString stringWithFormat:@"已识别此二维码内容为:\n「%@」", resultStr] buttonTitles:@[@"复制链接"] destructiveTitle:nil cancelTitle:@"取消" andDidDismissBlock:^(UIAlertAction *action, NSInteger index) {
if (index == 0) {
[[UIPasteboard generalPasteboard] setString:resultStr];
}
[self.navigationController popViewControllerAnimated:YES];
}] show];
}else{
[[UIAlertController ea_alertViewWithTitle:@"无效条码" message:@"未检测到条码信息" buttonTitles:@[@"重试"] destructiveTitle:nil cancelTitle:nil andDidDismissBlock:^(UIAlertAction *action, NSInteger index) {
if (![vc isScaning]) {
[vc startScan];
}
}] show];
}
}
@end
#else
@interface Project_RootViewController ()
@property (strong, nonatomic) NSMutableDictionary *myProjectsDict;
@property (nonatomic, strong) PopMenu *myPopMenu;
@property (nonatomic, strong) PopFliterMenu *myFliterMenu;
@property (strong, nonatomic) UIButton *titleBtn;
@property (nonatomic,assign) NSInteger selectNum; //筛选状态
@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];
}
}
- (BOOL)isRoot{
return [self isMemberOfClass:[Project_RootViewController class]];
}
- (void)viewDidLoad{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self configSegmentItems];
_useNewStyle = TRUE;
_oldSelectedIndex = 0;
_selectNum = 0;
_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;
});
__weak typeof(_myCarousel) weakCarousel = _myCarousel;
//初始化过滤目录
_myFliterMenu = [[PopFliterMenu alloc] initWithFrame:CGRectMake(0, 44 + kSafeArea_Top, kScreen_Width, kScreen_Height - (44 + kSafeArea_Top)) items:nil];
__weak typeof(self) weakSelf = self;
_myFliterMenu.clickBlock = ^(NSInteger pageIndex){
[weakSelf mobClickFliterMenuIndex:pageIndex];
if (pageIndex==1000) {
[weakSelf goToProjectSquareVC];
}else{
[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, 44 + kSafeArea_Top, kScreen_Width, kScreen_Height-(44 + kSafeArea_Top)) items:menuItems];
_myPopMenu.perRowItemCount = 3;
_myPopMenu.menuAnimationType = kPopMenuAnimationTypeSina;
}
@weakify(self);
_myPopMenu.didSelectedItemCompletion = ^(MenuItem *selectedItem){
@strongify(self);
if (!selectedItem) return;
[MobClick event:kUmeng_Event_Request_ActionOfLocal label:[NSString stringWithFormat:@"首页_添加_%@", selectedItem.title]];
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;
}
};
if ([self isRoot]) {
[self setupTitleBtn];
}
[self setupNavBtn];
self.icarouselScrollEnabled = NO;
// [[StartImagesManager shareManager] handleStartLink];//如果 start_image 有对应的 link 的话,需要进入到相应的 web 页面
// [self setupTerminalButton];
}
- (void)setupTerminalButton{
UIButton *terminalB = [UIButton new];
terminalB.backgroundColor = [UIColor clearColor];
[terminalB setImage:[UIImage imageNamed:@"button_terminal"] forState:UIControlStateNormal];
__weak typeof(self) weakSelf = self;
[terminalB bk_addEventHandler:^(id sender) {
EATerminalViewController *vc = [EATerminalViewController terminalVC];
[weakSelf.navigationController pushViewController:vc animated:YES];
} forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:terminalB];
[terminalB mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.offset(0);
make.bottom.offset(-weakSelf.rdv_tabBarController.tabBar.height);
make.size.mas_equalTo(CGSizeMake(80, 80));
}];
}
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
if (_myCarousel) {
ProjectListView *listView = (ProjectListView *)_myCarousel.currentItemView;
if (listView) {
[listView refreshToQueryData];
}
}
[_myFliterMenu refreshMenuDate];
}
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[self closeMenu];
if (_myFliterMenu.showStatus) {
[_myFliterMenu dismissMenu];
}
}
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
[[UnReadManager shareManager] updateUnRead];
}
- (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]];
}
#pragma mark - sub class method
- (void)setIcarouselScrollEnabled:(BOOL)icarouselScrollEnabled{
_myCarousel.scrollEnabled = icarouselScrollEnabled;
}
- (void)configSegmentItems{
_segmentItems = @[@"全部项目",@"我创建的", @"我参与的",@"我关注的",@"我收藏的"];
}
#pragma mark - nav item
- (void)setupNavBtn{
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"addBtn_Nav"] style:UIBarButtonItemStylePlain target:self action:@selector(addItemClicked:)];
}
- (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;
[self setTitleBtnStr:@"全部项目"];
}
}
- (void)setTitleBtnStr:(NSString *)titleStr{
if (_titleBtn.titleLabel.text.length != titleStr.length) {
CGFloat titleWidth = [titleStr getWidthWithFont:_titleBtn.titleLabel.font constrainedToSize:CGSizeMake(kScreen_Width, 30)];
CGFloat imageWidth = 12;
CGFloat btnWidth = titleWidth +imageWidth;
_titleBtn.frame = CGRectMake(0, 0, 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];
}else{
[_titleBtn setTitle:titleStr forState:UIControlStateNormal];
}
}
- (void)setSelectNum:(NSInteger)selectNum{
_selectNum = selectNum;
[self setTitleBtnStr:_segmentItems[MIN(_selectNum, _segmentItems.count - 1)]];
}
-(void)addItemClicked:(id)sender{
[self closeFliter];
if (!_myPopMenu.isShowed) {
[_myPopMenu showMenuAtView:kKeyWindow startPoint:CGPointMake(0, -100) endPoint:CGPointMake(0, -100)];
} else{
[self closeMenu];
}
}
-(void)fliterClicked:(id)sender{
[self closeMenu];
if (_myFliterMenu.showStatus == YES) {
[_myFliterMenu dismissMenu];
}else {
_myFliterMenu.selectNum = _selectNum >= 3? _selectNum + 1: _selectNum;
[_myFliterMenu showMenuAtView:kKeyWindow];
}
}
-(void)closeFliter{
if ([_myFliterMenu showStatus]) {
[_myFliterMenu dismissMenu];
}
}
-(void)closeMenu{
if ([_myPopMenu isShowed]) {
[_myPopMenu dismissMenu];
}
}
#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;
if ([self isRoot]) {//根视图设置,子类不设置
[listView setSearchBlock:^{
[weakSelf goToSearchVC];
} andScanBlock:^{
[weakSelf scanBtnClicked];
}];
}
}
[listView setSubScrollsToTop:(index == carousel.currentItemIndex)];
return listView;
}
- (Projects *)projectsWithIndex:(NSUInteger)index{
ProjectsType type = (index == 0? ProjectsTypeAll:
index == 1? ProjectsTypeCreated:
index == 2? ProjectsTypeJoined:
index == 3? ProjectsTypeWatched:
index == 4? ProjectsTypeStared:
ProjectsTypeAll);
return [Projects projectsWithType:type 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{
ProjectToChooseListViewController *chooseVC = [[ProjectToChooseListViewController alloc] init];
[self.navigationController pushViewController:chooseVC animated:YES];
}
- (void)goToNewTweetVC{
TweetSendViewController *vc = [[TweetSendViewController alloc] init];
vc.sendNextTweet = ^(Tweet *nextTweet){
[[Coding_NetAPIManager sharedManager] request_Tweet_DoTweet_WithObj:nextTweet andBlock:^(id data, NSError *error) {
if (data) {
[Tweet deleteSendData];//发送成功后删除草稿
}else{
[nextTweet saveSendData];//发送失败,保存草稿
}
}];
};
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];
}
-(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 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]){
[[UIAlertController ea_alertViewWithTitle:@"提示" message:[NSString stringWithFormat:@"可能存在风险,是否打开此链接?\n「%@」", resultStr] buttonTitles:@[@"打开链接"] destructiveTitle:nil cancelTitle:@"取消" andDidDismissBlock:^(UIAlertAction *action, NSInteger index) {
if (index == 0) {
[[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];
}
}] show];
}else if (resultStr.length > 0){
[[UIAlertController ea_alertViewWithTitle:@"提示" message:[NSString stringWithFormat:@"已识别此二维码内容为:\n「%@」", resultStr] buttonTitles:@[@"复制链接"] destructiveTitle:nil cancelTitle:@"取消" andDidDismissBlock:^(UIAlertAction *action, NSInteger index) {
if (index == 0) {
[[UIPasteboard generalPasteboard] setString:resultStr];
}
[self.navigationController popViewControllerAnimated:YES];
}] show];
}else{
[[UIAlertController ea_alertViewWithTitle:@"无效条码" message:@"未检测到条码信息" buttonTitles:@[@"重试"] destructiveTitle:nil cancelTitle:nil andDidDismissBlock:^(UIAlertAction *action, NSInteger index) {
if (![vc isScaning]) {
[vc startScan];
}
}] show];
}
}
@end
#endif