-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathProjectTasksView.m
executable file
·162 lines (141 loc) · 5.81 KB
/
ProjectTasksView.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
//
// ProjectTasksView.m
// Coding_iOS
//
// Created by 王 原闯 on 14-8-16.
// Copyright (c) 2014年 Coding. All rights reserved.
//
#import "ProjectTasksView.h"
#import "Coding_NetAPIManager.h"
#import "XTSegmentControl.h"
#import "iCarousel.h"
@interface ProjectTasksView ()<iCarouselDataSource, iCarouselDelegate>
@property (nonatomic, strong) Project *myProject;
@property (nonatomic , copy) ProjectTaskBlock block;
@property (strong, nonatomic) NSMutableDictionary *myProTksDict;
@property (strong, nonatomic) NSMutableArray *myMemberList;
@property (strong, nonatomic) XTSegmentControl *mySegmentControl;
@property (strong, nonatomic) iCarousel *myCarousel;
@end
@implementation ProjectTasksView
- (id)initWithFrame:(CGRect)frame project:(Project *)project block:(ProjectTaskBlock)block defaultIndex:(NSInteger)index{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
_myProject = project;
_role = TaskRoleTypeAll;
self.project_id = project.id.stringValue;
_block = block;
_myProTksDict = [[NSMutableDictionary alloc] initWithCapacity:1];
_myMemberList = [[NSMutableArray alloc] initWithObjects:[ProjectMember member_All], nil];
//添加myCarousel
self.myCarousel = ({
iCarousel *icarousel = [[iCarousel alloc] initWithFrame:frame];
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 addSubview:icarousel];
[icarousel mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self).insets(UIEdgeInsetsMake(kMySegmentControlIcon_Height, 0, 0, 0));
}];
icarousel;
});
__weak typeof(self) weakSelf = self;
[[Coding_NetAPIManager sharedManager] request_ProjectMembersHaveTasks_WithObj:_myProject andBlock:^(NSArray *data, NSError *error) {
if (data) {
[weakSelf.myMemberList addObjectsFromArray:data];
//添加滑块
CGRect segmentFrame = CGRectMake(0, 0, kScreen_Width, kMySegmentControlIcon_Height);
__weak typeof(_myCarousel) weakCarousel = weakSelf.myCarousel;
weakSelf.mySegmentControl = [[XTSegmentControl alloc] initWithFrame:segmentFrame Items:weakSelf.myMemberList selectedBlock:^(NSInteger index) {
[weakCarousel scrollToItemAtIndex:index animated:NO];
}];
[weakSelf addSubview:self.mySegmentControl];
[weakSelf.myCarousel reloadData];
}else{
// 添加一个重新加载的按钮
}
}];
}
return self;
}
- (void)refreshToQueryData{
UIView *currentItemView = self.myCarousel.currentItemView;
if ([currentItemView isKindOfClass:[ProjectTaskListView class]]) {
ProjectTaskListView *listView = (ProjectTaskListView *)currentItemView;
[listView refreshToQueryData];
}
}
- (ProjectMember *)selectedMember{
ProjectMember *curMember = [_myMemberList objectAtIndex:_myCarousel.currentItemIndex];
return curMember;
}
#pragma mark iCarousel M
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel{
return [_myMemberList count];
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view{
ProjectMember *curMember = [_myMemberList objectAtIndex:index];
Tasks *curTasks = [_myProTksDict objectForKey:curMember.user_id];
if (!curTasks) {
curTasks = [Tasks tasksWithPro:_myProject owner:curMember.user queryType:TaskQueryTypeAll];
[_myProTksDict setObject:curTasks forKey:curMember.user_id];
}
ProjectTaskListView *listView = (ProjectTaskListView *)view;
if (listView) {
[self assignmentWithlistView:listView];
[listView setTasks:curTasks];
}else{
if (_role == TaskRoleTypeOwner) {
_role = TaskRoleTypeAll;
}
listView = [[ProjectTaskListView alloc] initWithFrame:carousel.bounds tasks:curTasks project_id:_project_id keyword:_keyword status:_status label:_label userId:curTasks.owner.id.stringValue role:_role block:_block tabBarHeight:0];
}
[listView setSubScrollsToTop:(index == carousel.currentItemIndex)];
return listView;
}
- (void)carouselDidScroll:(iCarousel *)carousel{
if (_mySegmentControl) {
float offset = carousel.scrollOffset;
if (offset > 0) {
[_mySegmentControl moveIndexWithProgress:offset];
}
}
}
- (void)carouselCurrentItemIndexDidChange:(iCarousel *)carousel{
if (_mySegmentControl) {
_mySegmentControl.currentIndex = carousel.currentItemIndex;
}
NSInteger index = carousel.currentItemIndex;
NSString *userId = nil;
if (index != 0) {
userId = ((ProjectMember *)_myMemberList[index]).user_id.stringValue;
}
_userId = userId;
if (_selctUserBlock) {
_selctUserBlock(_userId);
}
[self refresh];
[carousel.visibleItemViews enumerateObjectsUsingBlock:^(UIView *obj, NSUInteger idx, BOOL *stop) {
[obj setSubScrollsToTop:(obj == carousel.currentItemView)];
}];
}
- (void)assignmentWithlistView:(ProjectTaskListView *)listView {
listView.keyword = self.keyword;
listView.status = self.status;
listView.label = self.label;
listView.userId = self.userId;
listView.role = self.role;
listView.project_id = _project_id;
}
- (void)refresh {
ProjectTaskListView *listView = (ProjectTaskListView *)self.myCarousel.currentItemView;
[self assignmentWithlistView:listView];
[listView refresh];
}
@end