Skip to content

Commit

Permalink
Multitag. Fixes #27
Browse files Browse the repository at this point in the history
  • Loading branch information
soffes committed Jul 31, 2012
1 parent f61f994 commit 0ac01da
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 50 deletions.
6 changes: 3 additions & 3 deletions Classes/CDIAddTaskView.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
+ (CGFloat)margin;
- (void)setEditing:(BOOL)editing animated:(BOOL)animated;

- (void)showTag:(NSString *)tagName;
- (void)hideTag;
- (void)showTags:(NSArray *)tags;
- (void)closeTags;

@end

Expand All @@ -39,6 +39,6 @@

- (void)addTaskViewDidBeginEditing:(CDIAddTaskView *)addTaskView;
- (void)addTaskViewDidEndEditing:(CDIAddTaskView *)addTaskView;
- (void)addTaskViewShouldCloseTag:(CDIAddTaskView *)addTaskView;
- (void)addTaskViewShouldCloseTags:(CDIAddTaskView *)addTaskView;

@end
20 changes: 11 additions & 9 deletions Classes/CDIAddTaskView.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

@interface CDIAddTaskView () <UITextFieldDelegate>
@property (nonatomic, strong) SMTEDelegateController *textExpander;
- (void)_closeTag;
- (void)_closeTags;
@end

@implementation CDIAddTaskView {
Expand Down Expand Up @@ -220,9 +220,11 @@ - (void)setEditing:(BOOL)editing animated:(BOOL)animated {

#pragma mark - Tag

- (void)showTag:(NSString *)tagName {
- (void)showTags:(NSArray *)tags {
_textField.enabled = NO;

NSString *text = [[NSString stringWithFormat:@"#%@", [[tags valueForKey:@"name"] componentsJoinedByString:@" #"]] lowercaseString];

if (!_tagContainer) {
_tagContainer = [[UIView alloc] initWithFrame:self.bounds];
_tagContainer.backgroundColor = [UIColor clearColor];
Expand All @@ -237,23 +239,23 @@ - (void)showTag:(NSString *)tagName {
[_tagContainer addSubview:_tagViewShadow];

_tagView = [[CDITagView alloc] initWithFrame:CGRectMake(0.0f, size.height, size.width, size.height)];
_tagView.textLabel.text = [NSString stringWithFormat:@"#%@", tagName];
_tagView.textLabel.text = text;
[_tagContainer addSubview:_tagView];

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(_closeTag)];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(_closeTags)];
[_tagView addGestureRecognizer:tap];

[UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction animations:^{
_tagView.frame = CGRectMake(0.0f, 0.0f, size.width, size.height);
_tagViewShadow.alpha = 0.55f;
} completion:nil];
} else {
_tagView.textLabel.text = [NSString stringWithFormat:@"#%@", tagName];
_tagView.textLabel.text = text;
}
}


- (void)hideTag {
- (void)closeTags {
_textField.enabled = YES;

CGSize size = self.bounds.size;
Expand All @@ -273,9 +275,9 @@ - (void)hideTag {
}


- (void)_closeTag {
if ([self.delegate respondsToSelector:@selector(addTaskViewShouldCloseTag:)]) {
[self.delegate addTaskViewShouldCloseTag:self];
- (void)_closeTags {
if ([self.delegate respondsToSelector:@selector(addTaskViewShouldCloseTags:)]) {
[self.delegate addTaskViewShouldCloseTags:self];
}
}

Expand Down
4 changes: 3 additions & 1 deletion Classes/CDIListViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
@interface CDIListViewController : CDIManagedTableViewController

@property (nonatomic, strong, readonly) CDKList *list;
@property (nonatomic, strong) CDKTag *currentTag;
@property (nonatomic, assign) BOOL focusKeyboard;

- (void)addTag:(CDKTag *)tag;
- (void)closeTags;

@end
84 changes: 49 additions & 35 deletions Classes/CDIListViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

@interface CDIListViewController () <CDIAddTaskViewDelegate, TTTAttributedLabelDelegate, UITextFieldDelegate, UIActionSheetDelegate, UIAlertViewDelegate>
@property (nonatomic, strong) CDIAddTaskView *addTaskView;
@property (nonatomic, strong) NSMutableArray *currentTags;
- (void)_renameList:(id)sender;
- (void)_archiveTasks:(id)sender;
- (void)_archiveAllTasks:(id)sender;
Expand All @@ -32,7 +33,7 @@ @implementation CDIListViewController {
}

@synthesize addTaskView = _addTaskView;
@synthesize currentTag = _currentTag;
@synthesize currentTags = _currentTags;
@synthesize focusKeyboard = _focusKeyboard;

- (void)setManagedObject:(SSManagedObject *)managedObject {
Expand All @@ -58,7 +59,7 @@ - (void)setManagedObject:(SSManagedObject *)managedObject {
[list addObserver:self forKeyPath:@"archivedAt" options:NSKeyValueObservingOptionNew context:context];

self.ignoreChange = YES;
self.currentTag = nil;
[self closeTags];

self.fetchedResultsController.fetchRequest.predicate = self.predicate;
[self.fetchedResultsController performFetch:nil];
Expand Down Expand Up @@ -92,32 +93,6 @@ - (CDIAddTaskView *)addTaskView {
}


- (void)setCurrentTag:(CDKTag *)tag {
if ((!_currentTag && !tag) || [_currentTag isEqual:tag]) {
return;
}

_currentTag = tag;

SSFilterableFetchedResultsController *controller = (SSFilterableFetchedResultsController *)self.fetchedResultsController;

if (_currentTag) {
NSString *filterName = [NSString stringWithFormat:@"tag-%@", tag.name];
[self.addTaskView showTag:_currentTag.name];
[controller addFilterPredicate:^BOOL(id obj) {
return [(CDKTask *)obj hasTag:_currentTag];
} forKey:filterName];
[controller setActiveFilterByKey:filterName];
self.navigationItem.rightBarButtonItem.enabled = NO;
[self setEditing:NO animated:YES];
} else {
[self.addTaskView hideTag];
[controller removeCurrentFilter];
self.navigationItem.rightBarButtonItem.enabled = YES;
}
}


#pragma mark - NSObject

- (id)init {
Expand Down Expand Up @@ -176,7 +151,7 @@ - (void)setEditing:(BOOL)editing animated:(BOOL)animated {
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UIBarButtonItemStyleBordered target:self action:@selector(toggleEditMode:)];
}
self.navigationItem.rightBarButtonItem.title = editing ? @"Done" : @"Edit";
self.navigationItem.rightBarButtonItem.enabled = !self.currentTag && self.list;
self.navigationItem.rightBarButtonItem.enabled = self.currentTags.count == 0 && self.list;
[self.addTaskView setEditing:editing animated:animated];
}

Expand All @@ -203,9 +178,9 @@ - (Class)entityClass {


- (NSPredicate *)predicate {
if (self.currentTag) {
return [NSPredicate predicateWithFormat:@"list = %@ AND archivedAt = nil AND ANY taggings.tag = %@", self.list, self.currentTag];
}
// if (self.currentTags.count > 0) {
// return [NSPredicate predicateWithFormat:@"list = %@ AND archivedAt = nil AND ANY taggings.tag IN %@", self.list, self.currentTags];
// }

return [NSPredicate predicateWithFormat:@"list = %@ AND archivedAt = nil", self.list];
}
Expand Down Expand Up @@ -263,6 +238,45 @@ - (void)refresh:(id)sender {
}


#pragma mark - Tags

- (void)addTag:(CDKTag *)tag {
if (!tag || [_currentTags containsObject:tag]) {
return;
}

if (!_currentTags) {
_currentTags = [[NSMutableArray alloc] init];
}

[_currentTags addObject:tag];

SSFilterableFetchedResultsController *controller = (SSFilterableFetchedResultsController *)self.fetchedResultsController;

NSString *filterName = [_currentTags componentsJoinedByString:@","];
[self.addTaskView showTags:_currentTags];
[controller addFilterPredicate:^BOOL(id obj) {
return [(CDKTask *)obj hasTags:_currentTags];
} forKey:filterName];
[controller setActiveFilterByKey:filterName];

self.navigationItem.rightBarButtonItem.enabled = NO;
[self setEditing:NO animated:YES];
}


- (void)closeTags {
[self.addTaskView closeTags];

SSFilterableFetchedResultsController *controller = (SSFilterableFetchedResultsController *)self.fetchedResultsController;
[controller removeCurrentFilter];

[_currentTags removeAllObjects];

self.navigationItem.rightBarButtonItem.enabled = YES;
}


#pragma mark - Private

- (void)updateTableViewOffsets {
Expand Down Expand Up @@ -469,8 +483,8 @@ - (void)addTaskViewDidEndEditing:(CDIAddTaskView *)addTaskView {
}


- (void)addTaskViewShouldCloseTag:(CDIAddTaskView *)addTaskView; {
self.currentTag = nil;
- (void)addTaskViewShouldCloseTags:(CDIAddTaskView *)addTaskView; {
[self closeTags];
}


Expand All @@ -480,7 +494,7 @@ - (void)attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithURL:(NSURL
// Open tag
if ([url.scheme isEqualToString:@"x-cheddar-tag"]) {
CDKTag *tag = [CDKTag existingTagWithName:url.host];
self.currentTag = tag;
[self addTag:tag];
return;
}

Expand Down
10 changes: 9 additions & 1 deletion Classes/CDITagView.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ - (id)initWithFrame:(CGRect)frame {
imageView.image = [UIImage imageNamed:@"tag.png"];
[self addSubview:imageView];

_textLabel = [[UILabel alloc] initWithFrame:CGRectMake(44.0f, 13.0f, self.bounds.size.width - 54.0f, 24.0f)];
_textLabel = [[UILabel alloc] initWithFrame:CGRectZero];
_textLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
_textLabel.backgroundColor = [UIColor clearColor];
_textLabel.textColor = [UIColor whiteColor];
_textLabel.shadowColor = [UIColor colorWithWhite:0.0f alpha:0.2f];
_textLabel.shadowOffset = CGSizeMake(0.0f, 1.0f);
_textLabel.font = [UIFont cheddarFontOfSize:24.0f];
_textLabel.lineBreakMode = UILineBreakModeTailTruncation;
[self addSubview:_textLabel];

imageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.bounds.size.width - 26.0f, 18.0f, 16.0f, 16.0f)];
Expand All @@ -45,4 +46,11 @@ - (id)initWithFrame:(CGRect)frame {
return self;
}


- (void)layoutSubviews {
[super layoutSubviews];

_textLabel.frame = CGRectMake(44.0f, 13.0f, self.bounds.size.width - 74.0f, 24.0f);
}

@end
2 changes: 1 addition & 1 deletion Vendor/CheddarKit

0 comments on commit 0ac01da

Please sign in to comment.