Skip to content

Commit

Permalink
Later #132, #119 : Add Progress and removed EGORefreshTableHeaderView.
Browse files Browse the repository at this point in the history
  • Loading branch information
patricksan committed Apr 16, 2012
1 parent ed6b013 commit d0335c8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 76 deletions.
21 changes: 20 additions & 1 deletion OpenPhoto/GalleryViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

#import "GalleryViewController.h"

@interface GalleryViewController()
- (void) loadImages;
@end

@implementation GalleryViewController
@synthesize service=_service, tagName=_tagName;

Expand Down Expand Up @@ -78,11 +82,22 @@ -(void) viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

UIBarButtonItem *refreshButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(loadImages)];
self.navigationItem.rightBarButtonItem = refreshButton;
[refreshButton release];

[self loadImages];
}

- (void) loadImages{
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
hud.labelText = @"Loading";

if (self.tagName != nil){
[self.service loadGallery:24 withTag:self.tagName onPage:1];
}else{
[self.service loadGallery:24 onPage:1];
}
}
}

- (void)viewDidLoad
Expand All @@ -94,6 +109,8 @@ - (void)viewDidLoad

// delegate
-(void) receivedResponse:(NSDictionary *)response{
[MBProgressHUD hideHUDForView:self.navigationController.view animated:YES];

// check if message is valid
if (![WebService isMessageValid:response]){
NSString* message = [WebService getResponseMessage:response];
Expand Down Expand Up @@ -181,7 +198,9 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
}

- (void) notifyUserNoInternet{
[MBProgressHUD hideHUDForView:self.navigationController.view animated:YES];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

// problem with internet, show message to user
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Internet error" message:@"Couldn't reach the server. Please, check your internet connection" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
Expand Down
9 changes: 1 addition & 8 deletions OpenPhoto/TagViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,8 @@
#import "TSAlertView.h"
#import "OpenPhotoServiceFactory.h"
#import "MBProgressHUD.h"
#import "EGORefreshTableHeaderView.h"

@interface TagViewController : UITableViewController<TSAlertViewDelegate, EGORefreshTableHeaderDelegate>{
EGORefreshTableHeaderView *_refreshHeaderView;

// Reloading var should really be your tableviews datasource
// Putting it here for demo purposes
BOOL _reloading;

@interface TagViewController : UITableViewController<TSAlertViewDelegate>{
NSMutableArray *tags;
}

Expand Down
74 changes: 7 additions & 67 deletions OpenPhoto/TagViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ - (id)initWithStyle:(UITableViewStyle)style
-(void) dealloc
{
[self.tags release];
[_refreshHeaderView release];
[super dealloc];
}
- (void) setReadOnly
Expand Down Expand Up @@ -106,10 +105,15 @@ -(void) viewWillAppear:(BOOL)animated
// Uncomment the following line to preserve selection between presentations.
self.clearsSelectionOnViewWillAppear = NO;

UIBarButtonItem *refreshButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(loadTags)];
self.navigationItem.rightBarButtonItem = refreshButton;
[refreshButton release];


// wanna add new tag name
if (self.readOnly == YES){
UIBarButtonItem *addNewTagButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addNewTag)];
self.navigationItem.rightBarButtonItem = addNewTagButton;
self.navigationItem.leftBarButtonItem = addNewTagButton;
[addNewTagButton release];

if ([self.tags count] == 0 ){
Expand All @@ -131,24 +135,6 @@ - (void)viewDidLoad

// set the tile of the table
self.title=@"Tags";

if (_refreshHeaderView == nil) {

EGORefreshTableHeaderView *view = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(0.0f, 0.0f - self.tableView.bounds.size.height, self.view.frame.size.width, self.tableView.bounds.size.height) arrowImageName:@"OpenPhotobrownRoundedArrow.png" textColor:UIColorFromRGB(0xC8BEA0)];
view.delegate = self;

// set background
view.backgroundColor = [UIColor clearColor];
view.opaque = NO;

[self.tableView addSubview:view];
_refreshHeaderView = view;
[view release];

}

// update the last update date
[_refreshHeaderView refreshLastUpdatedDate];
}

-(void) addNewTag
Expand Down Expand Up @@ -267,10 +253,9 @@ - (void) loadTags
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Internet error" message:@"Couldn't reach the server. Please, check your internet connection" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
[alert release];
[self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:1.0];
}else {
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
hud.labelText = @"Loading ";
hud.labelText = @"Loading";

dispatch_queue_t loadTags = dispatch_queue_create("loadTags", NULL);
dispatch_async(loadTags, ^{
Expand Down Expand Up @@ -309,19 +294,13 @@ - (void) loadTags
#endif
[MBProgressHUD hideHUDForView:self.navigationController.view animated:YES];

// refresh table
[self doneLoadingTableViewData];
});
}@catch (NSException *exception) {
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUDForView:self.navigationController.view animated:YES];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:exception.description delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
[alert release];

// refresh table
[self doneLoadingTableViewData];

});
}
});
Expand All @@ -330,49 +309,10 @@ - (void) loadTags

}

- (void)doneLoadingTableViewData
{
_reloading = NO;
[_refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:self.tableView];
}

#pragma mark -
#pragma mark UIScrollViewDelegate Methods

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{

[_refreshHeaderView egoRefreshScrollViewDidScroll:scrollView];

}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{

[_refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView];

}

#pragma mark -
#pragma mark EGORefreshTableHeaderDelegate Methods

- (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView*)view{
// via GCD, get tall tags
[self loadTags];
}

- (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView*)view
{
return _reloading; // should return if data source model is reloading
}

- (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView*)view
{
return [NSDate date]; // should return date data source was last changed
}

- (void)viewDidUnload
{
[super viewDidUnload];
_refreshHeaderView=nil;
}

@end

0 comments on commit d0335c8

Please sign in to comment.