Skip to content

Commit 54cee5f

Browse files
committed
Fixed transition process for new years
1 parent 8a8cc3f commit 54cee5f

File tree

7 files changed

+48
-6
lines changed

7 files changed

+48
-6
lines changed

iHW-iOS/iHW/iHW/IHWAppDelegate.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
2323
{
2424
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
2525

26+
if (![IHWCurriculum yearSetManually]) [IHWCurriculum updateCurrentYear];
27+
2628
// Override point for customization after application launch.
2729
UIViewController *rootVC = nil;
2830
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {

iHW-iOS/iHW/iHW/IHWChangeYearViewController.m

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#import "IHWCurriculum.h"
1111
#import "IHWAppDelegate.h"
1212
#import "IHWScheduleViewController.h"
13+
#import "IHWFirstRunViewController.h"
1314

1415
@implementation IHWChangeYearViewController
1516

@@ -145,7 +146,13 @@ - (void)viewWillDisappear:(BOOL)animated {
145146
[IHWCurriculum setCurrentCampus:self.selectedCampus];
146147
//Create a new schedule view controller
147148
//(this is not shown immediately -- instead, it appears behind the preferences view controller when the preferences view controller is dismissed)
148-
[((IHWAppDelegate *)[[UIApplication sharedApplication] delegate]).navController setViewControllers:@[[[IHWScheduleViewController alloc] initWithNibName:@"IHWScheduleViewController" bundle:nil]] animated:NO];
149+
if ([IHWCurriculum isFirstRun]) {
150+
IHWFirstRunViewController *frvc = [[IHWFirstRunViewController alloc] initWithNibName:@"IHWFirstRunViewController" bundle:nil];
151+
frvc.goingToStep2 = YES;
152+
[((IHWAppDelegate *)[[UIApplication sharedApplication] delegate]).navController setViewControllers:@[frvc] animated:NO];
153+
} else {
154+
[((IHWAppDelegate *)[[UIApplication sharedApplication] delegate]).navController setViewControllers:@[[[IHWScheduleViewController alloc] initWithNibName:@"IHWScheduleViewController" bundle:nil]] animated:NO];
155+
}
149156
}
150157
[super viewWillDisappear:animated];
151158
}

iHW-iOS/iHW/iHW/IHWCurriculum.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
+ (int)currentYear;
2525
+ (int)currentCampus;
2626
+ (void)setCurrentYear:(int)year;
27+
+ (void)updateCurrentYear;
28+
+ (BOOL)yearSetManually;
2729
+ (void)setCurrentCampus:(int)campus;
2830
+ (BOOL)isFirstRun;
2931

iHW-iOS/iHW/iHW/IHWCurriculum.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ + (int)currentCampus {
6161

6262
+ (void)setCurrentYear:(int)year {
6363
[[NSUserDefaults standardUserDefaults] setInteger:year forKey:@"currentYear"];
64+
[[NSUserDefaults standardUserDefaults] setInteger:[[IHWDate today] dateByAddingDays:-365/2].year forKey:@"manualYear"];
65+
}
66+
67+
+ (void)updateCurrentYear {
68+
[[NSUserDefaults standardUserDefaults] setInteger:[[IHWDate today] dateByAddingDays:-365/2].year forKey:@"currentYear"];
69+
[[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"manualYear"];
70+
}
71+
72+
+ (BOOL)yearSetManually {
73+
return ([[NSUserDefaults standardUserDefaults] integerForKey:@"manualYear"] == [[IHWDate today] dateByAddingDays:-365/2].year);
6474
}
6575

6676
+ (void)setCurrentCampus:(int)campus {

iHW-iOS/iHW/iHW/IHWFirstRunViewController.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@
1818
@property (weak, nonatomic) IBOutlet UIButton *manualButton;
1919
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topSpaceConstraint;
2020
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topSpaceConstraint2;
21+
@property BOOL goingToStep2;
22+
23+
- (void)gotoStep2;
2124

2225
@end

iHW-iOS/iHW/iHW/IHWFirstRunViewController.m

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#import "IHWDownloadScheduleViewController.h"
1313
#import "IHWGuidedCoursesViewController.h"
1414
#import "IHWDate.h"
15+
#import "IHWPreferencesViewController.h"
16+
#import "IHWChangeYearViewController.h"
1517

1618
@interface IHWFirstRunViewController ()
1719

@@ -24,7 +26,7 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
2426
{
2527
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
2628
if (self) {
27-
[IHWCurriculum setCurrentYear:[[IHWDate today] dateByAddingDays:-365/2].year];
29+
//[IHWCurriculum setCurrentYear:[[IHWDate today] dateByAddingDays:-365/2].year];
2830
}
2931
return self;
3032
}
@@ -39,6 +41,7 @@ - (void)viewDidLoad {
3941
self.topSpaceConstraint.constant = 20;
4042
self.topSpaceConstraint2.constant = 5;
4143
}
44+
if (self.goingToStep2) [self gotoStep2];
4245
}
4346

4447
- (void)viewWillAppear:(BOOL)animated {
@@ -48,17 +51,17 @@ - (void)viewWillAppear:(BOOL)animated {
4851

4952
- (IBAction)middleSchoolClicked:(id)sender {
5053
[IHWCurriculum setCurrentCampus:CAMPUS_MIDDLE];
51-
[[IHWCurriculum currentCurriculum].curriculumLoadingListeners addObject:self];
5254
[self gotoStep2];
5355
}
5456

5557
- (IBAction)upperSchoolClicked:(id)sender {
5658
[IHWCurriculum setCurrentCampus:CAMPUS_UPPER];
57-
[[IHWCurriculum currentCurriculum].curriculumLoadingListeners addObject:self];
5859
[self gotoStep2];
5960
}
6061

6162
- (void)gotoStep2 {
63+
NSLog(@"Going to Step 2");
64+
[[IHWCurriculum currentCurriculum].curriculumLoadingListeners addObject:self];
6265
self.downloadButton.hidden = NO;
6366
self.manualButton.hidden = NO;
6467
self.backButton.hidden = NO;
@@ -103,11 +106,26 @@ - (IBAction)backButtonClicked:(id)sender {
103106
}
104107

105108
- (void)curriculumFailedToLoad:(IHWCurriculum *)curriculum {
106-
[[[UIAlertView alloc] initWithTitle:@"Schedule Unavailable" message:@"The schedule for the campus and year you selected is not available." delegate:self cancelButtonTitle:@"Back" otherButtonTitles:nil] show];
109+
[[IHWCurriculum currentCurriculum].curriculumLoadingListeners removeObject:self];
110+
[[[UIAlertView alloc] initWithTitle:@"Schedule Unavailable" message:@"The schedule for the campus and year you selected is not available." delegate:self cancelButtonTitle:nil otherButtonTitles:@"Retry", @"Choose Year", nil] show];
107111
}
108112

109113
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
110-
[self.navigationController setViewControllers:@[[[IHWFirstRunViewController alloc] initWithNibName:@"IHWFirstRunViewController" bundle:nil]]];
114+
if (buttonIndex == 0) {
115+
[[IHWCurriculum reloadCurrentCurriculum].curriculumLoadingListeners addObject:self];
116+
} else {
117+
UINavigationController *navc = [[UINavigationController alloc] init];
118+
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
119+
navc.navigationBar.tintColor = [UIColor colorWithRed:0.6 green:0 blue:0 alpha:1];
120+
} else {
121+
navc.navigationBar.barTintColor = [UIColor colorWithRed:0.6 green:0 blue:0 alpha:1];
122+
navc.navigationBar.tintColor = [UIColor whiteColor];
123+
navc.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor]};
124+
navc.navigationBar.barStyle = UIBarStyleBlack;
125+
}
126+
navc.viewControllers = @[[[IHWPreferencesViewController alloc] initWithStyle:UITableViewStyleGrouped], [[IHWChangeYearViewController alloc] initWithStyle:UITableViewStyleGrouped]];
127+
[self presentViewController:navc animated:YES completion:nil];
128+
}
111129
}
112130

113131
- (void)didReceiveMemoryWarning

0 commit comments

Comments
 (0)