Browse Source

add pull to refresh network

Signed-off-by: Felix Paul Kühne <fkuehne@videolan.org>
Pierre SAGASPE 11 years ago
parent
commit
cc9acf2ca2
1 changed files with 29 additions and 0 deletions
  1. 29 0
      AspenProject/VLCLocalServerListViewController.m

+ 29 - 0
AspenProject/VLCLocalServerListViewController.m

@@ -32,6 +32,8 @@
     NSArray *_UPNPdevices;
 
     VLCNetworkLoginViewController *_loginViewController;
+
+    UIRefreshControl *refreshControl;
 }
 
 @end
@@ -74,6 +76,14 @@
 
     _netServiceBrowser = [[NSNetServiceBrowser alloc] init];
     _netServiceBrowser.delegate = self;
+
+    // Active le Pull down to refresh
+    refreshControl = [[UIRefreshControl alloc] init];
+
+    // call the refresh function
+    [refreshControl addTarget:self action:@selector(handleRefresh) forControlEvents:UIControlEventValueChanged];
+    [self.tableView addSubview:refreshControl];
+
 }
 
 - (void)viewWillDisappear:(BOOL)animated
@@ -224,6 +234,25 @@
     }
 }
 
+#pragma mark - Refresh
+
+-(void)handleRefresh
+{
+    //set the title while refreshing
+    refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refresh"];
+    //set the date and time of refreshing
+    NSDateFormatter *formattedDate = [[NSDateFormatter alloc]init];
+    [formattedDate setDateFormat:@"MMM d, h:mm a"];
+    NSString *lastupdated = [NSString stringWithFormat:@"Last Updated on %@",[formattedDate stringFromDate:[NSDate date]]];
+    refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:lastupdated];
+    //end the refreshing
+    [refreshControl endRefreshing];
+
+    [self.tableView reloadData];
+
+    [self performSelectorInBackground:@selector(_startUPNPDiscovery) withObject:nil];
+}
+
 #pragma mark - login panel protocol
 
 - (void)loginToURL:(NSURL *)url confirmedWithUsername:(NSString *)username andPassword:(NSString *)password