123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490 |
- //
- // CommonHomeVC.m
- // smartRhino
- //
- // Created by niuzhen on 2020/4/28.
- // Copyright © 2020 tederen. All rights reserved.
- //
- #import "CommonHomeVC.h"
- #import "CommonListCell.h"
- #import "MyTDGroupView.h"
- #import "GHRefreshCollectionView.h"
- #import "CommonBarCell.h"
- #import "CommonBarModel.h"
- #import "CommonWorkVC.h"
- #import "CommonToolVC.h"
- #import "MyFavoriteVC.h"
- #import "CommonNoteVC.h"
- #import "ChatMsgListCell.h"
- #import "ChatMsgCollectionCell.h"
- @interface CommonHomeVC ()<UITableViewDelegate,UITableViewDataSource,UICollectionViewDelegate,UICollectionViewDataSource>
- @property (weak, nonatomic) IBOutlet UIView *NavBar;
- @property (strong, nonatomic) UIView *HeadView;
- @property (strong, nonatomic) UITableView *tableView;
- @property (strong, nonatomic) MyTDGroupView *SearchView;
- @property (strong, nonatomic) GHRefreshCollectionView *collectionView;
- @property (strong, nonatomic) NSMutableArray *collectionDataSource;
- @property (strong, nonatomic) NSMutableArray *dataArray;
- @end
- @implementation CommonHomeVC
- - (UIView *)HeadView
- {
- if (!_HeadView) {
- _HeadView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 46)];
- _HeadView.backgroundColor = [UIColor whiteColor];
- }
- return _HeadView;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.fd_prefersNavigationBarHidden = YES;
- self.view.backgroundColor = UIColorHex(0xffffff);
- if (@available(iOS 11.0, *)) {
- self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- } else {
- self.automaticallyAdjustsScrollViewInsets = NO;
- }
- [self.HeadView addSubview:self.SearchView];
- [self.SearchView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_offset(5);
- make.left.right.mas_equalTo(self.HeadView);
- make.height.mas_offset(36);
- }];
- [self.view addSubview:self.tableView];
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.NavBar.mas_bottom);
- if (@available(iOS 11.0, *)) {
- make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
- } else {
- make.bottom.equalTo(self.view.mas_bottom);
- }
- }];
- self.tableView.tableHeaderView = self.HeadView;
-
- [self setBarData];
- [self.SearchView.button setAction:^{
- NSLog(@"点击搜索");
- }];
- self.tableView.delegate = self;
- self.tableView.dataSource = self;
- self.tableView.backgroundColor = [UIColor clearColor];
- CommonListModel * model = [[CommonListModel alloc] init];
- model.Title = @"钱颖一:人工智能将使中国教育仅存的优 势荡然无存";
- model.Name = @"钱颖一";
- model.Des = @"中国前沿计算机教育观察周刊";
- [self.dataArray addObject:model];
- [self.dataArray addObject:model];
- [self.dataArray addObject:model];
- [self.dataArray addObject:model];
- [self.dataArray addObject:model];
- CommonListModel * amodel = [[CommonListModel alloc] init];
- amodel.Title = @"钱颖一:人工智能将使中国教育仅存的优 势荡然无存";
- amodel.Name = @"钱颖一";
- amodel.Des = @"中国前沿计算机教育观察周刊";
- [self.dataArray addObject:amodel];
- CommonListModel * bmodel = [[CommonListModel alloc] init];
- bmodel.Title = @"钱颖一:人工智能将使中国教育仅存的优 势荡然无存";
- bmodel.Name = @"钱颖一";
- bmodel.Des = @"中国前沿计算机教育观察周刊";
- [self.dataArray addObject:bmodel];
- CommonListModel * cmodel = [[CommonListModel alloc] init];
- cmodel.Title = @"大脑不擅长思考,那我们应该怎么学习?";
- cmodel.Name = @"周明鑫";
- cmodel.Des = @"北国教育论坛";
- [self.dataArray addObject:cmodel];
- [self.tableView reloadData];
- }
- - (BOOL)hidesBottomBarWhenPushed{
- return NO;
- }
- #pragma mark - UITableViewDelegate
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- return 2;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- switch (section) {
- case 0:{
- return 1;
- }break;
- default:{
- return self.dataArray.count;
- }break;
- }
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- switch (indexPath.section) {
- case 0:{
- return 74.f;
- }break;
- default:{
- return UITableViewAutomaticDimension;
- }break;
- }
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- {
- switch (section) {
- case 0:{
- return 0.f;
- }break;
- default:{
- return 36.f;
- }break;
- }
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- {
- switch (section) {
- case 0:{
- UIView * view = [UIView new];
- return view;
- }break;
- default:{
- UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 36)];
- view.backgroundColor = UIColorHex(0xF5F5F5);
- UILabel * label = [UILabel new];
- label.font = [UIFont systemFontOfSize:14];
- label.textColor = UIColorHex(0x888888);
- label.text = @"最新收藏";
- [view addSubview:label];
- [label mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_offset(15);
- make.centerY.mas_equalTo(view);
- }];
- return view;
- }break;
- }
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- switch (indexPath.section) {
- case 0:
- {
- ChatMsgListCell *cell = [ChatMsgListCell configCell1:tableView indexPath:indexPath];
- [cell.cell1ContentBgView addSubview:self.collectionView];
- self.collectionView.frame = CGRectMake(0, 0, SCREEN_WIDTH, cell.cell1ContentBgView.height);
- [self.collectionView reloadData];
- return cell;
- }
- break;
- default:
- {
- CommonListCell *cell = [CommonListCell configCell1:tableView indexPath:indexPath];
- CommonListModel * model = [self.dataArray objectAtIndex:indexPath.row];
- [cell setCell1Data:model];
- return cell;
- }
- break;
- }
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
- }
- #pragma mark - load
- - (UITableView *)tableView
- {
- if (!_tableView) {
- _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- }
- return _tableView;
- }
- - (MyTDGroupView *)SearchView
- {
- if (!_SearchView) {
- _SearchView = [[MyTDGroupView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 36)];
- }
- return _SearchView;
- }
- -(NSMutableArray *)dataArray{
- if(!_dataArray){
- _dataArray = [[NSMutableArray alloc] init];
- }
- return _dataArray;
- }
- -(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;
- }
- #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 = 80;
- 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:
- {
- CommonNoteVC * vc = [CommonNoteVC initCommonNoteVC];
- 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];
- }
- }
- #pragma Mark 左滑按钮 iOS8以上
- #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_11_0
- - (nullable UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos){
- if (indexPath.section == 0) {
- UISwipeActionsConfiguration *actions = [UISwipeActionsConfiguration configurationWithActions:@[]];
- actions.performsFirstActionWithFullSwipe = NO;
- return actions;
- }else{
- WEAKSELF
- UIContextualAction *action1 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"转发" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
- [tableView setEditing:NO animated:YES];
- }];
- action1.backgroundColor = UIColorHex(#FF923A);
- UIContextualAction *action2 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"置顶" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
- [tableView setEditing:NO animated:YES];
-
- }];
- action2.backgroundColor = UIColorHex(#9BA9CB);
- UIContextualAction *action3 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"移动" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
- [tableView setEditing:NO animated:YES];
- }];
- action3.backgroundColor = UIColorHex(#589AF1);
- UIContextualAction *action4 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"删除" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
- [tableView setEditing:NO animated:YES];
- UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction *ok = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
- }];
- [ok setValue:k9 forKey:@"_titleTextColor"];
- UIAlertAction *noOk = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- }];
- [alertVC addAction:ok];
- [alertVC addAction:noOk];
- completionHandler(YES);
- [weakSelf presentViewController:alertVC animated:YES completion:nil];
- }];
- action4.backgroundColor = UIColorHex(#F64A33);
- UISwipeActionsConfiguration *actions = [UISwipeActionsConfiguration configurationWithActions:@[action4,action3,action2,action1]];
- actions.performsFirstActionWithFullSwipe = NO;
- return actions;
- }
- }
- #else
- - (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
- if (indexPath.section == 0) {
- return @[];
- }else{
- WEAKSELF
- UITableViewRowAction *action1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"转发" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
- }];
- action1.backgroundColor = UIColorHex(#FF923A);
-
- UITableViewRowAction *action2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"置顶" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
- }];
- action2.backgroundColor = UIColorHex(#9BA9CB);
-
- UITableViewRowAction *action3 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"移动" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
-
- }];
- action3.backgroundColor = UIColorHex(#589AF1);
-
- UITableViewRowAction *action4 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
- UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction *ok = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-
- }];
- [ok setValue:k9 forKey:@"_titleTextColor"];
- UIAlertAction *noOk = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- }];
- [alertVC addAction:ok];
- [alertVC addAction:noOk];
- [weakSelf presentViewController:alertVC animated:YES completion:nil];
- }];
- action4.backgroundColor = UIColorHex(#F64A33);
- return @[action4, action3, action2,action1];
- }
- }
- #endif
- @end
|