forked from coding/Coding-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskContentCell.m
More file actions
210 lines (194 loc) · 8.45 KB
/
Copy pathTaskContentCell.m
File metadata and controls
210 lines (194 loc) · 8.45 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
//
// TaskContentCell.m
// Coding_iOS
//
// Created by 王 原闯 on 14-8-19.
// Copyright (c) 2014年 Coding. All rights reserved.
//
#define kTaskContentCell_ContentHeightMin kScaleFrom_iPhone5_Desgin(90.0)
#define kTextView_Pading 8.0
#define kTaskContentCell_ContentWidth (kScreen_Width-kPaddingLeftWidth-kPaddingLeftWidth + 2*kTextView_Pading)
#define kTaskContentCell_ContentFont [UIFont systemFontOfSize:18]
#import "TaskContentCell.h"
#import "ProjectTagsView.h"
#import "Coding_NetAPIManager.h"
@interface TaskContentCell ()
@property (strong, nonatomic) ProjectTagsView *tagsView;
@property (strong, nonatomic) UITextView *taskContentView;
@property (strong, nonatomic) UIButton *deleteBtn;
@property (strong, nonatomic) UILabel *creatorLabel, *numLabel;
@property (strong, nonatomic) UIView *downLineView, *upLineView;
@end
@implementation TaskContentCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
self.selectionStyle = UITableViewCellSelectionStyleNone;
if (!_tagsView) {
_tagsView = [ProjectTagsView viewWithTags:nil];
@weakify(self);
_tagsView.addTagBlock = ^(){
@strongify(self);
if (self.addTagBlock) {
self.addTagBlock();
}
};
_tagsView.deleteTagBlock = ^(ProjectTag *curTag){
@strongify(self);
[self deleteTag:curTag];
};
[self.contentView addSubview:_tagsView];
}
if (!_upLineView) {
_upLineView = [[UIView alloc] initWithFrame:CGRectMake(kPaddingLeftWidth, 0, kScreen_Width - 2*kPaddingLeftWidth, 0.5)];
_upLineView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"dot_line"]];
[self.contentView addSubview:_upLineView];
}
if (!_taskContentView) {
_taskContentView = [[UITextView alloc] initWithFrame:CGRectZero];
_taskContentView.backgroundColor = [UIColor clearColor];
_taskContentView.font = kTaskContentCell_ContentFont;
_taskContentView.delegate = self;
[self.contentView addSubview:_taskContentView];
}
if (!_numLabel) {
if (!_numLabel) {
_numLabel = [[UILabel alloc] init];
_numLabel.font = [UIFont systemFontOfSize:12];
_numLabel.textColor = [UIColor colorWithHexString:@"0x222222"];
[self.contentView addSubview:_numLabel];
}
}
if (!_creatorLabel) {
_creatorLabel = [[UILabel alloc] init];
_creatorLabel.font = [UIFont systemFontOfSize:12];
_creatorLabel.textColor = [UIColor colorWithHexString:@"0x999999"];
[self.contentView addSubview:_creatorLabel];
}
if (!_deleteBtn) {
_deleteBtn = ({
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.titleLabel.font = [UIFont systemFontOfSize:13];
[button setTitleColor:[UIColor colorWithHexString:@"0x666666"] forState:UIControlStateNormal];
[button setTitle:@"删除" forState:UIControlStateNormal];
[button addTarget:self action:@selector(deleteBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:button];
button;
});
}
if (!_downLineView) {
_downLineView = [[UIView alloc] initWithFrame:CGRectMake(kPaddingLeftWidth, 0, kScreen_Width - 2*kPaddingLeftWidth, 0.5)];
_downLineView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"dot_line"]];
[self.contentView addSubview:_downLineView];
}
[_upLineView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView).offset(kPaddingLeftWidth);
make.right.equalTo(self.contentView).offset(-kPaddingLeftWidth);
make.height.mas_equalTo(0.5);
make.bottom.equalTo(_tagsView).offset(5);
}];
[_taskContentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(_upLineView.mas_bottom).offset(5.0);
make.left.equalTo(self.contentView).offset(kPaddingLeftWidth-kTextView_Pading);
make.right.equalTo(self.contentView).offset(-(kPaddingLeftWidth-kTextView_Pading));
make.height.mas_equalTo(kTaskContentCell_ContentHeightMin);
}];
[_numLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView.mas_left).offset(kPaddingLeftWidth);
make.bottom.equalTo(self.contentView.mas_bottom).offset(-10);
make.height.mas_equalTo(20);
}];
[_creatorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.numLabel.mas_right);
make.right.lessThanOrEqualTo(_deleteBtn.mas_left).offset(10);
make.bottom.equalTo(self.contentView.mas_bottom).offset(-10);
make.height.mas_equalTo(20);
}];
[_deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(44, 20));
make.bottom.equalTo(self.contentView.mas_bottom).offset(-10);
make.right.equalTo(self.contentView.mas_right).offset(-kPaddingLeftWidth);
}];
[_downLineView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView).offset(kPaddingLeftWidth);
make.right.equalTo(self.contentView).offset(-kPaddingLeftWidth);
make.height.mas_equalTo(0.5);
make.bottom.equalTo(self.contentView);
}];
}
return self;
}
- (void)layoutSubviews{
[super layoutSubviews];
if (!_task) {
return;
}
_tagsView.tags = _task.labels;
[_tagsView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentView).offset(10);
make.left.right.equalTo(self.contentView);
make.height.mas_equalTo([ProjectTagsView getHeightForTags:self.task.labels]);
}];
_taskContentView.text = _task.content;
if (_task.handleType > TaskHandleTypeEdit) {
_creatorLabel.text = [NSString stringWithFormat:@"%@ 现在", _task.creator.name];
_deleteBtn.hidden = YES;
_numLabel.hidden = YES;
}else{
_numLabel.text = [NSString stringWithFormat:@"#%@ ", _task.number.stringValue];
_creatorLabel.text = [NSString stringWithFormat:@"%@ 创建于 %@", _task.creator.name, [_task.created_at stringDisplay_HHmm]];
_deleteBtn.hidden = !([_task.creator.global_key isEqualToString:[Login curLoginUser].global_key] || _task.project.owner_id.integerValue == [Login curLoginUser].id.integerValue);
}
}
- (void)deleteBtnClicked:(id)sender{
if (_deleteBtnClickedBlock) {
_deleteBtnClickedBlock(_task);
}
}
- (void)descriptionBtnClicked:(id)sender{
if (_descriptionBtnClickedBlock) {
_descriptionBtnClickedBlock(_task);
}
}
- (void)deleteTag:(ProjectTag *)curTag{
curTag = [ProjectTag tags:_task.labels hasTag:curTag];
if (curTag) {
NSMutableArray *selectedTags = [_task.labels mutableCopy];
[selectedTags removeObject:curTag];
@weakify(self);
[[Coding_NetAPIManager sharedManager] request_EditTask:_task withTags:selectedTags andBlock:^(id data, NSError *error) {
@strongify(self);
if (data) {
self.task.labels = selectedTags;
if (self.tagsChangedBlock) {
self.tagsChangedBlock();
}
}
}];
}
}
+ (CGFloat)cellHeightWithObj:(id)obj{
CGFloat cellHeight = 0;
if ([obj isKindOfClass:[Task class]]) {
Task *task = (Task *)obj;
cellHeight += 10;
cellHeight += [ProjectTagsView getHeightForTags:task.labels];
cellHeight += 10 + kTaskContentCell_ContentHeightMin + 40;
}
return cellHeight;
}
#pragma mark TextView Delegate
- (void)textViewDidChange:(UITextView *)textView{
if (self.textValueChangedBlock) {
self.textValueChangedBlock(textView.text);
}
}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
if (self.textViewBecomeFirstResponderBlock) {
self.textViewBecomeFirstResponderBlock();
}
return YES;
}
@end