Advertisement
Guest User

MyViewController.m

a guest
Feb 22nd, 2013
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  MyViewController.m
  3.  
  4. // Attention:
  5. //  MyViewController.h <UIAlertViewDelegate>
  6.  
  7. #import "MyViewController.h"
  8. #import "MyAppDelegate.h"
  9. #import "MySync.h"
  10.  
  11. @interface MyViewController ()
  12.  
  13. @end
  14.  
  15. @implementation MyViewController {
  16.     UIAlertView *alertViewFirstSync;
  17.     UIAlertView *alertViewWait;
  18.     UIAlertView *alertViewDownload;
  19.     UIProgressView *progressView;
  20. }
  21.  
  22. - (void)viewDidLoad
  23. {
  24.     [self checkSync];
  25.     [super viewDidLoad];
  26.     // Do any additional setup after loading the view, typically from a nib.
  27. }
  28.  
  29. - (void)didReceiveMemoryWarning
  30. {
  31.     [super didReceiveMemoryWarning];
  32.     // Dispose of any resources that can be recreated.
  33. }
  34.  
  35. - (IBAction)gotoCategories:(id)sender
  36. {
  37.     [MyAppDelegate openStoryboardByName:self name:@"CategoriesStoryboard"];
  38. }
  39.  
  40.  
  41.  
  42. - (void)checkSync
  43. {
  44.     BOOL firstSyncComplete = [[NSUserDefaults standardUserDefaults] boolForKey:@"firstSyncComplete"];
  45.    
  46.     if (firstSyncComplete == TRUE) {
  47.         //pending...
  48.     } else {
  49.         [self firstSync];
  50.     }
  51. }
  52.  
  53. - (void)firstSync
  54. {
  55.     alertViewFirstSync = [[UIAlertView alloc] initWithTitle:@"Atención" message:@"The App need sync" delegate:self cancelButtonTitle:FALSE otherButtonTitles:@"OK", nil];
  56.    
  57.     [alertViewFirstSync show];
  58. }
  59.  
  60. - (void)alertView:(UIAlertView *)alertViewFirstSync clickedButtonAtIndex:(NSInteger)buttonIndex
  61. {
  62.     if (buttonIndex == 0) {
  63.         [alertViewFirstSync dismissWithClickedButtonIndex:buttonIndex animated:TRUE];
  64.         [self sync];
  65.     }
  66. }
  67.  
  68. - (void)sync
  69. {
  70.     alertViewWait = [[UIAlertView alloc] initWithTitle:@"Information" message:@"Connecting... please wait..." delegate:nil cancelButtonTitle:FALSE otherButtonTitles:FALSE, nil];
  71.    
  72.     UIActivityIndicatorView *activityIndicatorView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(130.0, 85.0, 20.0, 20.0)];
  73.     [activityIndicatorView startAnimating];
  74.     [alertViewWait addSubview:activityIndicatorView];
  75.    
  76.     [alertViewWait show];
  77.     [self startSync];
  78. }
  79.  
  80. - (void)startSync
  81. {
  82.     progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
  83.     [progressView setFrame:CGRectMake(30, 100, 225, 20)];
  84.    
  85.     [[MySync alloc] start:self progressView:progressView];
  86. }
  87.  
  88. - (void)syncJSonComplete
  89. {    
  90.     [self performSelector:@selector(dismissAlertView:) withObject:alertViewWait afterDelay:0.2];
  91.     [self performSelector:@selector(showAlertViewDownload) withObject:nil afterDelay:0.3];
  92. }
  93.  
  94. - (void)showAlertViewDownload
  95. {
  96.     alertViewDownload = [[UIAlertView alloc] initWithTitle:@"Downloading" message:@"Please wait..." delegate:nil cancelButtonTitle:FALSE otherButtonTitles:FALSE, nil];
  97.     [alertViewDownload addSubview:progressView];
  98.    
  99.     [alertViewDownload show];
  100. }
  101.  
  102. - (void)syncComplete
  103. {
  104.     NSLog(@"SynComplete on ViewController");
  105.     [self performSelector:@selector(dismissAlertView:) withObject:alertViewDownload afterDelay:0.5];
  106. }
  107.  
  108. - (void)setProgressView:(float)progress
  109. {
  110.     [progressView setProgress:progress];
  111. }
  112.  
  113. - (void)dismissAlertView:(UIAlertView *)alertView
  114. {
  115.     NSLog(@"dismiss alertview");
  116.     [alertView dismissWithClickedButtonIndex:0 animated:TRUE];
  117.     alertView = nil;
  118. }
  119.  
  120. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement