Permalink
Browse files

* Fixed bug @1047: Simply the request delegate model

  • Loading branch information...
1 parent 3aa0655 commit 6eb7ec554e040290e07135a706af1ec1c3f0438d @joehewitt joehewitt committed Feb 21, 2009
View
@@ -74,7 +74,7 @@ void TTNetworkRequestStopped() {
if (!bundle) {
NSString* path = [[[NSBundle mainBundle] resourcePath]
stringByAppendingPathComponent:@"Three20.bundle"];
- bundle = [NSBundle bundleWithPath:path];
+ bundle = [[NSBundle bundleWithPath:path] retain];
}
return [bundle localizedStringForKey:key value:key table:nil];
View
@@ -1,4 +1,7 @@
#import "Three20/TTImageView.h"
+#import "Three20/TTURLResponse.h"
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
@implementation TTImageView
@@ -61,17 +64,12 @@ - (void)requestLoading:(TTURLRequest*)request {
}
}
-- (void)request:(TTURLRequest*)request loadedData:(NSData*)data media:(id)media {
+- (void)requestLoaded:(TTURLRequest*)request {
+ TTURLImageResponse* response = request.response;
+ self.image = response.image;
+
[_request release];
_request = nil;
-
- if ([media isKindOfClass:[UIImage class]]) {
- self.image = (UIImage*)media;
- } else {
- if ([_delegate respondsToSelector:@selector(imageView:loadDidFailWithError:)]) {
- [_delegate imageView:self loadDidFailWithError:nil];
- }
- }
}
- (void)request:(TTURLRequest*)request didFailWithError:(NSError*)error {
@@ -119,9 +117,8 @@ - (void)reload {
if (_request)
return;
- TTURLRequest* request = [[[TTURLRequest alloc] initWithURL:_url delegate:self] autorelease];
- request.shouldConvertToMedia = YES;
-
+ TTURLRequest* request = [TTURLRequest requestWithURL:_url delegate:self];
+ request.response = [[[TTURLImageResponse alloc] init] autorelease];
if (_url && ![request send]) {
// Put the default image in place while waiting for the request to load
if (_defaultImage && self.image != _defaultImage) {
View
@@ -47,7 +47,7 @@ - (void)dealloc {
- (BOOL)loadVersion:(TTPhotoVersion)version fromNetwork:(BOOL)fromNetwork {
NSString* url = [_photo urlForVersion:version];
if (url) {
- UIImage* image = [[TTURLCache sharedCache] getMediaForURL:url fromDisk:NO];
+ UIImage* image = [[TTURLCache sharedCache] imageForURL:url];
if (image || fromNetwork) {
_photoVersion = version;
self.url = url;
@@ -361,7 +361,7 @@ - (void)updateContent {
if (_photoSource.loading) {
self.contentState = TTContentActivity;
} else if (!_centerPhoto) {
- [self loadPhotosFromIndex:_photoSource.isInvalid ? 0 : _photoSource.maxPhotoIndex+1
+ [self loadPhotosFromIndex:_photoSource.invalid ? 0 : _photoSource.maxPhotoIndex+1
toIndex:TT_INFINITE_PHOTO_INDEX];
} else if (_photoSource.numberOfPhotos == TT_INFINITE_PHOTO_INDEX) {
[self loadPhotosFromIndex:0 toIndex:TT_INFINITE_PHOTO_INDEX];
@@ -375,7 +375,7 @@ - (void)updateContent {
}
//- (void)refreshContent {
-// if (_photoSource.isInvalid && !_photoSource.loading) {
+// if (_photoSource.invalid && !_photoSource.loading) {
// [self loadPhotosFromIndex:0 toIndex:TT_INFINITE_PHOTO_INDEX];
// }
//}
View
@@ -5,7 +5,7 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
-static const CGFloat kMarginX = 5;
+static const CGFloat kMarginX = 5;
static const CGFloat kMarginY = 5;
static const CGFloat kPaddingX = 10;
View
@@ -349,7 +349,8 @@ - (id)initWithItem:(TTTabItem*)tabItem tabBar:(TTTabBar*)tabBar style:(TTTabBarS
_titleLabel.backgroundColor = [UIColor clearColor];
_titleLabel.contentMode = UIViewContentModeCenter;
_titleLabel.shadowOffset = CGSizeMake(0, -1);
-
+ _titleLabel.adjustsFontSizeToFitWidth = YES;
+ _titleLabel.minimumFontSize = 8;
_tabImage.image = tabBar.tabImage;
if (_style == TTTabBarStyleDark) {
@@ -430,25 +431,37 @@ - (void)layoutSubviews {
_tabImage.frame = self.bounds;
+ CGSize titleSize = [_titleLabel.text sizeWithFont:_titleLabel.font];
+
+ CGFloat textWidth = self.width;
+ CGFloat textLeft = 0;
+ if (titleSize.width > self.width) {
+ textLeft = 4;
+ textWidth -= 8;
+ }
+
if (_style == TTTabBarStyleButtons) {
CGFloat iconWidth = _iconView.url.length ? kIconSize + kIconSpacing : 0;
_iconView.frame = CGRectMake(kPadding2, floor(self.height/2 - kIconSize/2)+2,
kIconSize, kIconSize);
_titleLabel.frame = CGRectOffset(self.bounds, kPadding2 + iconWidth, 0);
} else if (_style == TTTabBarStyleLight) {
_iconView.frame = CGRectZero;
- _titleLabel.frame = CGRectOffset(self.bounds, 0, 2);
+ _titleLabel.frame = CGRectMake(textLeft, self.bounds.origin.y + 2,
+ textWidth, self.height);
} else if (_style == TTTabBarStyleDark) {
_iconView.frame = CGRectZero;
- _titleLabel.frame = CGRectOffset(self.bounds, 0, 2);
+ _titleLabel.frame = CGRectMake(textLeft, self.bounds.origin.y + 2,
+ textWidth, self.height);
}
}
-- (void)sizeToFit {
- [_titleLabel sizeToFit];
+- (CGSize)sizeThatFits:(CGSize)size {
+ CGSize titleSize = [_titleLabel sizeThatFits:size];
CGFloat padding = _style == TTTabBarStyleButtons ? kPadding2 : kPadding;
CGFloat iconWidth = _iconView.url.length ? kIconSize + kIconSpacing : 0;
- self.frame = CGRectMake(self.left, self.top, _titleLabel.width + iconWidth + padding*2, self.height);
+
+ return CGSizeMake(iconWidth + titleSize.width + padding*2, size.height);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
View
@@ -486,7 +486,7 @@ @implementation TTIconTableFieldCell
+ (CGFloat)tableView:(UITableView*)tableView rowHeightForItem:(id)item {
TTImageTableField* field = item;
- UIImage* image = field.image ? [[TTURLCache sharedCache] getMediaForURL:field.image] : nil;
+ UIImage* image = field.image ? [[TTURLCache sharedCache] imageForURL:field.image] : nil;
CGFloat iconWidth = image
? image.size.width + kKeySpacing
@@ -525,7 +525,7 @@ - (void)layoutSubviews {
[super layoutSubviews];
TTImageTableField* field = self.object;
- UIImage* image = field.image ? [[TTURLCache sharedCache] getMediaForURL:field.image] : nil;
+ UIImage* image = field.image ? [[TTURLCache sharedCache] imageForURL:field.image] : nil;
if (_iconView.url) {
CGFloat iconWidth = image
@@ -573,7 +573,7 @@ - (void)layoutSubviews {
[super layoutSubviews];
TTImageTableField* field = self.object;
- UIImage* image = field.image ? [[TTURLCache sharedCache] getMediaForURL:field.image] : nil;
+ UIImage* image = field.image ? [[TTURLCache sharedCache] imageForURL:field.image] : nil;
CGFloat iconWidth = image
? image.size.width
@@ -22,9 +22,6 @@ - (id)init {
}
- (void)dealloc {
- [_dataSource.delegates removeObject:self];
- [_dataSource release];
- [_statusDataSource release];
[super dealloc];
}
@@ -57,7 +57,7 @@ - (NSMutableArray*)delegates {
return _delegates;
}
-- (NSDate*)loadedTimestamp {
+- (NSDate*)loadedTime {
return nil;
}
@@ -74,8 +74,8 @@ - (BOOL)loaded {
}
- (BOOL)needsReload {
- if (self.loadedTimestamp) {
- return -[self.loadedTimestamp timeIntervalSinceNow] > TT_DEFAULT_CACHE_EXPIRATION_AGE;
+ if (self.loadedTime) {
+ return -[self.loadedTime timeIntervalSinceNow] > TT_DEFAULT_CACHE_EXPIRATION_AGE;
} else {
return NO;
}
@@ -137,7 +137,7 @@ - (void)showObject:(id<TTObject>)object inView:(NSString*)viewType withState:(NS
- (void)updateContent {
if (_photoSource.loading) {
self.contentState = TTContentActivity;
- } else if (_photoSource.isInvalid) {
+ } else if (_photoSource.invalid) {
[self loadPhotosFromIndex:0 toIndex:TT_INFINITE_PHOTO_INDEX fromCache:YES];
} else if (_photoSource.numberOfPhotos) {
self.contentState = TTContentReady;
@@ -147,7 +147,7 @@ - (void)updateContent {
}
- (void)refreshContent {
- if (_photoSource.isInvalid && !_photoSource.loading) {
+ if (_photoSource.invalid && !_photoSource.loading) {
[self loadPhotosFromIndex:0 toIndex:TT_INFINITE_PHOTO_INDEX fromCache:NO];
}
}
Oops, something went wrong.

0 comments on commit 6eb7ec5

Please sign in to comment.