diff --git a/Cheddar for iOS.xcodeproj/project.pbxproj b/Cheddar for iOS.xcodeproj/project.pbxproj index 1b2a959..79e7361 100644 --- a/Cheddar for iOS.xcodeproj/project.pbxproj +++ b/Cheddar for iOS.xcodeproj/project.pbxproj @@ -15,7 +15,7 @@ B208BC2E15BF63A80080705D /* CDICreateListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B208BB9D15BF63A80080705D /* CDICreateListViewController.m */; }; B208BC2F15BF63A80080705D /* CDIListsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B208BB9F15BF63A80080705D /* CDIListsViewController.m */; }; B208BC3015BF63A80080705D /* CDIListTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = B208BBA115BF63A80080705D /* CDIListTableViewCell.m */; }; - B208BC3115BF63A80080705D /* CDIListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B208BBA315BF63A80080705D /* CDIListViewController.m */; }; + B208BC3115BF63A80080705D /* CDITasksViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B208BBA315BF63A80080705D /* CDITasksViewController.m */; }; B208BC3215BF63A80080705D /* CDILoadingView.m in Sources */ = {isa = PBXBuildFile; fileRef = B208BBA515BF63A80080705D /* CDILoadingView.m */; }; B208BC3315BF63A80080705D /* CDIManagedTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B208BBA715BF63A80080705D /* CDIManagedTableViewController.m */; }; B208BC3515BF63A80080705D /* CDITasksPlaceholderView.m in Sources */ = {isa = PBXBuildFile; fileRef = B208BBAB15BF63A80080705D /* CDITasksPlaceholderView.m */; }; @@ -138,6 +138,7 @@ B26AE9BD15C5D25E0008AB1F /* CDIGroupedTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B26AE9BC15C5D25E0008AB1F /* CDIGroupedTableViewController.m */; }; B26AE9C015C5D52D0008AB1F /* CDIPickerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B26AE9BF15C5D52D0008AB1F /* CDIPickerViewController.m */; }; B2711F0F15F58398000D6C09 /* CDIHUDView.m in Sources */ = {isa = PBXBuildFile; fileRef = B2711F0E15F58398000D6C09 /* CDIHUDView.m */; }; + B2711F1215F58DFC000D6C09 /* CDICheckboxButton.m in Sources */ = {isa = PBXBuildFile; fileRef = B2711F1115F58DFB000D6C09 /* CDICheckboxButton.m */; }; B28F84DB15C37E1D003E4595 /* SSToolkitResources.bundle in Resources */ = {isa = PBXBuildFile; fileRef = B208C1E315BF63E30080705D /* SSToolkitResources.bundle */; }; B28FD2BE15BF730100365CD6 /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B28FD2BD15BF730100365CD6 /* CFNetwork.framework */; }; B28FD2C015BF731100365CD6 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B28FD2BF15BF731000365CD6 /* CoreGraphics.framework */; }; @@ -280,8 +281,8 @@ B208BB9F15BF63A80080705D /* CDIListsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDIListsViewController.m; sourceTree = ""; }; B208BBA015BF63A80080705D /* CDIListTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDIListTableViewCell.h; sourceTree = ""; }; B208BBA115BF63A80080705D /* CDIListTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDIListTableViewCell.m; sourceTree = ""; }; - B208BBA215BF63A80080705D /* CDIListViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDIListViewController.h; sourceTree = ""; }; - B208BBA315BF63A80080705D /* CDIListViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDIListViewController.m; sourceTree = ""; }; + B208BBA215BF63A80080705D /* CDITasksViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDITasksViewController.h; sourceTree = ""; }; + B208BBA315BF63A80080705D /* CDITasksViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDITasksViewController.m; sourceTree = ""; }; B208BBA415BF63A80080705D /* CDILoadingView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDILoadingView.h; sourceTree = ""; }; B208BBA515BF63A80080705D /* CDILoadingView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDILoadingView.m; sourceTree = ""; }; B208BBA615BF63A80080705D /* CDIManagedTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDIManagedTableViewController.h; sourceTree = ""; }; @@ -445,6 +446,8 @@ B26AE9BF15C5D52D0008AB1F /* CDIPickerViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDIPickerViewController.m; sourceTree = ""; }; B2711F0D15F58398000D6C09 /* CDIHUDView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDIHUDView.h; sourceTree = ""; }; B2711F0E15F58398000D6C09 /* CDIHUDView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDIHUDView.m; sourceTree = ""; }; + B2711F1015F58DFB000D6C09 /* CDICheckboxButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDICheckboxButton.h; sourceTree = ""; }; + B2711F1115F58DFB000D6C09 /* CDICheckboxButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDICheckboxButton.m; sourceTree = ""; }; B28FD2BD15BF730100365CD6 /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; }; B28FD2BF15BF731000365CD6 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; B28FD2C115BF731B00365CD6 /* MessageUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MessageUI.framework; path = System/Library/Frameworks/MessageUI.framework; sourceTree = SDKROOT; }; @@ -863,17 +866,17 @@ name = Lists; sourceTree = ""; }; - B23261A315C206F200D455EF /* List */ = { + B23261A315C206F200D455EF /* Tasks */ = { isa = PBXGroup; children = ( - B208BBA215BF63A80080705D /* CDIListViewController.h */, - B208BBA315BF63A80080705D /* CDIListViewController.m */, + B208BBA215BF63A80080705D /* CDITasksViewController.h */, + B208BBA315BF63A80080705D /* CDITasksViewController.m */, B208BBB015BF63A80080705D /* CDIRenameTaskViewController.h */, B208BBB115BF63A80080705D /* CDIRenameTaskViewController.m */, B2AD031F15C493C100D9B909 /* CDIWebViewController.h */, B2AD032015C493C100D9B909 /* CDIWebViewController.m */, ); - name = List; + name = Tasks; sourceTree = ""; }; B23261A415C206FF00D455EF /* Settings */ = { @@ -1013,6 +1016,8 @@ B208BBC115BF63A80080705D /* CDITagView.m */, B2711F0D15F58398000D6C09 /* CDIHUDView.h */, B2711F0E15F58398000D6C09 /* CDIHUDView.m */, + B2711F1015F58DFB000D6C09 /* CDICheckboxButton.h */, + B2711F1115F58DFB000D6C09 /* CDICheckboxButton.m */, ); name = Views; sourceTree = ""; @@ -1021,7 +1026,7 @@ isa = PBXGroup; children = ( B23261A215C206EC00D455EF /* Lists */, - B23261A315C206F200D455EF /* List */, + B23261A315C206F200D455EF /* Tasks */, B23261A615C2070D00D455EF /* Abstract */, B23261A515C2070600D455EF /* Sessions */, B23261A415C206FF00D455EF /* Settings */, @@ -1322,7 +1327,7 @@ B208BC2E15BF63A80080705D /* CDICreateListViewController.m in Sources */, B208BC2F15BF63A80080705D /* CDIListsViewController.m in Sources */, B208BC3015BF63A80080705D /* CDIListTableViewCell.m in Sources */, - B208BC3115BF63A80080705D /* CDIListViewController.m in Sources */, + B208BC3115BF63A80080705D /* CDITasksViewController.m in Sources */, B208BC3215BF63A80080705D /* CDILoadingView.m in Sources */, B208BC3315BF63A80080705D /* CDIManagedTableViewController.m in Sources */, B208BC3515BF63A80080705D /* CDITasksPlaceholderView.m in Sources */, @@ -1367,6 +1372,7 @@ B2AD656B15E907870073BBC5 /* CDIPlaceholderView.m in Sources */, B2AD656F15E907C50073BBC5 /* CDIListsPlaceholderView.m in Sources */, B2711F0F15F58398000D6C09 /* CDIHUDView.m in Sources */, + B2711F1215F58DFC000D6C09 /* CDICheckboxButton.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Classes/CDICheckboxButton.h b/Classes/CDICheckboxButton.h new file mode 100644 index 0000000..fe04433 --- /dev/null +++ b/Classes/CDICheckboxButton.h @@ -0,0 +1,15 @@ +// +// CDICheckboxButton.h +// Cheddar for iOS +// +// Created by Sam Soffes on 9/3/12. +// Copyright (c) 2012 Nothing Magical. All rights reserved. +// + +@interface CDICheckboxButton : UIButton + +// We need a reference to the table view cell so the action action get the index path by passing the table view cell to +// the table view. +@property (nonatomic, weak) UITableViewCell *tableViewCell; + +@end diff --git a/Classes/CDICheckboxButton.m b/Classes/CDICheckboxButton.m new file mode 100644 index 0000000..babe843 --- /dev/null +++ b/Classes/CDICheckboxButton.m @@ -0,0 +1,23 @@ +// +// CDICheckboxButton.m +// Cheddar for iOS +// +// Created by Sam Soffes on 9/3/12. +// Copyright (c) 2012 Nothing Magical. All rights reserved. +// + +#import "CDICheckboxButton.h" + +@implementation CDICheckboxButton + +@synthesize tableViewCell = _tableViewCell; + +- (id)initWithFrame:(CGRect)frame { + if ((self = [super initWithFrame:frame])) { + self.adjustsImageWhenHighlighted = NO; + [self setBackgroundImage:[[UIImage imageNamed:@"checkbox"] stretchableImageWithLeftCapWidth:4 topCapHeight:4] forState:UIControlStateNormal]; + } + return self; +} + +@end diff --git a/Classes/CDIListsViewController.m b/Classes/CDIListsViewController.m index 70375a5..6d82790 100644 --- a/Classes/CDIListsViewController.m +++ b/Classes/CDIListsViewController.m @@ -8,7 +8,7 @@ #import "CDIListsViewController.h" #import "CDIListTableViewCell.h" -#import "CDIListViewController.h" +#import "CDITasksViewController.h" #import "CDICreateListViewController.h" #import "CDISettingsViewController.h" #import "CDISplitViewController.h" @@ -361,7 +361,7 @@ - (void)_selectListAtIndexPath:(NSIndexPath *)indexPath newList:(BOOL)newList { [CDISplitViewController sharedSplitViewController].listViewController.managedObject = list; _selectedList = list; } else { - CDIListViewController *viewController = [[CDIListViewController alloc] init]; + CDITasksViewController *viewController = [[CDITasksViewController alloc] init]; viewController.managedObject = list; viewController.focusKeyboard = newList; [self.navigationController pushViewController:viewController animated:YES]; @@ -487,7 +487,7 @@ - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEd CDKList *list = [self objectForViewIndexPath:indexPath]; if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { - CDIListViewController *listViewController = [CDISplitViewController sharedSplitViewController].listViewController; + CDITasksViewController *listViewController = [CDISplitViewController sharedSplitViewController].listViewController; if ([listViewController.managedObject isEqual:list]) { listViewController.managedObject = nil; } diff --git a/Classes/CDISplitViewController.h b/Classes/CDISplitViewController.h index 6c4022d..f203efa 100644 --- a/Classes/CDISplitViewController.h +++ b/Classes/CDISplitViewController.h @@ -7,13 +7,13 @@ // @class CDIListsViewController; -@class CDIListViewController; +@class CDITasksViewController; @interface CDISplitViewController : UISplitViewController + (CDISplitViewController *)sharedSplitViewController; @property (nonatomic, strong, readonly) CDIListsViewController *listsViewController; -@property (nonatomic, strong, readonly) CDIListViewController *listViewController; +@property (nonatomic, strong, readonly) CDITasksViewController *listViewController; @end diff --git a/Classes/CDISplitViewController.m b/Classes/CDISplitViewController.m index bf01200..d411c35 100644 --- a/Classes/CDISplitViewController.m +++ b/Classes/CDISplitViewController.m @@ -8,7 +8,7 @@ #import "CDISplitViewController.h" #import "CDIListsViewController.h" -#import "CDIListViewController.h" +#import "CDITasksViewController.h" #import "CDIAppDelegate.h" @interface CDISplitViewController () @@ -32,7 +32,7 @@ + (CDISplitViewController *)sharedSplitViewController { - (id)init { if ((self = [super init])) { _listsViewController = [[CDIListsViewController alloc] init]; - _listViewController = [[CDIListViewController alloc] init]; + _listViewController = [[CDITasksViewController alloc] init]; self.viewControllers = [[NSArray alloc] initWithObjects: [[UINavigationController alloc] initWithRootViewController:_listsViewController], diff --git a/Classes/CDITaskTableViewCell.h b/Classes/CDITaskTableViewCell.h index 00781a1..09e96b4 100644 --- a/Classes/CDITaskTableViewCell.h +++ b/Classes/CDITaskTableViewCell.h @@ -10,6 +10,7 @@ @class CDKTask; @class CDIAttributedLabel; +@class CDICheckboxButton; @interface CDITaskTableViewCell : CDITableViewCell @@ -17,5 +18,6 @@ @property (nonatomic, strong) CDKTask *task; @property (nonatomic, strong, readonly) CDIAttributedLabel *attributedLabel; +@property (nonatomic, strong, readonly) CDICheckboxButton *checkboxButton; @end diff --git a/Classes/CDITaskTableViewCell.m b/Classes/CDITaskTableViewCell.m index 71b2301..4164940 100644 --- a/Classes/CDITaskTableViewCell.m +++ b/Classes/CDITaskTableViewCell.m @@ -8,17 +8,18 @@ #import "CDITaskTableViewCell.h" #import "CDIAttributedLabel.h" +#import "CDICheckboxButton.h" #import "UIColor+CheddariOSAdditions.h" #import "UIFont+CheddariOSAdditions.h" #import "CDKTask+CheddariOSAdditions.h" @implementation CDITaskTableViewCell { - UIImageView *_checkbox; UIImageView *_checkmark; } @synthesize task = _task; @synthesize attributedLabel = _attributedLabel; +@synthesize checkboxButton = _checkboxButton; - (void)setTask:(CDKTask *)task { @@ -27,15 +28,15 @@ - (void)setTask:(CDKTask *)task { if (_task.isCompleted) { _attributedLabel.textColor = [UIColor cheddarLightTextColor]; _checkmark.hidden = NO; - _attributedLabel.linkAttributes =[NSDictionary dictionaryWithObjectsAndKeys: - (id)[UIColor colorWithWhite:0.45f alpha:1.0f].CGColor, (NSString *)kCTForegroundColorAttributeName, - nil]; + _attributedLabel.linkAttributes = [NSDictionary dictionaryWithObjectsAndKeys: + (id)[UIColor colorWithWhite:0.45f alpha:1.0f].CGColor, (NSString *)kCTForegroundColorAttributeName, + nil]; } else { _attributedLabel.textColor = [UIColor cheddarTextColor]; _checkmark.hidden = YES; - _attributedLabel.linkAttributes =[NSDictionary dictionaryWithObjectsAndKeys: - (id)[UIColor cheddarBlueColor].CGColor, (NSString *)kCTForegroundColorAttributeName, - nil]; + _attributedLabel.linkAttributes = [NSDictionary dictionaryWithObjectsAndKeys: + (id)[UIColor cheddarBlueColor].CGColor, (NSString *)kCTForegroundColorAttributeName, + nil]; } [_attributedLabel setText:_task.displayText afterInheritingLabelAttributesAndConfiguringWithBlock:^NSMutableAttributedString *(NSMutableAttributedString *mutableAttributedString) { @@ -90,8 +91,9 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus if ((self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier])) { self.textLabel.hidden = YES; - _checkbox = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"checkbox"] stretchableImageWithLeftCapWidth:4 topCapHeight:4]]; - [self.contentView addSubview:_checkbox]; + _checkboxButton = [[CDICheckboxButton alloc] initWithFrame:CGRectZero]; + _checkboxButton.tableViewCell = self; + [self.contentView addSubview:_checkboxButton]; _checkmark = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"small-check"]]; _checkmark.hidden = YES; @@ -117,11 +119,11 @@ - (void)layoutSubviews { CGSize size = self.contentView.bounds.size; if (self.editing) { // TODO: Only match reordering and not swipe to delete - _checkbox.frame = CGRectMake(-34.0f, 13.0f, 24.0f, 24.0f); + _checkboxButton.frame = CGRectMake(-34.0f, 13.0f, 24.0f, 24.0f); _checkmark.frame = CGRectMake(-30.0f, 16.0f, 22.0f, 18.0f); _attributedLabel.frame = CGRectMake(12.0f, 13.0f, size.width - 20.0f, size.height - 27.0f); } else { - _checkbox.frame = CGRectMake(10.0f, 13.0f, 24.0f, 24.0f); + _checkboxButton.frame = CGRectMake(10.0f, 13.0f, 24.0f, 24.0f); _checkmark.frame = CGRectMake(12.0f, 16.0f, 22.0f, 18.0f); _attributedLabel.frame = CGRectMake(44.0f, 13.0f, size.width - 54.0f, size.height - 27.0f); } @@ -134,8 +136,8 @@ - (void)setEditing:(BOOL)editing animated:(BOOL)animated { [super setEditing:editing animated:animated]; void (^change)(void) = ^{ - _checkbox.alpha = editing ? 0.0f : 1.0f; - _checkmark.alpha = _checkbox.alpha; + _checkboxButton.alpha = editing ? 0.0f : 1.0f; + _checkmark.alpha = _checkboxButton.alpha; }; if (animated) { diff --git a/Classes/CDIListViewController.h b/Classes/CDITasksViewController.h similarity index 79% rename from Classes/CDIListViewController.h rename to Classes/CDITasksViewController.h index c2ccdf4..0348be6 100644 --- a/Classes/CDIListViewController.h +++ b/Classes/CDITasksViewController.h @@ -1,5 +1,5 @@ // -// CDIListViewController.h +// CDITasksViewController.h // Cheddar for iOS // // Created by Sam Soffes on 3/31/12. @@ -11,7 +11,7 @@ @class CDKList; @class CDKTag; -@interface CDIListViewController : CDIManagedTableViewController +@interface CDITasksViewController : CDIManagedTableViewController @property (nonatomic, strong, readonly) CDKList *list; @property (nonatomic, assign) BOOL focusKeyboard; diff --git a/Classes/CDIListViewController.m b/Classes/CDITasksViewController.m similarity index 96% rename from Classes/CDIListViewController.m rename to Classes/CDITasksViewController.m index 23f5ca6..0f120dc 100644 --- a/Classes/CDIListViewController.m +++ b/Classes/CDITasksViewController.m @@ -1,12 +1,12 @@ // -// CDIListViewController.m +// CDITasksViewController.m // Cheddar for iOS // // Created by Sam Soffes on 3/31/12. // Copyright (c) 2012 Nothing Magical. All rights reserved. // -#import "CDIListViewController.h" +#import "CDITasksViewController.h" #import "CDITaskTableViewCell.h" #import "CDIAddTaskView.h" #import "CDIAddTaskAnimationView.h" @@ -17,20 +17,22 @@ #import "CDIWebViewController.h" #import "CDISettingsTapPickerViewController.h" #import "CDIHUDView.h" +#import "CDICheckboxButton.h" #import "UIColor+CheddariOSAdditions.h" #import "UIFont+CheddariOSAdditions.h" -@interface CDIListViewController () +@interface CDITasksViewController () @property (nonatomic, strong) CDIAddTaskView *addTaskView; @property (nonatomic, strong) NSMutableArray *currentTags; - (void)_renameList:(id)sender; - (void)_archiveTasks:(id)sender; - (void)_archiveAllTasks:(id)sender; - (void)_archiveCompletedTasks:(id)sender; +- (void)_toggleCompletion:(CDICheckboxButton *)sender; - (void)_editTask:(CDKTask *)task; @end -@implementation CDIListViewController { +@implementation CDITasksViewController { NSIndexPath *_textEditingIndexPath; dispatch_semaphore_t _createTaskSemaphore; } @@ -321,6 +323,21 @@ - (void)_archiveCompletedTasks:(id)sender { } +- (void)_toggleCompletion:(CDICheckboxButton *)sender { + NSIndexPath *indexPath = [self.tableView indexPathForCell:(UITableViewCell *)sender.tableViewCell]; + if (!indexPath) { + return; + } + + CDKTask *task = [self objectForViewIndexPath:indexPath]; + if (!task) { + return; + } + + [task toggleCompleted]; +} + + - (void)_editTask:(CDKTask *)task { CDIRenameTaskViewController *viewController = [[CDIRenameTaskViewController alloc] init]; viewController.task = task; @@ -341,6 +358,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.attributedLabel.delegate = self; [cell setEditingAction:@selector(editRow:) forTarget:self]; + [cell.checkboxButton addTarget:self action:@selector(_toggleCompletion:) forControlEvents:UIControlEventTouchUpInside]; } [self configureCell:cell atIndexPath:indexPath];