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

Fix run/stop on iPhone

parent 7da23fdd
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,7 @@
@interface AppDelegate : UIResponder <UIApplicationDelegate>{
@public
bool compute;
}
@property (strong, nonatomic) UIWindow *window;
......
......@@ -14,10 +14,12 @@
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"iPadStoryboard" bundle:nil];
self.modelListController = (ModelListController *)self.window.rootViewController;
if([[UIDevice currentDevice].model isEqualToString:@"iPad"] || [[UIDevice currentDevice].model isEqualToString:@"iPad Simulator"])
if([[UIDevice currentDevice].model isEqualToString:@"iPad"] || [[UIDevice currentDevice].model isEqualToString:@"iPad Simulator"]) {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"iPadStoryboard" bundle:nil];
self.splitViewController = [storyboard instantiateViewControllerWithIdentifier:@"SplitViewController"];
}
compute = false;
return YES;
}
......
......@@ -125,6 +125,12 @@
- (void) showModelsList
{
if(((AppDelegate *)[UIApplication sharedApplication].delegate)->compute) {
UIAlertView *alert;
alert = [[UIAlertView alloc] initWithTitle:@"Can't show the models list" message:@"The compute have to be finished before you can select an other model." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
return;
}
if([[UIDevice currentDevice].model isEqualToString:@"iPad"] || [[UIDevice currentDevice].model isEqualToString:@"iPad Simulator"]){
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
[UIView transitionWithView:appDelegate.window
......
......@@ -8,6 +8,7 @@
#import "MasterViewController.h"
#import "DetailViewController.h"
#import "AppDelegate.h"
#import "parameter.h"
@interface MasterViewController () {
......@@ -30,8 +31,16 @@
// Do any additional setup after loading the view, typically from a nib.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshParameters:) name:@"refreshParameters" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resetParameters:) name:@"resetParameters" object:nil];
runButton = [[UIBarButtonItem alloc] initWithTitle:@"Run" style:UIBarButtonItemStyleBordered target:self action:@selector(runWithNewParameter)];
[runButton setTitle:@"Run"];
if(((AppDelegate *)[UIApplication sharedApplication].delegate)->compute){ // Only on iPhone/iPod
runButton = [[UIBarButtonItem alloc] initWithTitle:@"Stop" style:UIBarButtonItemStyleBordered target:self action:@selector(stopRunning)];
[runButton setTitle:@"Stop"];
}
else {
runButton = [[UIBarButtonItem alloc] initWithTitle:@"Run" style:UIBarButtonItemStyleBordered target:self action:@selector(runWithNewParameter)];
[runButton setTitle:@"Run"];
}
self.navigationItem.leftItemsSupplementBackButton = YES; // Only on iPhone/iPod
self.navigationItem.leftBarButtonItem = runButton;
UIBarButtonItem *refresh = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(resetParameters:)];
......@@ -175,17 +184,21 @@
- (void)runWithNewParameter
{
dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ // TODO fix Run/Stop for iPhone
dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
appDelegate->compute = YES;
[runButton setTitle:@"Stop"];
[self.view setNeedsDisplay];
[runButton setAction:@selector(stopRunning)];
self.navigationItem.rightBarButtonItem.enabled = NO;
onelab_cb("compute");
[runButton setTitle:@"Run"];
[self.view setNeedsDisplay];
[runButton setAction:@selector(runWithNewParameter)];
self.navigationItem.rightBarButtonItem.enabled = YES;
//[[NSNotificationCenter defaultCenter] postNotificationName:@"refreshParameters" object:nil];
if([[UIDevice currentDevice].model isEqualToString:@"iPad"] || [[UIDevice currentDevice].model isEqualToString:@"iPad Simulator"]){
[runButton setTitle:@"Run"];
[self.view setNeedsDisplay];
[runButton setAction:@selector(runWithNewParameter)];
self.navigationItem.rightBarButtonItem.enabled = YES;
}
appDelegate->compute = NO;
});
if(![[UIDevice currentDevice].model isEqualToString:@"iPad"] && ![[UIDevice currentDevice].model isEqualToString:@"iPad Simulator"])
[self.navigationController popViewControllerAnimated:YES];
......@@ -194,6 +207,10 @@
- (void)stopRunning
{
onelab_cb("stop");
if(![[UIDevice currentDevice].model isEqualToString:@"iPad"] && ![[UIDevice currentDevice].model isEqualToString:@"iPad Simulator"]){
((AppDelegate *)[UIApplication sharedApplication].delegate)->compute = NO;
[self.navigationController popViewControllerAnimated:YES];
}
}
#pragma mark - Table View
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment