From d0335c8839242b706dc7c81dda3fb149b49ba3ca Mon Sep 17 00:00:00 2001 From: Patrick Santana Date: Mon, 16 Apr 2012 14:15:03 +0200 Subject: [PATCH] Later #132, #119 : Add Progress and removed EGORefreshTableHeaderView. --- OpenPhoto/GalleryViewController.m | 21 ++++++++- OpenPhoto/TagViewController.h | 9 +--- OpenPhoto/TagViewController.m | 74 +++---------------------------- 3 files changed, 28 insertions(+), 76 deletions(-) diff --git a/OpenPhoto/GalleryViewController.m b/OpenPhoto/GalleryViewController.m index 8d85ce4..a4b4618 100644 --- a/OpenPhoto/GalleryViewController.m +++ b/OpenPhoto/GalleryViewController.m @@ -19,6 +19,10 @@ #import "GalleryViewController.h" +@interface GalleryViewController() +- (void) loadImages; +@end + @implementation GalleryViewController @synthesize service=_service, tagName=_tagName; @@ -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 @@ -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]; @@ -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]; diff --git a/OpenPhoto/TagViewController.h b/OpenPhoto/TagViewController.h index 6d6ed58..60a40a6 100644 --- a/OpenPhoto/TagViewController.h +++ b/OpenPhoto/TagViewController.h @@ -22,15 +22,8 @@ #import "TSAlertView.h" #import "OpenPhotoServiceFactory.h" #import "MBProgressHUD.h" -#import "EGORefreshTableHeaderView.h" -@interface TagViewController : UITableViewController{ - EGORefreshTableHeaderView *_refreshHeaderView; - - // Reloading var should really be your tableviews datasource - // Putting it here for demo purposes - BOOL _reloading; - +@interface TagViewController : UITableViewController{ NSMutableArray *tags; } diff --git a/OpenPhoto/TagViewController.m b/OpenPhoto/TagViewController.m index e5ff74c..d21c6f6 100644 --- a/OpenPhoto/TagViewController.m +++ b/OpenPhoto/TagViewController.m @@ -51,7 +51,6 @@ - (id)initWithStyle:(UITableViewStyle)style -(void) dealloc { [self.tags release]; - [_refreshHeaderView release]; [super dealloc]; } - (void) setReadOnly @@ -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 ){ @@ -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 @@ -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, ^{ @@ -309,8 +294,6 @@ - (void) loadTags #endif [MBProgressHUD hideHUDForView:self.navigationController.view animated:YES]; - // refresh table - [self doneLoadingTableViewData]; }); }@catch (NSException *exception) { dispatch_async(dispatch_get_main_queue(), ^{ @@ -318,10 +301,6 @@ - (void) loadTags UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:exception.description delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [alert show]; [alert release]; - - // refresh table - [self doneLoadingTableViewData]; - }); } }); @@ -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 \ No newline at end of file