forked from soffes/cheddar-ios
/
CDIMoveTaskView.m
131 lines (101 loc) · 4.52 KB
/
CDIMoveTaskView.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
//
// CDIMoveTaskView.m
// Cheddar for iOS
//
// Created by Sam Soffes on 9/30/12.
// Copyright (c) 2012 Nothing Magical. All rights reserved.
//
#import "CDIMoveTaskView.h"
#import "CDIEditTaskViewController.h"
#import "CDIGroupedTableViewCell.h"
#import "UIFont+CheddariOSAdditions.h"
#import "UIColor+CheddariOSAdditions.h"
@interface CDIMoveTaskView () <UITableViewDataSource, UITableViewDelegate>
@end
@implementation CDIMoveTaskView {
SSGradientView *_shadowView;
UITableView *_tableView;
NSArray *_lists;
}
@synthesize editViewController = _editViewController;
@synthesize moveButton = _moveButton;
@synthesize tableView = _tableView;
- (void)setEditViewController:(CDIEditTaskViewController *)editViewController {
_editViewController = editViewController;
// Get lists
CDKList *currentList = _editViewController.task.list;
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
fetchRequest.entity = [CDKList entity];
fetchRequest.sortDescriptors = [CDKList defaultSortDescriptors];
fetchRequest.predicate = [NSPredicate predicateWithFormat:@"remoteID != %@ AND archivedAt = nil AND user = %@", currentList.remoteID, [CDKUser currentUser]];
_lists = [[CDKList mainContext] executeFetchRequest:fetchRequest error:nil];
if (_lists.count == 0) {
UILabel *instructionsLabel = (UILabel *)_tableView.tableHeaderView;
instructionsLabel.text = @"You don't have any other lists.";
}
}
#pragma mark - UIView
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
_moveButton = [[UIButton alloc] init];
_moveButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin;
[_moveButton setImage:[UIImage imageNamed:@"move_task"] forState:UIControlStateNormal];
[self addSubview:_moveButton];
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
_tableView.dataSource = self;
_tableView.delegate = self;
SSLabel *instructionsLabel = [[SSLabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, frame.size.width, 38.0f)];
instructionsLabel.text = @"Select a list to move this task to";
instructionsLabel.font = [UIFont cheddarInterfaceFontOfSize:14.0f];
instructionsLabel.textColor = [UIColor cheddarLightTextColor];
instructionsLabel.backgroundColor = [UIColor clearColor];
instructionsLabel.textAlignment = UITextAlignmentCenter;
instructionsLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
instructionsLabel.textEdgeInsets = UIEdgeInsetsMake(10.0f, 0.0f, 0.0f, 0.0f);
_tableView.tableHeaderView = instructionsLabel;
UIView *backgroundView = [[UIView alloc] init];
backgroundView.backgroundColor = [UIColor cheddarArchesColor];
_tableView.backgroundView = backgroundView;
[self addSubview:_tableView];
_shadowView = [[SSGradientView alloc] init];
_shadowView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin;
_shadowView.backgroundColor = [UIColor clearColor];
_shadowView.topBorderColor = [UIColor colorWithWhite:0.812f alpha:1.0f];
_shadowView.colors = @[[UIColor colorWithWhite:0.937f alpha:1.0f],
[UIColor colorWithWhite:0.937f alpha:0.0f]];
[self addSubview:_shadowView];
}
return self;
}
- (void)layoutSubviews {
CGSize size = self.bounds.size;
_moveButton.frame = CGRectMake(size.width - 32.0f, 0.0f, 32.0f, 32.0f);
_tableView.frame = CGRectMake(0.0f, 32.0f, size.width, size.height - 32.0f);
_shadowView.frame = CGRectMake(0.0f, 32.0f, size.width, 4.0f);
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return _lists.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *cellIdentifier = @"None";
NSUInteger numberOfRows = [tableView numberOfRowsInSection:indexPath.section];
if (numberOfRows == 1) {
cellIdentifier = @"Both";
} else if (indexPath.row == 0) {
cellIdentifier = @"Top";
} else if (indexPath.row == numberOfRows - 1) {
cellIdentifier = @"Bottom";
}
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) {
cell = [[CDIGroupedTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.textLabel.text = [[_lists objectAtIndex:indexPath.row] title];
return cell;
}
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self.editViewController moveTaskToList:[_lists objectAtIndex:indexPath.row]];
}
@end