Skip to content
This repository has been archived by the owner on Mar 31, 2020. It is now read-only.

Commit

Permalink
Make the checkbox toggle completion no matter what
Browse files Browse the repository at this point in the history
  • Loading branch information
soffes committed Sep 4, 2012
1 parent f330c96 commit bed5a44
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 35 deletions.
24 changes: 15 additions & 9 deletions Cheddar for iOS.xcodeproj/project.pbxproj
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -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 */; };
Expand Down Expand Up @@ -280,8 +281,8 @@
B208BB9F15BF63A80080705D /* CDIListsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDIListsViewController.m; sourceTree = "<group>"; };
B208BBA015BF63A80080705D /* CDIListTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDIListTableViewCell.h; sourceTree = "<group>"; };
B208BBA115BF63A80080705D /* CDIListTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDIListTableViewCell.m; sourceTree = "<group>"; };
B208BBA215BF63A80080705D /* CDIListViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDIListViewController.h; sourceTree = "<group>"; };
B208BBA315BF63A80080705D /* CDIListViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDIListViewController.m; sourceTree = "<group>"; };
B208BBA215BF63A80080705D /* CDITasksViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDITasksViewController.h; sourceTree = "<group>"; };
B208BBA315BF63A80080705D /* CDITasksViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDITasksViewController.m; sourceTree = "<group>"; };
B208BBA415BF63A80080705D /* CDILoadingView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDILoadingView.h; sourceTree = "<group>"; };
B208BBA515BF63A80080705D /* CDILoadingView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDILoadingView.m; sourceTree = "<group>"; };
B208BBA615BF63A80080705D /* CDIManagedTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDIManagedTableViewController.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -445,6 +446,8 @@
B26AE9BF15C5D52D0008AB1F /* CDIPickerViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDIPickerViewController.m; sourceTree = "<group>"; };
B2711F0D15F58398000D6C09 /* CDIHUDView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDIHUDView.h; sourceTree = "<group>"; };
B2711F0E15F58398000D6C09 /* CDIHUDView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDIHUDView.m; sourceTree = "<group>"; };
B2711F1015F58DFB000D6C09 /* CDICheckboxButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDICheckboxButton.h; sourceTree = "<group>"; };
B2711F1115F58DFB000D6C09 /* CDICheckboxButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDICheckboxButton.m; sourceTree = "<group>"; };
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; };
Expand Down Expand Up @@ -863,17 +866,17 @@
name = Lists;
sourceTree = "<group>";
};
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 = "<group>";
};
B23261A415C206FF00D455EF /* Settings */ = {
Expand Down Expand Up @@ -1013,6 +1016,8 @@
B208BBC115BF63A80080705D /* CDITagView.m */,
B2711F0D15F58398000D6C09 /* CDIHUDView.h */,
B2711F0E15F58398000D6C09 /* CDIHUDView.m */,
B2711F1015F58DFB000D6C09 /* CDICheckboxButton.h */,
B2711F1115F58DFB000D6C09 /* CDICheckboxButton.m */,
);
name = Views;
sourceTree = "<group>";
Expand All @@ -1021,7 +1026,7 @@
isa = PBXGroup;
children = (
B23261A215C206EC00D455EF /* Lists */,
B23261A315C206F200D455EF /* List */,
B23261A315C206F200D455EF /* Tasks */,
B23261A615C2070D00D455EF /* Abstract */,
B23261A515C2070600D455EF /* Sessions */,
B23261A415C206FF00D455EF /* Settings */,
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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;
};
Expand Down
15 changes: 15 additions & 0 deletions 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
23 changes: 23 additions & 0 deletions 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
6 changes: 3 additions & 3 deletions Classes/CDIListsViewController.m
Expand Up @@ -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"
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions Classes/CDISplitViewController.h
Expand Up @@ -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
4 changes: 2 additions & 2 deletions Classes/CDISplitViewController.m
Expand Up @@ -8,7 +8,7 @@

#import "CDISplitViewController.h"
#import "CDIListsViewController.h"
#import "CDIListViewController.h"
#import "CDITasksViewController.h"
#import "CDIAppDelegate.h"

@interface CDISplitViewController () <UISplitViewControllerDelegate>
Expand All @@ -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],
Expand Down
2 changes: 2 additions & 0 deletions Classes/CDITaskTableViewCell.h
Expand Up @@ -10,12 +10,14 @@

@class CDKTask;
@class CDIAttributedLabel;
@class CDICheckboxButton;

@interface CDITaskTableViewCell : CDITableViewCell

+ (CGFloat)cellHeightForTask:(CDKTask *)task width:(CGFloat)width;

@property (nonatomic, strong) CDKTask *task;
@property (nonatomic, strong, readonly) CDIAttributedLabel *attributedLabel;
@property (nonatomic, strong, readonly) CDICheckboxButton *checkboxButton;

@end
28 changes: 15 additions & 13 deletions Classes/CDITaskTableViewCell.m
Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
Expand All @@ -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) {
Expand Down
@@ -1,5 +1,5 @@
//
// CDIListViewController.h
// CDITasksViewController.h
// Cheddar for iOS
//
// Created by Sam Soffes on 3/31/12.
Expand All @@ -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;
Expand Down
@@ -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"
Expand All @@ -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 () <CDIAddTaskViewDelegate, TTTAttributedLabelDelegate, UITextFieldDelegate, UIActionSheetDelegate, UIAlertViewDelegate>
@interface CDITasksViewController () <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;
- (void)_archiveCompletedTasks:(id)sender;
- (void)_toggleCompletion:(CDICheckboxButton *)sender;
- (void)_editTask:(CDKTask *)task;
@end

@implementation CDIListViewController {
@implementation CDITasksViewController {
NSIndexPath *_textEditingIndexPath;
dispatch_semaphore_t _createTaskSemaphore;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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];
Expand Down

0 comments on commit bed5a44

Please sign in to comment.