This repository has been archived by the owner on Jan 19, 2018. It is now read-only.
/
DZCAppDelegate.m
101 lines (77 loc) · 3.51 KB
/
DZCAppDelegate.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
#import "DZCAppDelegate.h"
#import "DZCDataController.h"
#import "DZCLabsListViewController.h"
#import "DZCEmptyDetailViewController.h"
#import "UIColor+DZCColors.h"
#import "AFNetworkActivityIndicatorManager.h"
#import <BugSense-iOS/BugSenseController.h>
static const NSTimeInterval DZCAppBackgroundRefreshTimeout = 60.0;
static NSString * const DZCCAENLabsBugSenseAPIKey = @"989bc067";
@interface DZCAppDelegate ()
@property (nonatomic, strong) DZCDataController *dataController;
@property (nonatomic, strong) DZCLabsListViewController *labsViewController;
@property (nonatomic, strong) NSDate *appBackgroundTime;
@end
@implementation DZCAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[BugSenseController sharedControllerWithBugSenseAPIKey:DZCCAENLabsBugSenseAPIKey];
[BugSenseController setLogMessagesCount:10];
[BugSenseController setLogMessagesLevel:8];
[self applyStyles];
UIViewController *rootVC;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.labsViewController = [[DZCLabsListViewController alloc] init];
rootVC = [[UINavigationController alloc] initWithRootViewController:self.labsViewController];
} else { // UIUserInterfaceIdiomPad
UISplitViewController *vc = [[UISplitViewController alloc] init];
DZCEmptyDetailViewController *emptyVC = [[DZCEmptyDetailViewController alloc] init];
emptyVC.dataController = self.dataController;
UINavigationController *detailNavigationVC = [[UINavigationController alloc] initWithRootViewController:emptyVC];
self.labsViewController = [[DZCLabsListViewController alloc] init];
self.labsViewController.padDetailNavigationController = detailNavigationVC;
vc.viewControllers = @[
[[UINavigationController alloc] initWithRootViewController:self.labsViewController],
detailNavigationVC
];
vc.delegate = self;
rootVC = vc;
}
self.labsViewController.dataController = self.dataController;
[[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = rootVC;
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
self.appBackgroundTime = [NSDate date];
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
if (self.appBackgroundTime && [[NSDate date] timeIntervalSinceDate:self.appBackgroundTime] > DZCAppBackgroundRefreshTimeout) {
[self.dataController clearCache];
[self.dataController reloadLabStatusesWithBlock:nil];
[self.labsViewController refreshData];
}
}
#pragma mark - UI Management
- (void)applyStyles {
[[UINavigationBar appearance] setTintColor:[UIColor dzc_blueTintColor]];
[[UIRefreshControl appearance] setTintColor:[UIColor dzc_blueTintColor]];
}
#pragma mark UISplitViewControllerDelegate
- (BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation
{
return NO; // on iPad, keep both VCs visible, regardless of orientation.
}
#pragma mark - Property overrides
- (DZCDataController *)dataController
{
if (!_dataController) {
_dataController = [[DZCDataController alloc] init];
}
return _dataController;
}
@end