ICRAppViewControllerManager.m 7.46 KB
Newer Older
mei's avatar
mei committed
1 2
//
//  ICRAppViewControllerManager.m
mei's avatar
mei committed
3
//  XFFruit
mei's avatar
mei committed
4 5 6 7 8 9 10 11
//
//  Created by Xummer on 3/23/15.
//  Copyright (c) 2015 Xummer. All rights reserved.
//

#import "ICRAppViewControllerManager.h"
#import "ICRUIAppearance.h"

Sandy's avatar
Sandy committed
12
#import "BusinessViewController.h"
mei's avatar
mei committed
13 14
#import "IBTUINavigationController.h"
#import "ICRHomeViewController.h"
Sandy's avatar
Sandy committed
15
#import "ICRLoginViewController.h"
mei's avatar
mei committed
16 17
#import "ICRSyncViewController.h"
#import "ICRSystemViewController.h"
18
#import "ReportDetailViewController.h"
Sandy's avatar
Sandy committed
19 20
#import "ReportViewController.h"
@interface ICRAppViewControllerManager () <UITabBarControllerDelegate>
mei's avatar
mei committed
21 22 23 24
@end

@implementation ICRAppViewControllerManager

Sandy's avatar
Sandy committed
25 26
+ (UINavigationController *)getCurrentNavigationController
{
mei's avatar
mei committed
27 28 29
    return nil;
}

Sandy's avatar
Sandy committed
30 31
+ (IBTTabBarController *)getTabBarController
{
mei's avatar
mei committed
32 33 34
    return [[self getAppViewControllerManager] getTabBarController];
}

Sandy's avatar
Sandy committed
35 36
+ (ICRAppViewControllerManager *)getAppViewControllerManager
{
mei's avatar
mei committed
37 38 39 40 41 42
    static ICRAppViewControllerManager *_sharedMgr = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
        _sharedMgr = [[ICRAppViewControllerManager alloc] initWithWindow:keyWindow];
    });
Sandy's avatar
Sandy committed
43

mei's avatar
mei committed
44 45 46
    return _sharedMgr;
}

Sandy's avatar
Sandy committed
47 48
- (id)initWithWindow:(UIWindow *)window
{
mei's avatar
mei committed
49 50 51 52
    self = [super init];
    if (!self) {
        return nil;
    }
Sandy's avatar
Sandy committed
53

mei's avatar
mei committed
54
    [ICRUIAppearance CustomAppearance];
Sandy's avatar
Sandy committed
55

mei's avatar
mei committed
56 57 58
    m_window = window;
    m_arrTabBarBaseViewController = [NSMutableArray array];
    m_arrViewController = [NSMutableArray array];
Sandy's avatar
Sandy committed
59

mei's avatar
mei committed
60 61 62 63
    // Automatic login
    ICRUserUtil *userUtil = [ICRUserUtil sharedInstance];
    if ([userUtil isLogin]) {
        [self openMainFrame];
Sandy's avatar
Sandy committed
64
    } else {
mei's avatar
mei committed
65 66
        [self openFirstView];
    }
Sandy's avatar
Sandy committed
67

mei's avatar
mei committed
68 69 70
    return self;
}

Sandy's avatar
Sandy committed
71 72
- (void)dealloc
{
mei's avatar
mei committed
73 74 75 76 77 78 79
    m_window = nil;
    m_arrViewController = nil;
    m_arrTabBarBaseViewController = nil;
    m_tabbarController = nil;
}

#pragma mark - Public Method
Sandy's avatar
Sandy committed
80 81
- (CGSize)getRootViewSize
{
mei's avatar
mei committed
82 83 84
    return m_window.rootViewController.view.frame.size;
}

Sandy's avatar
Sandy committed
85 86
- (IBTTabBarController *)getTabBarController
{
mei's avatar
mei committed
87 88 89
    return m_tabbarController;
}

Sandy's avatar
Sandy committed
90 91
- (NSUInteger)getCurTabBarIndex
{
mei's avatar
mei committed
92 93 94
    return m_tabbarController.selectedIndex;
}

Sandy's avatar
Sandy committed
95 96
- (UIViewController *)getTabBarBaseViewController:(CRTapBarItemIndex)index
{
mei's avatar
mei committed
97 98 99
    if (index > kCRSystem || index > [m_arrTabBarBaseViewController count]) {
        return nil;
    }
Sandy's avatar
Sandy committed
100 101

    return m_arrTabBarBaseViewController[index];
mei's avatar
mei committed
102
}
Sandy's avatar
Sandy committed
103 104 105

- (void)openFirstView
{
mei's avatar
mei committed
106 107
    if ([m_window.rootViewController isKindOfClass:[IBTUINavigationController class]]) {
        IBTUINavigationController *navCtrl = (IBTUINavigationController *)m_window.rootViewController;
Sandy's avatar
Sandy committed
108

mei's avatar
mei committed
109 110
        if ([[navCtrl.viewControllers lastObject] isKindOfClass:[ICRLoginViewController class]]) {
            return;
Sandy's avatar
Sandy committed
111
        } else if ([[navCtrl.viewControllers firstObject] isKindOfClass:[ICRLoginViewController class]]) {
mei's avatar
mei committed
112 113 114 115
            [navCtrl popToRootViewControllerAnimated:YES];
            return;
        }
    }
Sandy's avatar
Sandy committed
116

mei's avatar
mei committed
117 118 119
    ICRLoginViewController *loginCtrl = [[ICRLoginViewController alloc] init];
    IBTUINavigationController *naviCtrl = [[IBTUINavigationController alloc] initWithRootViewController:loginCtrl];
    naviCtrl.navigationBarHidden = YES;
Sandy's avatar
Sandy committed
120

mei's avatar
mei committed
121 122
    m_window.rootViewController = naviCtrl;
}
mei's avatar
mei committed
123
//   主页面
Sandy's avatar
Sandy committed
124 125 126
- (void)openMainFrame
{
    if (m_window.rootViewController && m_window.rootViewController == m_tabbarController) {
mei's avatar
mei committed
127 128
        return;
    }
Sandy's avatar
Sandy committed
129

mei's avatar
mei committed
130 131
    [m_arrTabBarBaseViewController removeAllObjects];
    [m_arrViewController removeAllObjects];
Sandy's avatar
Sandy committed
132 133 134

    [self createHomeViewController];    //首页
    [self createBusinessViewController];//业务
陈俊俊's avatar
陈俊俊 committed
135 136 137
    if ([IBTCommon checkIsPermission:Report_ACTION_Check]) {
        [self createReportViewController];
    }
Sandy's avatar
Sandy committed
138 139
#ifdef Demonstrate
#else
Sandy's avatar
Sandy committed
140
    [self createSyncViewController];
Sandy's avatar
Sandy committed
141
#endif
mei's avatar
mei committed
142
    [self createSystemViewController];
143

mei's avatar
mei committed
144 145 146 147
    if (!m_tabbarController) {
        m_tabbarController = [[IBTTabBarController alloc] init];
        m_tabbarController.delegate = self;
    }
Sandy's avatar
Sandy committed
148
    //    添加  首页  门店  同步   系统
mei's avatar
mei committed
149
    [m_tabbarController setViewControllers:m_arrViewController];
Sandy's avatar
Sandy committed
150
    //    默认首次进入
mei's avatar
mei committed
151
    [m_tabbarController setSelectedIndex:kCRHome];
Sandy's avatar
Sandy committed
152
    //    底部bar
mei's avatar
mei committed
153 154 155
    m_window.rootViewController = m_tabbarController;
}

mei's avatar
mei committed
156
#pragma mark - Actions
Sandy's avatar
Sandy committed
157 158
- (void)doLogout
{
mei's avatar
mei committed
159 160 161
    ICRUserUtil *userUtil = [ICRUserUtil sharedInstance];
    [userUtil logout];
    [ICRDataBaseController CleanUpDBPath];
Sandy's avatar
Sandy committed
162

mei's avatar
mei committed
163 164 165
    [self openFirstView];
}

mei's avatar
mei committed
166
#pragma mark - Creation
Sandy's avatar
Sandy committed
167 168 169 170 171
- (void)createHomeViewController
{

    NSString *nsTitle = ACETapBarItemNames[kCRHome];

mei's avatar
mei committed
172 173 174
    ICRHomeViewController *homeVCtrl = [[ICRHomeViewController alloc] init];
    [m_arrTabBarBaseViewController addObject:homeVCtrl];
    homeVCtrl.title = [IBTCommon localizableString:nsTitle];
Sandy's avatar
Sandy committed
175

mei's avatar
mei committed
176 177
    IBTUINavigationController *navCtrl = [[IBTUINavigationController alloc] initWithRootViewController:homeVCtrl];
    [m_arrViewController addObject:navCtrl];
Sandy's avatar
Sandy committed
178

mei's avatar
mei committed
179 180
    navCtrl.title = nsTitle;
}
Sandy's avatar
Sandy committed
181
- (void)createBusinessViewController
mei's avatar
mei committed
182
{
Sandy's avatar
Sandy committed
183 184
    NSString *nsTitle = ACETapBarItemNames[kCRBusiness];
    BusinessViewController *businessVCtrl = [[BusinessViewController alloc] init];
mei's avatar
mei committed
185
    [m_arrTabBarBaseViewController addObject:businessVCtrl];
Sandy's avatar
Sandy committed
186
    businessVCtrl.title = [IBTCommon localizableString:nsTitle];
mei's avatar
mei committed
187 188
    IBTUINavigationController *navCtrl = [[IBTUINavigationController alloc] initWithRootViewController:businessVCtrl];
    [m_arrViewController addObject:navCtrl];
mei's avatar
mei committed
189

Sandy's avatar
Sandy committed
190
    navCtrl.title = nsTitle;
mei's avatar
mei committed
191
}
Sandy's avatar
Sandy committed
192 193
- (void)createReportViewController
{
194 195 196
    //如果登陆的是子节点
    ICRUserUtil *user = [ICRUserUtil sharedInstance];
    if (user.belongOrgIsLeaf) {
Sandy's avatar
Sandy committed
197
        Compass *com = [[Compass alloc] init];
198 199 200 201 202 203 204
        com.orgCode = user.org_code;
        com.orgName = user.org_name;
        com.orgUuid = user.org_uuid;
        ReportDetailViewController *storeVCtrl = [[ReportDetailViewController alloc] init];
        storeVCtrl.compass = com;
        [m_arrTabBarBaseViewController addObject:storeVCtrl];
        storeVCtrl.title = com.orgName;
Sandy's avatar
Sandy committed
205 206

        NSString *nsTitle = ACETapBarItemNames[kCRReport];
207 208 209 210 211

        IBTUINavigationController *navCtrl = [[IBTUINavigationController alloc] initWithRootViewController:storeVCtrl];
        [m_arrViewController addObject:navCtrl];

        navCtrl.title = nsTitle;
Sandy's avatar
Sandy committed
212 213
    } else {
        NSString *nsTitle = ACETapBarItemNames[kCRReport];
214 215 216
        ReportViewController *storeVCtrl = [[ReportViewController alloc] init];
        [m_arrTabBarBaseViewController addObject:storeVCtrl];
        storeVCtrl.title = [IBTCommon localizableString:nsTitle];
Sandy's avatar
Sandy committed
217

218 219
        IBTUINavigationController *navCtrl = [[IBTUINavigationController alloc] initWithRootViewController:storeVCtrl];
        [m_arrViewController addObject:navCtrl];
Sandy's avatar
Sandy committed
220

221 222
        navCtrl.title = nsTitle;
    }
mei's avatar
mei committed
223 224
}

Sandy's avatar
Sandy committed
225 226 227 228
- (void)createSyncViewController
{
    NSString *nsTitle = ACETapBarItemNames[kCRSync];

mei's avatar
mei committed
229 230 231
    ICRSyncViewController *syncVCtrl = [[ICRSyncViewController alloc] init];
    [m_arrTabBarBaseViewController addObject:syncVCtrl];
    syncVCtrl.title = [IBTCommon localizableString:nsTitle];
Sandy's avatar
Sandy committed
232

mei's avatar
mei committed
233 234
    IBTUINavigationController *navCtrl = [[IBTUINavigationController alloc] initWithRootViewController:syncVCtrl];
    [m_arrViewController addObject:navCtrl];
Sandy's avatar
Sandy committed
235

mei's avatar
mei committed
236 237 238
    navCtrl.title = nsTitle;
}

Sandy's avatar
Sandy committed
239 240 241 242
- (void)createSystemViewController
{
    NSString *nsTitle = ACETapBarItemNames[kCRSystem];

mei's avatar
mei committed
243 244 245
    ICRSystemViewController *systemVCtrl = [[ICRSystemViewController alloc] init];
    [m_arrTabBarBaseViewController addObject:systemVCtrl];
    systemVCtrl.title = [IBTCommon localizableString:nsTitle];
Sandy's avatar
Sandy committed
246

mei's avatar
mei committed
247 248
    IBTUINavigationController *navCtrl = [[IBTUINavigationController alloc] initWithRootViewController:systemVCtrl];
    [m_arrViewController addObject:navCtrl];
Sandy's avatar
Sandy committed
249

mei's avatar
mei committed
250 251 252 253
    navCtrl.title = nsTitle;
}

@end