Permalink
Browse files

Merge branch 'echamberlain-TTLauncherButton' into development

Closes #411.
  • Loading branch information...
2 parents fad323d + aa4427d commit 20b2106d8943809365d3fab60a5286022cd7b5bf @jverkoey jverkoey committed Feb 26, 2011
@@ -44,13 +44,13 @@ - (void)loadView {
URL:@"fb://item4" canDelete:YES] autorelease],
[[[TTLauncherItem alloc] initWithTitle:@"Button 5"
image:@"bundle://Icon.png"
- URL:nil canDelete:YES] autorelease],
+ URL:@"fb://item5" canDelete:YES] autorelease],
[[[TTLauncherItem alloc] initWithTitle:@"Button 6"
image:@"bundle://Icon.png"
- URL:nil canDelete:YES] autorelease],
+ URL:@"fb://item6" canDelete:YES] autorelease],
[[[TTLauncherItem alloc] initWithTitle:@"Button 7"
image:@"bundle://Icon.png"
- URL:nil canDelete:YES] autorelease],
+ URL:@"fb://item7" canDelete:YES] autorelease],
nil],
[NSArray arrayWithObjects:
[[[TTLauncherItem alloc] initWithTitle:@"Button 8"
@@ -66,6 +66,18 @@ - (void)loadView {
TTLauncherItem* item = [_launcherView itemWithURL:@"fb://item3"];
item.badgeNumber = 4;
+
+ item = [_launcherView itemWithURL:@"fb://item4"];
+ item.badgeNumber = 0;
+
+ item = [_launcherView itemWithURL:@"fb://item5"];
+ item.badgeValue = @"100!";
+
+ item = [_launcherView itemWithURL:@"fb://item6"];
+ item.badgeValue = @"Off";
+
+ item = [_launcherView itemWithURL:@"fb://item7"];
+ item.badgeNumber = 300;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -27,7 +27,7 @@
NSString* _URL;
NSString* _style;
- NSInteger _badgeNumber;
+ NSString* _badgeValue;
BOOL _canDelete;
}
@@ -38,6 +38,7 @@
@property (nonatomic, copy) NSString* URL;
@property (nonatomic, copy) NSString* style;
@property (nonatomic) NSInteger badgeNumber;
+@property (nonatomic, copy) NSString* badgeValue;
@property (nonatomic) BOOL canDelete;
- (id)initWithTitle:(NSString*)title image:(NSString*)image URL:(NSString*)URL;
@@ -103,24 +103,29 @@ - (void)dealloc {
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)updateBadge {
- if (!_badge && _item.badgeNumber) {
+ if (_badge == nil && _item.badgeValue != nil) {
_badge = [[TTLabel alloc] init];
_badge.style = TTSTYLE(largeBadge);
_badge.backgroundColor = [UIColor clearColor];
_badge.userInteractionEnabled = NO;
[self addSubview:_badge];
}
- if (_item.badgeNumber > 0) {
- if (_item.badgeNumber <= kMaxBadgeNumber) {
- _badge.text = [NSString stringWithFormat:@"%d", _item.badgeNumber];
-
+ NSString *badgeText = nil;
+ NSString *badgeValue = _item.badgeValue;
+
+ if (badgeValue != nil) {
+ NSRange range = [badgeValue rangeOfCharacterFromSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]];
+
+ if (range.location == NSNotFound && _item.badgeNumber > kMaxBadgeNumber) {
+ badgeText = [NSString stringWithFormat:@"%d+", kMaxBadgeNumber];
} else {
- _badge.text = [NSString stringWithFormat:@"%d+", kMaxBadgeNumber];
+ badgeText = badgeValue;
}
}
-
- _badge.hidden = _item.badgeNumber <= 0;
+
+ _badge.text = badgeText;
+ _badge.hidden = badgeValue == nil;
[_badge sizeToFit];
[self setNeedsLayout];
}
@@ -30,7 +30,7 @@ @implementation TTLauncherItem
@synthesize image = _image;
@synthesize URL = _URL;
@synthesize style = _style;
-@synthesize badgeNumber = _badgeNumber;
+@synthesize badgeValue = _badgeValue;
@synthesize canDelete = _canDelete;
@@ -111,12 +111,30 @@ - (void)encodeWithCoder:(NSCoder*)encoder {
#pragma mark Public
+///////////////////////////////////////////////////////////////////////////////////////////////////
+- (NSInteger)badgeNumber {
+ return [self.badgeValue integerValue];
+}
+
+
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)setBadgeNumber:(NSInteger)badgeNumber {
- _badgeNumber = badgeNumber;
+ if (badgeNumber == 0) {
+ [self setBadgeValue:nil];
+ } else {
+ [self setBadgeValue:[NSString stringWithFormat:@"%d",badgeNumber]];
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+- (void)setBadgeValue:(NSString *)badgeValue {
+ if (_badgeValue != badgeValue) {
+ [_badgeValue release];
+ _badgeValue = [badgeValue copy];
+ }
+
[_launcher performSelector:@selector(updateItemBadge:) withObject:self];
}
-
@end

0 comments on commit 20b2106

Please sign in to comment.