Advertisement
Oshevnev

Untitled

Jul 25th, 2012
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  BsuirHelperVCSchedule.m
  3. //  BSUIR Helper
  4. //
  5. //  Created by Alex Oshevnev on 7/16/12.
  6. //  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
  7. //
  8.  
  9. #import <QuartzCore/QuartzCore.h>
  10. #import "BsuirHelperVCSchedule.h"
  11. #import "SystemConfiguration/SystemConfiguration.h"
  12. #import "TFHpple.h"
  13.  
  14. @interface BsuirHelperVCSchedule ()
  15.  
  16. @end
  17.  
  18. @implementation BsuirHelperVCSchedule
  19. @synthesize TextLabelWeek;
  20. @synthesize refreshProtocol;
  21.  
  22. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  23. {
  24.     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  25.     if (self) {
  26.         // Custom initialization
  27.     }
  28.     return self;
  29. }
  30.  
  31. - (void)viewDidLoad
  32. {
  33.     // Divarication
  34.     if (![[NSUserDefaults standardUserDefaults]valueForKey:@"groupValue"]) {
  35.         [self performSegueWithIdentifier: @"StoryboardSegueSecondLaunch" sender: self];
  36.     }
  37.     else {
  38.         // Change TextLaberWeek
  39.        
  40.         SCNetworkReachabilityFlags flags;
  41.         BOOL receivedFlags;
  42.        
  43.         SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(CFAllocatorGetDefault(), [@"google.com" UTF8String]);
  44.         receivedFlags = SCNetworkReachabilityGetFlags(reachability, &flags);
  45.         CFRelease(reachability);
  46.        
  47.         if ((receivedFlags && (flags != 0)) && ![[[NSUserDefaults standardUserDefaults] valueForKey:@"numberWeek"] objectForKey:@"numberWeek"]) {
  48.             [refreshProtocol getNumberWeek];
  49.         }
  50.         else {
  51.             [refreshProtocol recalculateNumberWeek];
  52.         }
  53.         TextLabelWeek.text = [[[NSUserDefaults standardUserDefaults] valueForKey:@"numberWeek"] objectForKey:@"numberWeek"];
  54.     }
  55.      
  56.     self.refreshProtocol = [[BsuirHelperRefreshDelegate new] autorelease];
  57.     self.refreshProtocol.delegate = self;
  58.     [super viewDidLoad];
  59.     // Do any additional setup after loading the view.
  60. }
  61.  
  62. - (void)viewDidUnload
  63. {
  64.     [self setTextLabelWeek:nil];
  65.     [super viewDidUnload];
  66.     // Release any retained subviews of the main view.
  67. }
  68.  
  69. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  70. {
  71.     return (interfaceOrientation == UIInterfaceOrientationPortrait);
  72. }
  73.  
  74. // Table
  75. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  76. {
  77.     return [[self.refreshProtocol returnDataForTable] count];
  78. }
  79.  
  80. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  81. {
  82.     NSArray *curent = [self curent:section];
  83.     return [curent count];
  84. }
  85.  
  86. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  87.     return [[[self.refreshProtocol returnDataForTable] allKeys] objectAtIndex:section];
  88. }
  89.  
  90. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  91. {
  92.     static NSString *CellIdentifier = @"Cell";
  93.    
  94.     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  95.     if (cell == nil) {
  96.         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
  97.                                        reuseIdentifier:CellIdentifier] autorelease];
  98.     }
  99.    
  100.     NSArray *curent = [self curent:indexPath.section];
  101.     cell.textLabel.text = [curent objectAtIndex:indexPath.row];
  102.    
  103.     return cell;
  104. }
  105.  
  106. - (NSArray *)curent:(NSInteger)index {
  107.     NSArray *keys = [[self.refreshProtocol returnDataForTable] allKeys];
  108.     NSString *curentKey = [keys objectAtIndex:index];
  109.     NSArray *curent = [[self.refreshProtocol returnDataForTable] objectForKey:curentKey];
  110.     return curent;
  111. }
  112.  
  113. // Buttons
  114. - (IBAction)BarButtonPageCurlAction:(id)sender {
  115.     [self performSegueWithIdentifier: @"StoryboardSegueSetting" sender: self];    
  116. }
  117.  
  118. - (IBAction)BarButtonRefreshAction:(id)sender {
  119.     if ([[[NSUserDefaults standardUserDefaults]valueForKey:@"groupValue"] length] != 6) {
  120.         [self performSegueWithIdentifier: @"StoryboardSegueSetting" sender: self];
  121.     } else {
  122.         SCNetworkReachabilityFlags flags;
  123.         BOOL receivedFlags;
  124.        
  125.         SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(CFAllocatorGetDefault(), [@"google.com" UTF8String]);
  126.         receivedFlags = SCNetworkReachabilityGetFlags(reachability, &flags);
  127.         CFRelease(reachability);
  128.        
  129.         UIAlertView *InternetDown = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_attentionTitle", nil)
  130.                                                                message:NSLocalizedString(@"_internetDownText", nil)
  131.                                                               delegate:self
  132.                                                      cancelButtonTitle:NSLocalizedString(@"_dismiss", nil)
  133.                                                      otherButtonTitles:nil];
  134.        
  135.        
  136.        
  137.         if (receivedFlags && (flags != 0)) {
  138.             [InternetDown release];
  139.             [refreshProtocol writeDB];
  140.         }
  141.         else {
  142.             [InternetDown show];
  143.             [InternetDown release];
  144.         }
  145.     }
  146. }
  147.  
  148. - (void)dealloc {
  149.     [TextLabelWeek release];
  150.     [super dealloc];
  151. }
  152. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement