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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
//
//  LinPullBottomViewController.m
//  LINPullTableView
//
//  Created by earnestLin on 2019/1/16.
//  Copyright © 2019年 earnestLin. All rights reserved.
//
 
#import "LinPullBottomViewController.h"
#import "PBProjectModel.h"
#import "PBProjectTableViewCell.h"
#import "PBProjectSearchView.h"
#import "PBTabBarController.h"
 
//PBTabBarController *tabBarController = [[PBTabBarController alloc] init];
//tabBarController.projectModel = self.dataList[indexPath.row];
//tabBarController.modalPresentationStyle = UIModalPresentationFullScreen;
//[self presentViewController:tabBarController animated:YES completion:nil];
static NSString *const cellID = @"cellID";
 
//static CGFloat const kBottomControllerClosedHeight = 141.0f;
static inline CGFloat kBottomControllerClosedHeight() {
    if (IS_IPHONE_X) {
        return 141.0f + IPHONE_X_BOTTOM;
    }else {
        return 141.0f;
    }
}
static inline CGFloat kBottomControllerPartiallyExpandHeight() {
//    return [UIScreen mainScreen].bounds.size.height - 336.0f;
    if (IS_IPHONE_X) {
        return 300.0f + IPHONE_X_BOTTOM;
    }else {
        return 300.0f;
    }
}
 
@interface LinPullBottomViewController ()<UITableViewDelegate,UITableViewDataSource>
 
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *dataList;
@property (nonatomic, weak) UIButton *topBtn;
@property (nonatomic, weak) UIView *newsV;
@property (nonatomic, assign) JYPulleyStatus lastStatus;
@property (nonatomic, assign) JYPulleyStatus currentStatus;
@property (nonatomic, strong) PBProjectSearchView *projectSearchV;
@end
 
@implementation LinPullBottomViewController
-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self loadUnReadMessage];
}
- (void)loadUnReadMessage {
    [[PBNetworkTools sharedTools] RequestGetNotReadMsgWithPageIndex:1 andPageSize:1 andIsRead:@"0" andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) {
        if (error) {
            NSLog(@"%@",error);
//            [YJProgressHUD showMessage:@"加载失败" inView:nil];
            return;
        }
        NSString *str = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
        PBNetworkModel *networkModel = [PBNetworkModel yy_modelWithJSON:str];
        if (networkModel.Ret == 1) {
            NSArray *list = [networkModel.Data valueForKey:@"List"];
            if (list.count > 0) {
                self.newsV.hidden = NO;
            }else {
                self.newsV.hidden = YES;
            }
        }else {
//            [YJProgressHUD showMessage:@"加载失败" inView:nil];
        }
    }];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [PBNoteCenter addObserver:self selector:@selector(JPushMessage:) name:@"JPushMessage" object:nil];
    [PBNoteCenter addObserver:self selector:@selector(jumpBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:nil];
    [self setRoundedCorners];
    [self setupUI];
    [self loadProjectList];
}
- (void)JPushMessage:(NSNotification *)notification {
    self.newsV.hidden = NO;
}
- (void)jumpBecomeActive:(NSNotification *)notification {
    [self loadUnReadMessage];
}
- (void)setRoundedCorners {
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.view.bounds byRoundingCorners:UIRectCornerTopLeft |UIRectCornerTopRight cornerRadii:CGSizeMake(10, 10)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init];
    //设置大小
    maskLayer.frame = self.view.bounds;
    //设置图形样子
    maskLayer.path = maskPath.CGPath;
    self.view.layer.mask = maskLayer;
}
- (void)loadProjectList {
    self.dataList = nil;
    [self.tableView reloadData];
    [YJProgressHUD showProgress:@"" inView:self.view];
    NSString *favorite = @"";
    if (self.isFavorite) {
        favorite = @"1";
    }
    [[PBNetworkTools sharedTools] getProjectListWithKeyword:@"" andIsPublic:@"" andSort:@"CreateDate desc" andSkip:@"0" andtake:@"999" andOnlyFavorite:favorite andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) {
        if(error) {
            NSLog(@"%@",error);
            [YJProgressHUD showMessage:@"加载项目列表失败" inView:self.view];
            return;
        }
        NSString *str = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
        PBNetworkModel *networkModel = [PBNetworkModel yy_modelWithJSON:str];
        if (networkModel.Ret == 1) {
            [YJProgressHUD hide];
            self.dataList = [NSArray yy_modelArrayWithClass:[PBProjectModel class] json:[networkModel.Data valueForKey:@"rows"]];
            [self.tableView reloadData];
        }else {
            [YJProgressHUD showMessage:networkModel.Msg inView:self.view];
        }
    }];
}
#pragma mark - setupUI
 
- (void)setupUI {
    self.view.backgroundColor = [UIColor whiteColor];
    UIButton *topBtn = [UIButton z_bgImageButton:[UIImage imageNamed:@"bar"]];
    [topBtn addTarget:self action:@selector(topBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:topBtn];
    [topBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(2);
        make.size.mas_equalTo(CGSizeMake(28, 20));
        make.centerX.equalTo(self.view);
    }];
    UIImageView *searchBg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"search_bg"]];
    [self.view addSubview:searchBg];
    [searchBg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(24);
        make.left.equalTo(self.view).offset(10);
        make.right.equalTo(self.view).offset(-10);
        make.height.equalTo(@46);
    }];
//    UIButton *iconBtn = [[UIButton alloc] init];
//    iconBtn.backgroundColor = PBColor(38, 55, 75);
//    [iconBtn addTarget:self action:@selector(iconBtnAction) forControlEvents:UIControlEventTouchUpInside];
//    [self.view addSubview:iconBtn];
//    [iconBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerY.equalTo(searchBg);
//        make.size.mas_equalTo(CGSizeMake(28, 28));
//        make.left.equalTo(searchBg).offset(10);
//    }];
//    [iconBtn circleViewWithRadius:6];
    
    UIImageView *iconBtn = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"avatar_bg"]];
    iconBtn.userInteractionEnabled = YES;
    [self.view addSubview:iconBtn];
    [iconBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(searchBg);
        make.size.mas_equalTo(CGSizeMake(28, 28));
        make.left.equalTo(searchBg).offset(10);
    }];
    UITapGestureRecognizer *iconBtnTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(iconBtnAction)];
    [iconBtn addGestureRecognizer:iconBtnTap];
    
    UILabel *nameL = [UILabel z_labelWithText:@"" Color:[UIColor whiteColor] isBold:NO Font:14];
    nameL.textAlignment = NSTextAlignmentCenter;
    NSString *name = Realname;
    BOOL isChiness = [self IsChinese:name];
    if (isChiness) {
        nameL.text = [name substringFromIndex:name.length - 1];
    }else {
        nameL.text = [name substringToIndex:1];
    }
    [self.view addSubview:nameL];
    [nameL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.left.right.equalTo(iconBtn);
    }];
 
    UIButton *newsBtn = [UIButton z_bgImageButton:[UIImage imageNamed:@"news"]];
    [newsBtn addTarget:self action:@selector(newsBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:newsBtn];
    [newsBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(searchBg);
        make.size.mas_equalTo(CGSizeMake(24, 24));
        make.right.equalTo(searchBg).offset(-10);
    }];
    UIView *newsV = [[UIView alloc] init];
    newsV.backgroundColor = [UIColor redColor];
    [self.view addSubview:newsV];
    newsV.layer.cornerRadius = 3;
    [newsV.layer setMasksToBounds:YES];
    [newsV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(5, 5));
        make.top.equalTo(newsBtn);
        make.left.equalTo(newsBtn.mas_right);
    }];
    self.newsV = newsV;
    self.newsV.hidden = YES;
    
    UILabel *searchTextL = [UILabel z_labelWithText:@"在全部项目中查找" Color:PBColor(97, 111, 125) isBold:NO Font:16];
    [self.view addSubview:searchTextL];
    [searchTextL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(searchBg);
        make.left.equalTo(searchBg).offset(50);
        make.right.equalTo(newsBtn.mas_left).offset(-10);
        make.height.equalTo(@40);
    }];
    searchTextL.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(searchAction)];
    [searchTextL addGestureRecognizer:tap];
    self.topBtn = topBtn;
}
- (BOOL)IsChinese:(NSString *)str {
    for(int i=0; i< [str length];i++){
        int a = [str characterAtIndex:i];
        if( a > 0x4e00 && a < 0x9fff){
            return YES;
        }
      }
    return NO;
}
#pragma mark - 点击顶部按钮
- (void)topBtnAction {
    JYPulleyStatus action = JYPulleyStatusNone;
    if (self.currentStatus == JYPulleyStatusExpand) {//上
        action = JYPulleyStatusPartiallyExpand;
    }else if (self.currentStatus == JYPulleyStatusClosed) {//下
        action = JYPulleyStatusPartiallyExpand;
    }else if (self.currentStatus == JYPulleyStatusPartiallyExpand) {//中
        if (self.lastStatus == JYPulleyStatusExpand) {
            action = JYPulleyStatusClosed;
        }else {
            action = JYPulleyStatusExpand;
        }
    }
    [PBNoteCenter postNotificationName:@"LinPulBottomViewControllerNeedChangeStatus" object:[NSString stringWithFormat:@"%zd",action]];
}
#pragma mark - 点击头像方法
- (void)iconBtnAction {
    if (self.jumpToSetVCBlock) {
        self.jumpToSetVCBlock();
    }   
}
#pragma mark - 点击消息方法
- (void)newsBtnAction {
    if (self.jumpToMessageBlock) {
        self.jumpToMessageBlock();
    }
}
#pragma mark - 搜索方法
- (void)searchAction {
    __weak typeof(self) weakSelf = self;
    [PBNoteCenter postNotificationName:@"LinPulBottomViewControllerNeedChangeStatus" object:[NSString stringWithFormat:@"%zd",JYPulleyStatusExpand]];
    self.projectSearchV.hidden = NO;
    self.projectSearchV.cancelSearchBlock = ^{
        [weakSelf cancelSearchWithDrag:NO];
    };
//    PBProjectSearchViewController *projectSearchVC = [[PBProjectSearchViewController alloc] init];
////    projectSearchVC.modalPresentationStyle = UIModalPresentationCustom;
//    projectSearchVC.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
//    [self presentViewController:projectSearchVC animated:NO completion:nil];
//    [self.navigationController pushViewController:projectSearchVC animated:NO];
}
- (void)cancelSearchWithDrag:(BOOL)drag {
    [self.view endEditing:NO];
    [self.projectSearchV removeFromSuperview];
    self.projectSearchV = nil;
    if (!drag) {
        [PBNoteCenter postNotificationName:@"LinPulBottomViewControllerNeedChangeStatus" object:[NSString stringWithFormat:@"%zd",JYPulleyStatusPartiallyExpand]];
    }
}
#pragma mark - JYPulleyDrawerDataSource
 
- (CGFloat)closedHeightInPulleyViewController:(JYPulleyViewController *)pulleyViewController
{
    return kBottomControllerClosedHeight();
}
 
- (CGFloat)partiallyExpandHeightInPulleyViewController:(JYPulleyViewController *)pulleyViewController
{
    return kBottomControllerPartiallyExpandHeight();
}
 
#pragma mark - JYPulleyDrawerDelegate
 
- (void)pulleyViewController:(JYPulleyViewController *)pulleyViewController didChangeStatus:(JYPulleyStatus)status
{
    self.lastStatus = self.currentStatus;
    self.currentStatus = status;
    if (status == JYPulleyStatusClosed)
    {
        self.tableView.scrollEnabled = NO;
//        self.tableView.contentInset =
//        UIEdgeInsetsMake(0, 0, kBottomControllerClosedHeight, 0);
        
//        if ([self.delegate
//             respondsToSelector:@selector(linPullBottomViewController:didChangeToClosed:)]) {
//            [self.delegate linPullBottomViewController:self
//                                     didChangeToClosed:kBottomControllerClosedHeight()];
//        }
        [self cancelSearchWithDrag:YES];
        [self.topBtn setBackgroundImage:[UIImage imageNamed:@"bar_arrow"] forState:UIControlStateNormal];
    }
    if (status == JYPulleyStatusPartiallyExpand)
    {
        self.tableView.scrollEnabled = NO;
//        self.tableView.contentInset =
//        UIEdgeInsetsMake(0, 0, kBottomControllerPartiallyExpandHeight(), 0);
//        if ([self.delegate respondsToSelector:@selector(linPullBottomViewController:didChangeToPartiallyExpand:)])
//        {
//            [self.delegate linPullBottomViewController:self didChangeToPartiallyExpand:kBottomControllerPartiallyExpandHeight()];
//        }
        [self cancelSearchWithDrag:YES];
        [self.topBtn setBackgroundImage:[UIImage imageNamed:@"bar"] forState:UIControlStateNormal];
    }
    
    if (status == JYPulleyStatusExpand)
    {
        self.tableView.scrollEnabled = YES;
        self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 20, 0);
//        if ([self.delegate respondsToSelector:@selector(linPullBottomViewController:didChangeToPartiallyExpand:)])
//        {
//            [self.delegate linPullBottomViewController:self didChangeToExpand:0];
//        }
        [self.topBtn setBackgroundImage:[UIImage imageNamed:@"bar_down"] forState:UIControlStateNormal];
    }
}
 
#pragma mark - tableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataList.count;
}
 
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 120;
}
 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellId = @"cellId";
    PBProjectTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (!cell)
        cell = [[PBProjectTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
    cell.projectModel = self.dataList[indexPath.row];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    PBTabBarController *tabBarController = [[PBTabBarController alloc] init];
    tabBarController.projectModel = self.dataList[indexPath.row];
    tabBarController.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentViewController:tabBarController animated:YES completion:nil];
}
 
#pragma mark - GET
- (UITableView *)tableView {
    if (!_tableView)
    {
        CGFloat bottomViewH = 71.f - 20;
        if (IS_IPHONE_X) {
            bottomViewH = bottomViewH + IPHONE_X_BOTTOM;
        }
        _tableView = [[UITableView alloc] init];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [self.view addSubview:_tableView];
        [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.view).offset(75 );
            make.left.right.bottom.equalTo(self.view);
            make.bottom.equalTo(self.view).offset(-bottomViewH);
        }];
    }
    return _tableView;
}
- (PBProjectSearchView *)projectSearchV {
    __weak typeof(self) weakSelf = self;
    if (!_projectSearchV) {
        _projectSearchV = [[PBProjectSearchView alloc] init];
        [self.view addSubview:_projectSearchV];
        [_projectSearchV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(self.view);
            make.top.equalTo(self.view).offset(24);
        }];
        _projectSearchV.hidden = YES;
        _projectSearchV.projectDetailBlock = ^(PBProjectModel * _Nonnull projectModel) {
            PBTabBarController *tabBarController = [[PBTabBarController alloc] init];
            tabBarController.projectModel = projectModel;
            tabBarController.modalPresentationStyle = UIModalPresentationFullScreen;
            [weakSelf presentViewController:tabBarController animated:YES completion:nil];
        };
    }
    return _projectSearchV;
}
- (void)setIsFavorite:(BOOL)isFavorite {
    _isFavorite = isFavorite;
    [self loadProjectList];
}
- (void)dealloc {
    [PBNoteCenter removeObserver:self];
}
@end