Skip to content

Commit

Permalink
Merge pull request facebookarchive#749 from aporat/tterrorview-button
Browse files Browse the repository at this point in the history
[UI] Reload buttons in TTTableViewController error views
  • Loading branch information
Adar Porat committed Jan 20, 2012
2 parents 5560bcb + aba9621 commit c167505
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 3 deletions.
Binary file added src/Three20.bundle/images/reloadButton.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/Three20.bundle/images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/Three20.bundle/images/reloadButtonActive.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/Three20.bundle/images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions src/Three20Style/Sources/TTDefaultStyleSheet.m
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,24 @@ - (UIColor*)searchTableSeparatorColor {
return [UIColor colorWithWhite:0.85 alpha:1];
}

///////////////////////////////////////////////////////////////////////////////////////////////////
- (TTStyle*)tableReloadButton:(UIControlState)state {
if (state == UIControlStateHighlighted) {
return
[TTImageStyle styleWithImageURL:@"bundle://Three20.bundle/images/reloadButtonActive.png"
defaultImage:nil
contentMode:UIViewContentModeCenter
size:CGSizeMake(50,50) next:nil];

} else {
return
[TTImageStyle styleWithImageURL:@"bundle://Three20.bundle/images/reloadButton.png"
defaultImage:nil
contentMode:UIViewContentModeCenter
size:CGSizeMake(50,50) next:nil];
}
}


///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
15 changes: 13 additions & 2 deletions src/Three20UI/Headers/TTErrorView.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,30 @@
// limitations under the License.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
// UI
#import "Three20UI/TTButton.h"

@interface TTErrorView : UIView {
UIImageView* _imageView;
UILabel* _titleView;
UILabel* _subtitleView;
TTButton* _reloadButton;
}

@property (nonatomic, retain) UIImage* image;
@property (nonatomic, copy) NSString* title;
@property (nonatomic, copy) NSString* subtitle;
@property (nonatomic, copy) TTButton* reloadButton;


/**
* creates an error view
*/
- (id)initWithTitle:(NSString*)title subtitle:(NSString*)subtitle image:(UIImage*)image;

/**
* adds a reload button into the error view
*/
- (void)addReloadButton;

@end
6 changes: 6 additions & 0 deletions src/Three20UI/Headers/TTTableViewDataSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@

- (NSString*)subtitleForEmpty;


/**
* return YES to include a reload button in the TTErrorView.
*/
- (BOOL)reloadButtonForEmpty;

- (UIImage*)imageForError:(NSError*)error;

- (NSString*)titleForError:(NSError*)error;
Expand Down
27 changes: 26 additions & 1 deletion src/Three20UI/Sources/TTErrorView.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
#import "Three20Core/TTCorePreprocessorMacros.h"

static const CGFloat kVPadding1 = 30.0f;
static const CGFloat kVPadding2 = 20.0f;
static const CGFloat kVPadding2 = 10.0f;
static const CGFloat kVPadding3 = 15.0f;
static const CGFloat kHPadding = 10.0f;


Expand All @@ -36,6 +37,20 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
@implementation TTErrorView

@synthesize reloadButton = _reloadButton;


///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)addReloadButton {
_reloadButton = [[TTButton buttonWithStyle:@"tableReloadButton:"] retain];
[_reloadButton setImage:@"bundle://Three20.bundle/images/reloadButton.png"
forState:UIControlStateNormal];
[_reloadButton sizeToFit];
[self addSubview:_reloadButton];

[self layoutSubviews];
}


///////////////////////////////////////////////////////////////////////////////////////////////////
- (id)initWithTitle:(NSString*)title subtitle:(NSString*)subtitle image:(UIImage*)image {
Expand Down Expand Up @@ -83,6 +98,7 @@ - (void)dealloc {
TT_RELEASE_SAFELY(_imageView);
TT_RELEASE_SAFELY(_titleView);
TT_RELEASE_SAFELY(_subtitleView);
TT_RELEASE_SAFELY(_reloadButton);

[super dealloc];
}
Expand Down Expand Up @@ -116,6 +132,8 @@ - (void)layoutSubviews {
totalHeight += (totalHeight ? kVPadding2 : 0) + _subtitleView.height;
}

totalHeight += (totalHeight ? kVPadding3 : 0) + _reloadButton.height;

CGFloat top = floor(self.height/2 - totalHeight/2);

if (canShowImage) {
Expand All @@ -132,6 +150,11 @@ - (void)layoutSubviews {
}
if (_subtitleView.text.length) {
_subtitleView.origin = CGPointMake(floor(self.width/2 - _subtitleView.width/2), top);
top += _subtitleView.height + kVPadding3;
}

if (_reloadButton!=nil) {
_reloadButton.origin = CGPointMake(floor(self.width/2 - _reloadButton.width/2), top);
}
}

Expand Down Expand Up @@ -178,4 +201,6 @@ - (void)setImage:(UIImage*)image {
}




@end
7 changes: 7 additions & 0 deletions src/Three20UI/Sources/TTTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,14 @@ - (void)showError:(BOOL)show {
TTErrorView* errorView = [[[TTErrorView alloc] initWithTitle:title
subtitle:subtitle
image:image] autorelease];
if ([_dataSource reloadButtonForEmpty]) {
[errorView addReloadButton];
[errorView.reloadButton addTarget:self
action:@selector(reload)
forControlEvents:UIControlEventTouchUpInside];
}
errorView.backgroundColor = _tableView.backgroundColor;

self.errorView = errorView;

} else {
Expand Down
6 changes: 6 additions & 0 deletions src/Three20UI/Sources/TTTableViewDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,12 @@ - (NSString*)subtitleForEmpty {
}


///////////////////////////////////////////////////////////////////////////////////////////////////
- (BOOL)reloadButtonForEmpty {
return YES;
}


///////////////////////////////////////////////////////////////////////////////////////////////////
- (UIImage*)imageForError:(NSError*)error {
return nil;
Expand Down
6 changes: 6 additions & 0 deletions src/Three20UI/Sources/TTThumbsDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ - (NSString*)subtitleForEmpty {
}


///////////////////////////////////////////////////////////////////////////////////////////////////
- (BOOL)reloadButtonForEmpty {
return NO;
}


///////////////////////////////////////////////////////////////////////////////////////////////////
- (UIImage*)imageForError:(NSError*)error {
return TTIMAGE(@"bundle://Three20.bundle/images/photoDefault.png");
Expand Down

0 comments on commit c167505

Please sign in to comment.