// // CommonHomeVC.m // smartRhino // // Created by niuzhen on 2020/10/15. // Copyright © 2020 tederen. All rights reserved. // #import "CommonHomeVC.h" #import "MyTDGroupView.h" #import "GHRefreshCollectionView.h" #import "CommomSearchVC.h" #import "CommonNoteVC.h" #import "ChatMsgCollectionCell.h" #import "CommonWorkVC.h" #import "CommonToolVC.h" #import "MyFavoriteVC.h" #import "NoteBookVC.h" #import "CommonNoteVC.h" #import "CommonCollectVC.h" #import "My_CenterVC.h" @interface CommonHomeVC () @property (nonatomic, strong) UIView *IconView; @property (nonatomic, strong) UIImageView *IconImageV; @property (nonatomic, strong) UILabel *NameL; @property (nonatomic, strong) UIView *headView; @property (strong, nonatomic) NSMutableArray *collectionDataSource; @property (strong, nonatomic) MyTDGroupView *SearchView; @property (strong, nonatomic) GHRefreshCollectionView *collectionView; @end @implementation CommonHomeVC - (void)viewDidLoad { [super viewDidLoad]; self.fd_prefersNavigationBarHidden = YES; [self loadStatusBarColor:[UIColor whiteColor]]; [self addIconView]; [self addHeadView]; [self setCusPageVC]; [self setBarData]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(PushSettingVC:) name:DRAWERPUSHVC object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updataIcon) name:UPDATAUSERICON object:nil]; } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)updataIcon { [UserManager getUserInfoDetail]; [self.IconImageV sd_setImageWithURL:[NSURL URLWithString:[AppUserModel sharedAppUserModel].AvatarUrl] placeholderImage:kPlaceHolderImage]; } - (void)PushSettingVC:(NSNotification *)notification { NSInteger index = [[notification.userInfo objectForKey:VCINDEX] integerValue]; My_CenterVC * vc = [[My_CenterVC alloc] init]; if (index == 4) { vc.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:vc animated:YES]; }else{ if (index > 4) { vc.barIndex = index; vc.systemNar = YES; vc.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:vc animated:NO]; } } } - (BOOL)hidesBottomBarWhenPushed { [self.tabBarController.tabBar setHidden:NO]; return NO; } - (void)addIconView { [self.view addSubview:self.IconView]; [self.IconView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.statusBar.mas_bottom); make.left.right.equalTo(self.view); make.height.equalTo(@44); }]; [self.IconView addSubview:self.IconImageV]; [self.IconView addSubview:self.NameL]; UIImageView * rightV = [UIImageView new]; rightV.image = IMG(@"icon_arrowRight"); [self.IconView addSubview:rightV]; [self.IconImageV mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.mas_equalTo(self.IconView); make.left.mas_offset(15); make.size.mas_offset(CGSizeMake(29, 29)); }]; [self.NameL mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.mas_equalTo(self.IconView); make.left.mas_equalTo(self.IconImageV.mas_right).offset(9); }]; [rightV mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.mas_equalTo(self.IconView); make.right.mas_offset(-15); }]; self.NameL.text = [AppUserModel sharedAppUserModel].Name; [self.IconImageV sd_setImageWithURL:[NSURL URLWithString:[AppUserModel sharedAppUserModel].AvatarUrl] placeholderImage:kPlaceHolderImage]; WS(weakSelf); UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id _Nonnull sender) { My_CenterVC * vc = [[My_CenterVC alloc] init]; vc.hidesBottomBarWhenPushed = YES; [weakSelf.navigationController pushViewController:vc animated:YES]; }]; [self.IconView addGestureRecognizer:tap]; } - (void)addHeadView { [self.headView addSubview:self.SearchView]; [self.headView addSubview:self.collectionView]; [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.bottom.mas_equalTo(self.headView); make.height.mas_offset(78); }]; [self.SearchView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_offset(5); make.left.right.mas_equalTo(self.headView); make.bottom.mas_equalTo(self.collectionView.mas_top); }]; WS(weakSelf); [self.SearchView.button setAction:^{ CommomSearchVC * vc = [[CommomSearchVC alloc] init]; vc.hidesBottomBarWhenPushed = YES; [weakSelf.navigationController pushViewController:vc animated:YES]; }]; } - (UIView *)IconView { if (!_IconView) { _IconView = [UIView new]; } return _IconView; } - (UIImageView *)IconImageV { if (!_IconImageV) { _IconImageV = [UIImageView new]; _IconImageV.layer.cornerRadius = 4.f; _IconImageV.layer.masksToBounds = YES; } return _IconImageV; } - (UILabel *)NameL { if (!_NameL) { _NameL = [UILabel new]; _NameL.textColor = UIColorHex(0x0A0A0A); _NameL.font = Kfont(15); } return _NameL; } - (UIView *)headView { if (!_headView) { _headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 124)]; _headView.backgroundColor = [UIColor whiteColor]; } return _headView; } - (MyTDGroupView *)SearchView { if (!_SearchView) { _SearchView = [[MyTDGroupView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 36)]; } return _SearchView; } -(NSMutableArray *)collectionDataSource{ if(!_collectionDataSource){ _collectionDataSource = [[NSMutableArray alloc] init]; } return _collectionDataSource; } - (GHRefreshCollectionView *)collectionView { if (!_collectionView) { UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; layout.scrollDirection = UICollectionViewScrollDirectionHorizontal; layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0); _collectionView = [[GHRefreshCollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout]; _collectionView.delegate = self; _collectionView.dataSource = self; _collectionView.showsHorizontalScrollIndicator = NO; [_collectionView registerNib:[UINib nibWithNibName:@"ChatMsgCollectionCell" bundle:nil] forCellWithReuseIdentifier:@"ChatMsgCollectionCell"]; _collectionView.backgroundColor = [UIColor whiteColor]; } return _collectionView; } - (void)setCusPageVC { CGFloat height = SCREEN_HEIGHT - NAVH - self.tabBarController.tabBar.frame.size.height; WS(weakSelf); NSMutableArray * data = [NSMutableArray array]; NSMutableArray * vcArr = [NSMutableArray array]; CommonCollectVC * cvc = [[CommonCollectVC alloc] init]; CommonNoteVC * nvc = [[CommonNoteVC alloc] init]; [data addObject:@"最新收藏"]; [data addObject:@"最新笔记"]; [vcArr addObject:cvc]; [vcArr addObject:nvc]; WMZPageParam *param = PageParam() .wTitleArrSet(data) .wControllersSet(vcArr) //固定在所有子控制器底部 需要放在第一个控制器里 例如此例子 .wFixFirstSet(YES) //悬浮开启 .wTopSuspensionSet(YES) //等分 .wTopOffsetSet(NAVH) .wFromNaviSet(YES) .wMenuAnimalSet(PageTitleMenuNone) .wMenuTitleFontSet(15.f) .wMenuTitleSelectColorSet(UIColorHex(0x3979D3)) .wMenuIndicatorYSet(0.f) .wMenuIndicatorColorSet(UIColorHex(0x3979D3)) .wMenuTitleColorSet(UIColorHex(0x888888)) .wMenuTitleSelectFontSet(15.f) .wMenuFixShadowSet(NO) .wMenuFixRightDataSet(@{@"image":@"common_edit"}) .wMenuFixWidthSet(52) .wMenuCellMarginSet(11) .wMenuCellPaddingSet(15) .wMenuBgColorSet(UIColorHex(0xF4F4F4)) .wScrollCanTransferSet(NO) //头部 .wEventFixedClickSet(^(id anyID, NSInteger index) { MyTDTopicCreateVC * vc = [MyTDTopicCreateVC initMyTDTopicCreateVC]; vc.type = CollectModel_NoteBook; vc.FolderId = 0; vc.FolderName = @"根目录"; [weakSelf.navigationController pushViewController:vc animated:YES]; }) .wMenuHeadViewSet(^UIView *{ return self.headView; }); self.param = param; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{ for (UIView * view in weakSelf.view.subviews) { if ([view isKindOfClass:[WMZPageScroller class]]) { [view setFrame:CGRectMake(0, NAVH, SCREEN_WIDTH, height)]; } if ([view isKindOfClass:[UIScrollView class]]) { UIScrollView * sView = (UIScrollView *)view; sView.showsVerticalScrollIndicator = NO; } } }); }); } #pragma mark UICollectionView - (NSInteger)numberOfSectionsInCollectionView:(GHRefreshCollectionView *)collectionView{ return 1; } /**********************************************************************/ #pragma mark -UICollectionViewDataSource /**********************************************************************/ - (NSInteger)collectionView:(GHRefreshCollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.collectionDataSource.count; } - (UICollectionViewCell *)collectionView:(GHRefreshCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { MoreAppInfoModel *bean = [self.collectionDataSource objectAtIndex:indexPath.item]; ChatMsgCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ChatMsgCollectionCell" forIndexPath:indexPath]; cell.cell0IconImg.image = [UIImage imageNamed:bean.imgName]; cell.cell0TitleLabel.text = bean.title; cell.imagH.constant = 25.f; cell.imagW.constant = 25.f; cell.titleConstant.constant = 8.f; switch (indexPath.item) { case 0: { cell.cell0ReadNumLabel.hidden = YES; NSString * count = @"0"; cell.cell0ReadNumLabel.text = count; UILabel * label = [UILabel new]; label.font = [UIFont systemFontOfSize:12]; label.text = count; CGFloat width = [label sizeThatFits:CGSizeMake(SCREEN_WIDTH, 16)].width; if ((width + 5) < 16) { cell.constant.constant = 16; }else{ cell.constant.constant = width + 8; } } break; case 1: { cell.cell0ReadNumLabel.hidden = YES; NSString * count = @"0"; cell.cell0ReadNumLabel.text = count; UILabel * label = [UILabel new]; label.font = [UIFont systemFontOfSize:12]; label.text = count; CGFloat width = [label sizeThatFits:CGSizeMake(SCREEN_WIDTH, 16)].width; if ((width + 5) < 16) { cell.constant.constant = 16; }else{ cell.constant.constant = width + 8; } } break; case 2: { cell.cell0ReadNumLabel.hidden = YES; NSString * count = @"0"; cell.cell0ReadNumLabel.text = count; UILabel * label = [UILabel new]; label.font = [UIFont systemFontOfSize:12]; label.text = count; CGFloat width = [label sizeThatFits:CGSizeMake(SCREEN_WIDTH, 16)].width; if ((width + 5) < 16) { cell.constant.constant = 16; }else{ cell.constant.constant = width + 8; } } break; case 3: { cell.cell0ReadNumLabel.hidden = YES; NSString * count = @"0"; cell.cell0ReadNumLabel.text = count; UILabel * label = [UILabel new]; label.font = [UIFont systemFontOfSize:12]; label.text = count; CGFloat width = [label sizeThatFits:CGSizeMake(SCREEN_WIDTH, 16)].width; if ((width + 5) < 16) { cell.constant.constant = 16; }else{ cell.constant.constant = width + 8; } } break; default: { cell.cell0ReadNumLabel.hidden = YES ; } break; } cell.cell0MengCengView.hidden = YES; return cell; } /****************************************************/ #pragma mark --UICollectionViewDelegateFlowLayout /****************************************************/ - (CGSize)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { CGFloat width = (SCREEN_WIDTH - 20) / self.collectionDataSource.count; CGFloat height = 78; return CGSizeMake(width, height); } -(UIEdgeInsets)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section { CGFloat W = 10; return UIEdgeInsetsMake(0,W,0,W); } - (CGFloat)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{ return 0; } - (CGFloat)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{ return 0; } - (void)collectionView:(GHRefreshCollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ [collectionView deselectItemAtIndexPath:indexPath animated:YES]; switch (indexPath.item) { case 0: { MyFavoriteVC *vc = [MyFavoriteVC initMyFavoriteVC]; vc.listType = MyFavoriteListLevelTypeA; vc.FolderId = 0; vc.operationStateEnum = OperationStateEnum0; vc.myTitle = @"我的收藏"; vc.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:vc animated:YES]; } break; case 1: { NoteBookVC *vc = [NoteBookVC initNoteBookVC]; vc.listType = MyFavoriteListLevelTypeA; vc.myTitle = @"我的笔记"; vc.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:vc animated:YES]; } break; case 2: { CommonToolVC * vc = [CommonToolVC initCommonToolVC]; vc.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:vc animated:YES]; } break; default: { CommonWorkVC * vc = [CommonWorkVC initCommonWorkVC]; vc.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:vc animated:YES]; } break; } } - (void)setBarData { [self.collectionDataSource removeAllObjects]; NSArray * titleArray = @[@"收藏夹",@"笔记本",@"工具箱",@"工作台"]; NSArray * imageArray = @[@"Common_collect",@"Common_note",@"Common_gjxiang",@"Common_gztai"]; for (NSInteger i = 0; i < titleArray.count; i ++) { MoreAppInfoModel * model = [[MoreAppInfoModel alloc] init]; model.title = titleArray[i]; model.imgName = imageArray[i]; [self.collectionDataSource addObject:model]; } } @end