zjf
2023-03-06 392b76515f40376b6d36f40a114850ef63650384
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
//
//  LinPullMainViewController.m
//  LINPullTableView
//
//  Created by earnestLin on 2019/1/16.
//  Copyright © 2019年 earnestLin. All rights reserved.
//
 
#import "LinPullMainViewController.h"
 
#import "LinPullTopViewController.h"
#import "LinPullBottomViewController.h"
#import "PBLoginViewController.h"
#import "PBTabBarController.h"
// tool
#import "JYPulleyViewController.h"
#import "PBProjectInfoView.h"
#import "PBSetViewController.h"
#import "PBScanningViewController.h"
#import "PBMessageController.h"
#import "PBNavigationController.h"
@interface LinPullMainViewController ()<LinPullBottomViewControllerDelegate>
 
@property (nonatomic, strong) JYPulleyViewController *pulleyViewController;
@property (nonatomic, strong) LinPullTopViewController *topController;
@property (nonatomic, strong) LinPullBottomViewController *bottomController;
@property (nonatomic, weak) UIButton *allProjectBtn;
@property (nonatomic, weak) UIButton *collectionProjectBtn;
@property (nonatomic, strong) PBProjectInfoView *projectInfoView;
@end
 
@implementation LinPullMainViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    [PBNoteCenter addObserver:self selector:@selector(reRegister) name:@"PBNoteCenterTokenExpired" object:nil];
    self.view.backgroundColor = [UIColor whiteColor];
    if ([NSString getLoginData]) {
        [self setupUI];
    }else{
        [self toLogin];
    }
}
- (void)reRegister {
    [self toLogin];
}
- (void)toLogin {
//    self.dataList = nil;
//    [self.tableView reloadData];
    PBLoginViewController *loginVC = [[PBLoginViewController alloc] init];
    loginVC.LoginSuccessfulBlock = ^{
//        self.mineView.realName = Realname;
//        self.searchBar.text = nil;
//        self.fullName = nil;
//        [self.tableView.mj_header beginRefreshing];
        [self setupUI];
    };
    loginVC.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentViewController:loginVC animated:YES completion:nil];
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
    [self.navigationController setNavigationBarHidden:YES animated:animated];
}
 
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
//    self.navigationController.navigationBarHidden = NO;
}
 
#pragma mark - setupUI
- (void)setupUI {
    self.title = @"amap";
    __weak typeof(self) weakSelf = self;
    self.topController = [[LinPullTopViewController alloc] init];
    self.topController.OpenDetailsBlock = ^(PBProjectModel * _Nonnull projectModel) {
        [PBNoteCenter postNotificationName:@"LinPulBottomViewControllerNeedChangeStatus" object:[NSString stringWithFormat:@"%zd",JYPulleyStatusClosed]];
        weakSelf.projectInfoView.projectModel = projectModel;
        weakSelf.projectInfoView.IntoProjectBlock = ^(PBProjectModel * _Nonnull projectModel){
            PBTabBarController *tabBarController = [[PBTabBarController alloc] init];
            tabBarController.projectModel = projectModel;
            tabBarController.modalPresentationStyle = UIModalPresentationFullScreen;
            [weakSelf presentViewController:tabBarController animated:YES completion:nil];
        };
        [weakSelf show];
    };
    self.topController.ShutDetailsBlock = ^{
        [weakSelf hidden];
    };
    self.bottomController = [[LinPullBottomViewController alloc] init];
    self.bottomController.jumpToSetVCBlock = ^{
        PBSetViewController *setVC = [[PBSetViewController alloc] init];
        setVC.ToLoginBlock = ^{
            [weakSelf.view.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
            [weakSelf toLogin];
        };
        [weakSelf.navigationController pushViewController:setVC animated:YES];
    };
    self.bottomController.jumpToMessageBlock = ^{
        PBMessageController *messageVC = [[PBMessageController alloc] init];
        PBNavigationController *nav = [[PBNavigationController alloc] initWithRootViewController:messageVC];
        nav.modalPresentationStyle = UIModalPresentationFullScreen;
        [weakSelf presentViewController:nav animated:YES completion:nil];
//        [weakSelf.navigationController pushViewController:messageVC animated:YES];
    };
    self.bottomController.delegate = self;
    self.pulleyViewController =
    [[JYPulleyViewController alloc] initWithContentDataSource:self.topController
                                             drawerDataSource:self.bottomController];
    self.pulleyViewController.view.frame = self.view.bounds;
    self.pulleyViewController.supportedStatus = JYPulleyStatusClosed | JYPulleyStatusExpand | JYPulleyStatusPartiallyExpand;
    self.pulleyViewController.drawerExpandTopInset = 0;
    self.pulleyViewController.dimmingView.backgroundColor = [UIColor whiteColor];
    self.pulleyViewController.dimmingOpacity = 1;
    self.pulleyViewController.drawerDelegate = self.bottomController;
    self.bottomController.drawerScrollDelegate = self.pulleyViewController;
    [self.pulleyViewController addChildViewController:self.topController];
    [self.pulleyViewController addChildViewController:self.bottomController];
    [self addChildViewController:self.pulleyViewController];
    [self.view addSubview:self.pulleyViewController.view];
    [self.pulleyViewController updateStatus:JYPulleyStatusPartiallyExpand animated:NO];
    CGFloat bottomSpacing = 0.f;
    if (IS_IPHONE_X) {
        bottomSpacing = IPHONE_X_BOTTOM;
    }
//    UIImageView *bottomV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tab_bar"]];
//    [self.view addSubview:bottomV];
//    [bottomV mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.right.equalTo(self.view);
//        make.height.equalTo(@71);
//        make.bottom.equalTo(self.view).offset(-bottomSpacing);
//    }];
    UIView *bottomV = [[UIView alloc] init];
    bottomV.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:bottomV];
    [bottomV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.height.equalTo(@56);
        make.bottom.equalTo(self.view).offset(-bottomSpacing);
    }];
    
    UIView *supplementV = [[UIView alloc] init];
    supplementV.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:supplementV];
    [supplementV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bottomV.mas_bottom);
        make.left.right.equalTo(bottomV);
        make.bottom.equalTo(self.view);
    }];
//    UIButton *scanningBtn = [UIButton z_bgImageButton:[UIImage imageNamed:@"scan"]];
//    [scanningBtn addTarget:self action:@selector(scanningAction) forControlEvents:UIControlEventTouchUpInside];
//    [self.view addSubview:scanningBtn];
//    [scanningBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(bottomV).offset(10);
//        make.centerX.equalTo(bottomV);
//        make.size.mas_equalTo(CGSizeMake(44, 44));
//    }];
    UIButton *allProjectBtn = [UIButton z_bgNormalImage:[UIImage imageNamed:@"all_project_nor"] bgSelectedImage:[UIImage imageNamed:@"all_project"]];
    allProjectBtn.selected = YES;
    [allProjectBtn addTarget:self action:@selector(allProjectAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:allProjectBtn];
    [allProjectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bottomV).offset(12);
        make.left.equalTo(bottomV).offset(63);
        make.size.mas_equalTo(CGSizeMake(28, 42));
    }];
    
    UIButton *collectProjectBtn = [UIButton z_bgNormalImage:[UIImage imageNamed:@"collect_nor"] bgSelectedImage:[UIImage imageNamed:@"collect_select"]];
    [collectProjectBtn addTarget:self action:@selector(collectionProjectAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:collectProjectBtn];
    [collectProjectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bottomV).offset(12);
        make.right.equalTo(bottomV).offset(-63);
        make.size.mas_equalTo(CGSizeMake(28, 42));
    }];
    self.allProjectBtn = allProjectBtn;
    self.collectionProjectBtn = collectProjectBtn;
    [self.view addSubview:self.projectInfoView];
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.projectInfoView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(10, 10)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = self.projectInfoView.bounds;
    maskLayer.path = maskPath.CGPath;
    self.projectInfoView.layer.mask = maskLayer;
}
 
#pragma mark - 扫描二维码
- (void)scanningAction {
    PBScanningViewController *scanningVC = [[PBScanningViewController alloc] init];
    [self QRCodeScanVC:scanningVC];
}
- (void)QRCodeScanVC:(UIViewController *)scanVC {
    AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    if (device) {
        AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
        switch (status) {
                case AVAuthorizationStatusNotDetermined: {
                    [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
                        if (granted) {
                            dispatch_sync(dispatch_get_main_queue(), ^{
                                [self.navigationController pushViewController:scanVC animated:YES];
                            });
                            NSLog(@"用户第一次同意了访问相机权限 - - %@", [NSThread currentThread]);
                        } else {
                            NSLog(@"用户第一次拒绝了访问相机权限 - - %@", [NSThread currentThread]);
                        }
                    }];
                    break;
                }
                case AVAuthorizationStatusAuthorized: {
                    [self.navigationController pushViewController:scanVC animated:YES];
                    break;
                }
                case AVAuthorizationStatusDenied: {
                    UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"请去-> [设置 - 隐私 - 相机 - SGQRCodeExample] 打开访问开关" preferredStyle:(UIAlertControllerStyleAlert)];
                    UIAlertAction *alertA = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
                        
                    }];
                    
                    [alertC addAction:alertA];
                    [self presentViewController:alertC animated:YES completion:nil];
                    break;
                }
                case AVAuthorizationStatusRestricted: {
                    NSLog(@"因为系统原因, 无法访问相册");
                    break;
                }
                
            default:
                break;
        }
        return;
    }
    
    UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"未检测到您的摄像头" preferredStyle:(UIAlertControllerStyleAlert)];
    UIAlertAction *alertA = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    
    [alertC addAction:alertA];
    [self presentViewController:alertC animated:YES completion:nil];
}
 
#pragma mark - 全部项目
- (void)allProjectAction {
    if (self.allProjectBtn.selected) {
        return;
    }
    self.collectionProjectBtn.selected = NO;
    self.allProjectBtn.selected = YES;
    self.bottomController.isFavorite = NO;
}
#pragma mark - 收藏项目
- (void)collectionProjectAction {
    if (self.collectionProjectBtn.selected) {
        return;
    }
    self.allProjectBtn.selected = NO;
    self.collectionProjectBtn.selected = YES;
    self.bottomController.isFavorite = YES;
}
#pragma mark - JYEBMonitorEbikeDetailContentVCDelegate
 
//- (void)linPullBottomViewController:(LinPullBottomViewController *)vc
//                  didChangeToExpand:(CGFloat)height
//{
//    self.navigationController.navigationBarHidden = YES;
//}
//
//- (void)linPullBottomViewController:(LinPullBottomViewController *)vc
//         didChangeToPartiallyExpand:(CGFloat)height
//{
//    self.navigationController.navigationBarHidden = YES;
//}
//
//- (void)linPullBottomViewController:(LinPullBottomViewController *)vc
//         didChangeToClosed:(CGFloat)height
//{
//    self.navigationController.navigationBarHidden = YES;
//}
- (PBProjectInfoView *)projectInfoView {
    if (_projectInfoView == nil) {
        CGFloat height;
        if (IS_IPHONE_X) {
            height = 182.f + IPHONE_X_BOTTOM;
        }else {
            height = 182.f;
        }
        __weak typeof(self) weakSelf = self;
        _projectInfoView = [[PBProjectInfoView alloc] initWithFrame:CGRectMake(0, PBScreenHeight, PBScreenWidth, height)];
        _projectInfoView.packupBlock = ^{
            [weakSelf hidden];
        };
        weakSelf.projectInfoView.SetCollectionState = ^(PBProjectModel * _Nonnull projectModel) {
            weakSelf.topController.projectModel = projectModel;
        };
    }
    return _projectInfoView;
}
- (void)hidden {
    [UIView animateWithDuration:0.3 animations:^{
//        self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0];
        self.projectInfoView.y = PBScreenHeight;
    }completion:^(BOOL finished) {
        for (UIView *cover in PBKeyWindow.subviews) {
            if ([cover isKindOfClass:[PBProjectInfoView class]]) {
                [cover removeFromSuperview];
            }
        }
    }];
}
- (void)show {
    [UIView animateWithDuration:0.3 animations:^{
//        self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.5];
        CGFloat height;
        if (IS_IPHONE_X) {
            height = 182.f + IPHONE_X_BOTTOM;
        }else {
            height = 182.f;
        }
        self.projectInfoView.y = PBScreenHeight - height;
    }];
}
@end