Browse files

Finalize font preference. Fixes #16

  • Loading branch information...
1 parent 412e3f0 commit 2b183bcd7f370beed8046b77578a5b29e431d71a @soffes soffes committed Sep 3, 2012
View
3 Classes/CDIListsViewController.m
@@ -12,7 +12,6 @@
#import "CDICreateListViewController.h"
#import "CDISettingsViewController.h"
#import "CDISplitViewController.h"
-#import "CDISettingsFontPickerViewController.h"
#import "UIColor+CheddariOSAdditions.h"
#import "CDIUpgradeViewController.h"
#import "CDIListsPlaceholderView.h"
@@ -79,8 +78,6 @@ - (void)viewDidLoad {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_listUpdated:) name:kCDKListDidUpdateNotificationName object:nil];
}
- [[NSNotificationCenter defaultCenter] addObserver:self.tableView selector:@selector(reloadData) name:kCDIFontDidChangeNotificationName object:nil];
-
_checkForOneList = YES;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_currentUserDidChange:) name:kCDKCurrentUserChangedNotificationName object:nil];
View
2 Classes/CDISettingsViewController.m
@@ -94,8 +94,6 @@ - (void)viewDidLoad {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_updateUI) name:kCDKPlusDidChangeNotificationName object:nil];
[self _updateUI];
-
- [[NSNotificationCenter defaultCenter] addObserver:self.tableView selector:@selector(reloadData) name:kCDIFontDidChangeNotificationName object:nil];
}
View
1 Classes/CDITableViewCell.h
@@ -14,5 +14,6 @@
+ (CGFloat)cellHeight;
- (void)setEditingAction:(SEL)editAction forTarget:(id)target;
+- (void)updateFonts;
@end
View
15 Classes/CDITableViewCell.m
@@ -7,6 +7,7 @@
//
#import "CDITableViewCell.h"
+#import "CDISettingsFontPickerViewController.h"
#import "UIColor+CheddariOSAdditions.h"
#import "UIFont+CheddariOSAdditions.h"
@@ -30,11 +31,11 @@ - (UITextField *)textField {
_textField = [[SSTextField alloc] initWithFrame:CGRectZero];
_textField.textColor = self.textLabel.textColor;
_textField.placeholderTextColor = [UIColor cheddarLightTextColor];
- _textField.font = self.textLabel.font;
_textField.backgroundColor = [UIColor whiteColor];
_textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
_textField.returnKeyType = UIReturnKeyDone;
_textField.alpha = 0.0f;
+ [self updateFonts];
[self.contentView addSubview:_textField];
}
return _textField;
@@ -87,7 +88,7 @@ - (void)layoutSubviews {
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if ((self = [super initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier])) {
self.textLabel.textColor = [UIColor cheddarTextColor];
- self.textLabel.font = [UIFont cheddarFontOfSize:20.0f];
+ [self updateFonts];
SSBorderedView *background = [[SSBorderedView alloc] initWithFrame:CGRectZero];
background.backgroundColor = [UIColor whiteColor];
@@ -103,6 +104,8 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus
_editingLongPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] init];
_editingLongPressGestureRecognizer.delegate = self;
[self addGestureRecognizer:_editingLongPressGestureRecognizer];
+
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateFonts) name:kCDIFontDidChangeNotificationName object:nil];
}
return self;
}
@@ -128,6 +131,14 @@ - (void)prepareForReuse {
}
+#pragma mark - Font Handling
+
+- (void)updateFonts {
+ _textField.font = self.textLabel.font;
+ self.textLabel.font = [UIFont cheddarFontOfSize:20.0f];
+}
+
+
#pragma mark - UIGestureRecognizerDelegate
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
View
77 Classes/CDITaskTableViewCell.m
@@ -13,6 +13,10 @@
#import "UIFont+CheddariOSAdditions.h"
#import "CDKTask+CheddariOSAdditions.h"
+@interface CDITaskTableViewCell ()
+- (void)_updateAttributedText;
+@end
+
@implementation CDITaskTableViewCell {
UIImageView *_checkmark;
}
@@ -39,32 +43,7 @@ - (void)setTask:(CDKTask *)task {
nil];
}
- [_attributedLabel setText:_task.displayText afterInheritingLabelAttributesAndConfiguringWithBlock:^NSMutableAttributedString *(NSMutableAttributedString *mutableAttributedString) {
- [task addEntitiesToAttributedString:mutableAttributedString];
- return mutableAttributedString;
- }];
-
- // Add links
- for (NSDictionary *entity in _task.entities) {
- NSArray *indices = [entity objectForKey:@"display_indices"];
- NSRange range = NSMakeRange([[indices objectAtIndex:0] unsignedIntegerValue], 0);
- range.length = [[indices objectAtIndex:1] unsignedIntegerValue] - range.location;
- range = [_attributedLabel.text composedRangeWithRange:range];
-
- NSString *type = [entity objectForKey:@"type"];
-
- // Tag
- if ([type isEqualToString:@"tag"]) {
- NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"x-cheddar-tag://%@", [entity objectForKey:@"tag_name"]]];
- [_attributedLabel addLinkToURL:url withRange:range];
- }
-
- // Link
- else if ([type isEqualToString:@"link"]) {
- NSURL *url = [NSURL URLWithString:[entity objectForKey:@"url"]];
- [_attributedLabel addLinkToURL:url withRange:range];
- }
- }
+ [self _updateAttributedText];
}
@@ -75,9 +54,9 @@ + (CGFloat)cellHeightForTask:(CDKTask *)task width:(CGFloat)width {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
label = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
- label.font = [UIFont cheddarFontOfSize:20.0f];
label.numberOfLines = 0;
});
+ label.font = [UIFont cheddarFontOfSize:20.0f];
label.text = task.attributedDisplayText;
CGSize size = [label sizeThatFits:CGSizeMake(width - 54.0f, 2000.0f)];
label.text = nil;
@@ -101,10 +80,10 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus
_attributedLabel = [[CDIAttributedLabel alloc] initWithFrame:CGRectZero];
_attributedLabel.textColor = [UIColor cheddarTextColor];
- _attributedLabel.font = [UIFont cheddarFontOfSize:20.0f];
_attributedLabel.backgroundColor = [UIColor clearColor];
_attributedLabel.numberOfLines = 0;
_attributedLabel.verticalAlignment = TTTAttributedLabelVerticalAlignmentTop;
+ [self updateFonts];
[self.contentView addSubview:_attributedLabel];
self.contentView.clipsToBounds = YES;
@@ -153,4 +132,46 @@ - (void)prepareForReuse {
self.task = nil;
}
+
+#pragma mark - CDITableViewCell
+
+- (void)updateFonts {
+ [super updateFonts];
+ _attributedLabel.font = [UIFont cheddarFontOfSize:20.0f];
+ [self _updateAttributedText];
+}
+
+
+#pragma Private
+
+- (void)_updateAttributedText {
+ __weak CDKTask *task = _task;
+ [_attributedLabel setText:_task.displayText afterInheritingLabelAttributesAndConfiguringWithBlock:^NSMutableAttributedString *(NSMutableAttributedString *mutableAttributedString) {
+ [task addEntitiesToAttributedString:mutableAttributedString];
+ return mutableAttributedString;
+ }];
+
+ // Add links
+ for (NSDictionary *entity in _task.entities) {
+ NSArray *indices = [entity objectForKey:@"display_indices"];
+ NSRange range = NSMakeRange([[indices objectAtIndex:0] unsignedIntegerValue], 0);
+ range.length = [[indices objectAtIndex:1] unsignedIntegerValue] - range.location;
+ range = [_attributedLabel.text composedRangeWithRange:range];
+
+ NSString *type = [entity objectForKey:@"type"];
+
+ // Tag
+ if ([type isEqualToString:@"tag"]) {
+ NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"x-cheddar-tag://%@", [entity objectForKey:@"tag_name"]]];
+ [_attributedLabel addLinkToURL:url withRange:range];
+ }
+
+ // Link
+ else if ([type isEqualToString:@"link"]) {
+ NSURL *url = [NSURL URLWithString:[entity objectForKey:@"url"]];
+ [_attributedLabel addLinkToURL:url withRange:range];
+ }
+ }
+}
+
@end

0 comments on commit 2b183bc

Please sign in to comment.