Skip to content
Snippets Groups Projects
Commit 42a4a6a0 authored by Maxime Graulich's avatar Maxime Graulich
Browse files

iOS: Open the link associate to a model in a browser

parent 4745b942
No related branches found
No related tags found
No related merge requests found
...@@ -15,9 +15,12 @@ ...@@ -15,9 +15,12 @@
@implementation ModelListController @implementation ModelListController
-(void)viewDidLoad -(void)viewDidLoad
{ {
UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
lpgr.minimumPressDuration = 1.0;
[self.tableView addGestureRecognizer:lpgr];
models = [[NSMutableArray alloc] init]; models = [[NSMutableArray alloc] init];
NSString *docsPath = [Utils getApplicationDocumentsDirectory]; NSString *docsPath = [Utils getApplicationDocumentsDirectory];
[Utils copyRes]; [Utils copyRes];
NSArray *docs = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:docsPath error:NULL]; NSArray *docs = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:docsPath error:NULL];
for(NSString* doc in docs){ for(NSString* doc in docs){
...@@ -54,6 +57,11 @@ ...@@ -54,6 +57,11 @@
[cell.textLabel setText:[m getName]]; [cell.textLabel setText:[m getName]];
if([m getSummary] != nil) [cell.detailTextLabel setText:[m getSummary]]; if([m getSummary] != nil) [cell.detailTextLabel setText:[m getSummary]];
if([m getPreview] != nil) cell.imageView.image = [m getPreview]; if([m getPreview] != nil) cell.imageView.image = [m getPreview];
if([m getFile] == nil) {
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.userInteractionEnabled = NO;
cell.textLabel.alpha = 0.75;
}
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell; return cell;
} }
...@@ -78,6 +86,31 @@ ...@@ -78,6 +86,31 @@
[self performSegueWithIdentifier:@"showModelSegue" sender:self]; [self performSegueWithIdentifier:@"showModelSegue" sender:self];
} }
} }
-(void)handleLongPress:(UILongPressGestureRecognizer *)sender
{
CGPoint p = [sender locationInView:self.tableView];
if(sender.state == UIGestureRecognizerStateCancelled) return;
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:p];
if(indexPath == nil) return;
UIActionSheet *actionSheet;
if([[models objectAtIndex:indexPath.row] getUrl])
actionSheet = [[UIActionSheet alloc] initWithTitle:[[models objectAtIndex:indexPath.row] getName] delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles: @"Open this models", @"More informations", nil];
else
actionSheet = [[UIActionSheet alloc] initWithTitle:[[models objectAtIndex:indexPath.row] getName] delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles: @"Open this models", nil];
actionSheet.tag = indexPath.row;
[actionSheet showInView:self.view];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
switch (buttonIndex) {
case 1:
[[UIApplication sharedApplication] openURL:[[models objectAtIndex:actionSheet.tag] getUrl]];
break;
case 0:
[self tableView:self.tableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:actionSheet.tag inSection:0]];
break;
}
}
- (BOOL) parseInfosFile:(NSString *)file - (BOOL) parseInfosFile:(NSString *)file
{ {
NSData *xmlFile = [[NSFileManager defaultManager] contentsAtPath:file]; NSData *xmlFile = [[NSFileManager defaultManager] contentsAtPath:file];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment