-
Notifications
You must be signed in to change notification settings - Fork 2
/
SynchViewController.m
executable file
·113 lines (91 loc) · 3.45 KB
/
SynchViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//
// SynchViewController.m
// searchbar
//
// Created by Jeremy Gould on 12/8/13.
// Copyright (c) 2013 mmai. All rights reserved.
//
#import "SynchViewController.h"
@interface SynchViewController ()
@end
@implementation SynchViewController
@synthesize activity;
@synthesize textOut;
@synthesize delegate;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
delegate = (macroinvAppDelegate *) [[UIApplication sharedApplication] delegate]; // to refer to AppDelegate methods
}
- (IBAction)goClicked:(id)sender {
//textOut.text = @"Connecting to Server...";
//NSLog(@"GO");
//[activity startAnimating]; // Start the spinner
//textOut.text = @"Getting Invertebrate Data...";
//NSLog(@"BUGS");
//[delegate.webData synchBugs: activity with: textOut];
//NSLog(@"STREAMS");
//textOut.text = @"Getting Stream Data...";
//[delegate.webData synchStreams: activity with: textOut];
//[activity stopAnimating]; // stop spinner
//textOut.text = @"Process Complete";
[self triggerSynch];
}
- (void) triggerSynch{
//pjc - fix - Figure out how to update label with sync status
[NSThread detachNewThreadSelector:@selector(threadStartAnimating:) toTarget:self withObject:nil];
//pjc - Prevent device from sleeping and terminating sync
[UIApplication sharedApplication].idleTimerDisabled = YES;
//[activity startAnimating];
//[delegate.webData setFeedbackLabel:textOut];
[textOut setNumberOfLines:2];
[textOut setText:@"Getting Invertebrate Data"];
[[self view] setNeedsDisplay];
[delegate.webData synchBugs];
[textOut setText:@"Getting Stream Data"];
BOOL success = [delegate.webData synchStreams];
if(success){
[textOut setText:@"Sync Complete."];
UIAlertView * alert =[[UIAlertView alloc ] initWithTitle:@"Sync Complete"
message:@"Congratulations, Sync Complete"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alert show];
}
else{
[textOut setText:@"Sync Failed.\nCheck Network Connection."];
UIAlertView * alert =[[UIAlertView alloc ] initWithTitle:@"Sync Failed"
message:@"We apologize. Sync failed. Please check Network Connection and try again"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alert show];
}
[NSThread detachNewThreadSelector:@selector(threadStopAnimating:) toTarget:self withObject:nil];
[UIApplication sharedApplication].idleTimerDisabled = NO;
}
- (void) threadStartAnimating:(id)data {
[activity startAnimating];
}
- (void) threadStopAnimating:(id)data {
[activity stopAnimating];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (UILabel *)getLabel {
return textOut;
}
@end