// // ShowPhotosViewController.m // LN_School // // Created by 张嵘 on 2019/7/28. // Copyright © 2019 Danson. All rights reserved. // #import "ShowPhotoesViewController.h" #import "ShowPhotoesViewModel.h" #import #import "ShowPhotoesModel.h" @interface ShowPhotoesViewController () @property (nonatomic, readwrite, strong) HDCollectionView *collectionView; @property (nonatomic, readwrite, strong) ShowPhotoesViewModel *showPhotoesViewModel; @property (nonatomic, readwrite, strong) NSMutableArray *dataSourceArr; @end @implementation ShowPhotoesViewController #pragma mark - Life Cycle - (void)viewDidLoad { [super viewDidLoad]; [self initUI]; } #pragma mark - Private Functions - (void)initUI { self.title = @"查看照片"; self.view.backgroundColor = KBackGroundColor; [self goBackByNavigation]; [self.view addSubview:self.collectionView]; [_collectionView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.view.hd_mas_left); make.right.mas_equalTo(self.view.hd_mas_right); make.bottom.mas_equalTo(self.view.hd_mas_bottom); make.top.mas_equalTo(self.view.hd_mas_top); }]; /// 初始化数据 __weak typeof(self) weakS = self; _collectionView.collectionV.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{ [self.showPhotoesViewModel loadData:^(BOOL success, id _Nonnull res) { [_collectionView.collectionV.mj_header endRefreshing]; NSMutableArray *resArr = res; HDSectionModel *secModel = resArr.firstObject; if (success) { [secModel.sectionDataArr.rac_sequence.signal subscribeNext:^(HDCellModel * _Nullable cellModel) { if ([cellModel.orgData isKindOfClass:[ShowPhotoesModel class]]) { ShowPhotoesModel *showPhotoesModel = cellModel.orgData; [self.dataSourceArr addObject:showPhotoesModel.url]; } }]; [_collectionView hd_setAllDataArr:res]; }else{ //error } }]; }]; _collectionView.collectionV.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{ [self.showPhotoesViewModel loadData:^(BOOL success, id _Nonnull res) { [_collectionView.collectionV.mj_footer endRefreshing]; NSMutableArray *resArr = res; HDSectionModel *secModel = resArr.firstObject; if (success) { [secModel.sectionDataArr.rac_sequence.signal subscribeNext:^(HDCellModel * _Nullable cellModel) { if ([cellModel.orgData isKindOfClass:[ShowPhotoesModel class]]) { ShowPhotoesModel *showPhotoesModel = cellModel.orgData; [self.dataSourceArr addObject:showPhotoesModel.url]; } }]; [_collectionView hd_setAllDataArr:res]; }else{ //error } }]; }]; [_collectionView.collectionV.mj_header beginRefreshing]; [_collectionView hd_setAllEventCallBack:^(id backModel, HDCallBackType type) { if (type == HDCellCallBack) { [weakS clickCell:backModel]; }else if (type == HDSectionHeaderCallBack){ [weakS clickHeader:backModel]; } }]; } - (void)clickCell:(HDCellModel*)cellM { NSLog(@"点击了%zd--%zd cell",cellM.indexP.section,cellM.indexP.item); IDMPhotoBrowser *brower = [[IDMPhotoBrowser alloc] initWithPhotoURLs:self.dataSourceArr animatedFromView:self.view]; [brower setInitialPageIndex:cellM.indexP.item]; [self.navigationController presentViewController:brower animated:YES completion:nil]; } - (void)clickHeader:(HDSectionModel*)secM { NSLog(@"点击了段头"); } #pragma mark - Lazy Load - (HDCollectionView *)collectionView { if (!_collectionView) { _collectionView = [HDCollectionView hd_makeHDCollectionView:^(HDCollectionViewMaker *maker) { maker .hd_isNeedTopStop(YES) .hd_scrollDirection(UICollectionViewScrollDirectionVertical); }]; _collectionView.backgroundColor = RQBackGroundColor; } return _collectionView; } - (ShowPhotoesViewModel *)showPhotoesViewModel { if (!_showPhotoesViewModel) { _showPhotoesViewModel = [[ShowPhotoesViewModel alloc] init]; } return _showPhotoesViewModel; } - (NSMutableArray *)dataSourceArr { if (!_dataSourceArr) { _dataSourceArr = @[].mutableCopy; } return _dataSourceArr; } @end