ShowPhotoesViewController.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //
  2. // ShowPhotosViewController.m
  3. // LN_School
  4. //
  5. // Created by 张嵘 on 2019/7/28.
  6. // Copyright © 2019 Danson. All rights reserved.
  7. //
  8. #import "ShowPhotoesViewController.h"
  9. #import "ShowPhotoesViewModel.h"
  10. #import <IDMPhotoBrowser/IDMPhotoBrowser.h>
  11. #import "ShowPhotoesModel.h"
  12. @interface ShowPhotoesViewController ()
  13. @property (nonatomic, readwrite, strong) HDCollectionView *collectionView;
  14. @property (nonatomic, readwrite, strong) ShowPhotoesViewModel *showPhotoesViewModel;
  15. @property (nonatomic, readwrite, strong) NSMutableArray *dataSourceArr;
  16. @end
  17. @implementation ShowPhotoesViewController
  18. #pragma mark - Life Cycle
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. [self initUI];
  22. }
  23. #pragma mark - Private Functions
  24. - (void)initUI {
  25. self.title = @"查看照片";
  26. self.view.backgroundColor = KBackGroundColor;
  27. [self goBackByNavigation];
  28. [self.view addSubview:self.collectionView];
  29. [_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  30. make.left.mas_equalTo(self.view.hd_mas_left);
  31. make.right.mas_equalTo(self.view.hd_mas_right);
  32. make.bottom.mas_equalTo(self.view.hd_mas_bottom);
  33. make.top.mas_equalTo(self.view.hd_mas_top);
  34. }];
  35. /// 初始化数据
  36. __weak typeof(self) weakS = self;
  37. _collectionView.collectionV.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  38. [self.showPhotoesViewModel loadData:^(BOOL success, id _Nonnull res) {
  39. [_collectionView.collectionV.mj_header endRefreshing];
  40. NSMutableArray *resArr = res;
  41. HDSectionModel *secModel = resArr.firstObject;
  42. if (success) {
  43. [secModel.sectionDataArr.rac_sequence.signal subscribeNext:^(HDCellModel * _Nullable cellModel) {
  44. if ([cellModel.orgData isKindOfClass:[ShowPhotoesModel class]]) {
  45. ShowPhotoesModel *showPhotoesModel = cellModel.orgData;
  46. [self.dataSourceArr addObject:showPhotoesModel.url];
  47. }
  48. }];
  49. [_collectionView hd_setAllDataArr:res];
  50. }else{
  51. //error
  52. }
  53. }];
  54. }];
  55. _collectionView.collectionV.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  56. [self.showPhotoesViewModel loadData:^(BOOL success, id _Nonnull res) {
  57. [_collectionView.collectionV.mj_footer endRefreshing];
  58. NSMutableArray *resArr = res;
  59. HDSectionModel *secModel = resArr.firstObject;
  60. if (success) {
  61. [secModel.sectionDataArr.rac_sequence.signal subscribeNext:^(HDCellModel * _Nullable cellModel) {
  62. if ([cellModel.orgData isKindOfClass:[ShowPhotoesModel class]]) {
  63. ShowPhotoesModel *showPhotoesModel = cellModel.orgData;
  64. [self.dataSourceArr addObject:showPhotoesModel.url];
  65. }
  66. }];
  67. [_collectionView hd_setAllDataArr:res];
  68. }else{
  69. //error
  70. }
  71. }];
  72. }];
  73. [_collectionView.collectionV.mj_header beginRefreshing];
  74. [_collectionView hd_setAllEventCallBack:^(id backModel, HDCallBackType type) {
  75. if (type == HDCellCallBack) {
  76. [weakS clickCell:backModel];
  77. }else if (type == HDSectionHeaderCallBack){
  78. [weakS clickHeader:backModel];
  79. }
  80. }];
  81. }
  82. - (void)clickCell:(HDCellModel*)cellM {
  83. NSLog(@"点击了%zd--%zd cell",cellM.indexP.section,cellM.indexP.item);
  84. IDMPhotoBrowser *brower = [[IDMPhotoBrowser alloc] initWithPhotoURLs:self.dataSourceArr animatedFromView:self.view];
  85. [brower setInitialPageIndex:cellM.indexP.item];
  86. [self.navigationController presentViewController:brower animated:YES completion:nil];
  87. }
  88. - (void)clickHeader:(HDSectionModel*)secM {
  89. NSLog(@"点击了段头");
  90. }
  91. #pragma mark - Lazy Load
  92. - (HDCollectionView *)collectionView {
  93. if (!_collectionView) {
  94. _collectionView = [HDCollectionView hd_makeHDCollectionView:^(HDCollectionViewMaker *maker) {
  95. maker
  96. .hd_isNeedTopStop(YES)
  97. .hd_scrollDirection(UICollectionViewScrollDirectionVertical);
  98. }];
  99. _collectionView.backgroundColor = RQBackGroundColor;
  100. }
  101. return _collectionView;
  102. }
  103. - (ShowPhotoesViewModel *)showPhotoesViewModel {
  104. if (!_showPhotoesViewModel) {
  105. _showPhotoesViewModel = [[ShowPhotoesViewModel alloc] init];
  106. }
  107. return _showPhotoesViewModel;
  108. }
  109. - (NSMutableArray *)dataSourceArr {
  110. if (!_dataSourceArr) {
  111. _dataSourceArr = @[].mutableCopy;
  112. }
  113. return _dataSourceArr;
  114. }
  115. @end