YMHomePageListViewControllerOnline.m 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. //
  2. // YMHomeChildController.m
  3. // MSYOUPAI
  4. //
  5. // Created by You on 2024/4/18.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMHomePageListViewControllerOnline.h"
  9. #import "YMHomePageListViewModel.h"
  10. #import "YMChatNotificationViewModel.h"
  11. #import "CHTCollectionViewWaterfallLayout.h"
  12. #import "YMHomeChildCollectCell.h"
  13. @interface YMHomePageListViewControllerOnline ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout,CHTCollectionViewDelegateWaterfallLayout>
  14. /// 滚动视图回调
  15. @property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView);
  16. /// 列表VM
  17. @property (nonatomic, strong) YMHomePageListViewModel *viewModel;
  18. /// 内容排版
  19. @property (nonatomic, strong) CHTCollectionViewWaterfallLayout *contentLayout;
  20. /// 容器列表
  21. @property (nonatomic, strong) UICollectionView *contentCollectionView;
  22. @end
  23. @implementation YMHomePageListViewControllerOnline
  24. @dynamic viewModel;
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. [self setNavHidden:YES];
  28. [OCNotificationCenter addObserver:self selector:@selector(refreshHomeData:) name:REFRESH_HOME_NOTIFICATION object:nil];
  29. self.viewModel.jxCategoryPageIndex = self.jxCategoryPageIndex;
  30. YMEmptyView *empty = [YMEmptyView emptyActionViewWithImage:ImageByName(@"ym_common_no_data_icon") titleStr:@"开启“个性化推荐”后可启用推荐列表" detailStr:@"" btnTitleStr:@"立即开启" btnClickBlock:^{
  31. YMChatNotificationViewModel *chatNotificationVM = [[YMChatNotificationViewModel alloc]initWithParams:@{}];
  32. [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_CHAT_NOTIFICATION) withUserInfo:@{
  33. RouterViewModel:chatNotificationVM
  34. } completion:nil];
  35. }];
  36. empty.contentViewOffset = adapt(-80);
  37. empty.imageSize = kEmptyViewSize;
  38. empty.titleLabFont = LCFont(13);
  39. empty.titleLabTextColor = HexColorFromRGB(0x9b9b9b);
  40. empty.actionBtnCornerRadius = adapt(10);
  41. empty.actionBtnTitleColor = HexColorFromRGB(0xFFFFFF);
  42. empty.actionBtnBackGroundColor = HexColorFromRGB(0xfd7bc5);
  43. self.view.ym_emptyView = empty;
  44. self.view.ym_emptyView.autoShowEmptyView = NO;
  45. }
  46. - (void)viewWillAppear:(BOOL)animated{
  47. [super viewWillAppear:animated];
  48. [self homePageIsHidePersonalizedRecommendationTips];
  49. }
  50. - (void)ym_setupViews {
  51. [self.view addSubview:self.contentCollectionView];
  52. [self.view setNeedsUpdateConstraints];
  53. [self.view updateConstraintsIfNeeded];
  54. }
  55. - (void)updateViewConstraints {
  56. [self.contentCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  57. make.top.left.right.bottom.equalTo(self.view);
  58. }];
  59. [super updateViewConstraints];
  60. }
  61. - (void)ym_bindViewModel {
  62. [self headerRefreshing];
  63. @weakify(self)
  64. [[self.viewModel.refreshUISubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id result) {
  65. @strongify(self)
  66. [self.contentCollectionView reloadData];
  67. switch ([result intValue]) {
  68. case YMHeaderRefresh_HasMoreData:
  69. case YMHeaderRefresh_HasNoMoreData:
  70. {
  71. [self.contentCollectionView.mj_header endRefreshing];
  72. [self.contentCollectionView.mj_footer endRefreshing];
  73. }
  74. break;
  75. case YMFooterRefresh_HasMoreData:
  76. {
  77. [self.contentCollectionView.mj_header endRefreshing];
  78. [self.contentCollectionView.mj_footer endRefreshing];
  79. if (self.contentCollectionView.mj_footer == self.noLoadMoreFooter) {
  80. self.contentCollectionView.mj_footer = self.loadMoreFooter;
  81. }
  82. }
  83. break;
  84. case YMFooterRefresh_HasNoMoreData:
  85. {
  86. [self.contentCollectionView.mj_header endRefreshing];
  87. [self.contentCollectionView.mj_footer endRefreshing];
  88. if (self.contentCollectionView.mj_footer == self.loadMoreFooter) {
  89. self.contentCollectionView.mj_footer = self.noLoadMoreFooter;
  90. }
  91. }
  92. break;
  93. case YMRefreshError: {
  94. [self.contentCollectionView.mj_header endRefreshing];
  95. [self.contentCollectionView.mj_footer endRefreshing];
  96. }
  97. break;
  98. default:
  99. break;
  100. }
  101. [self.contentCollectionView ym_endLoading];
  102. }];
  103. }
  104. #pragma mark - UICollectionViewDataSource
  105. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  106. return 1;
  107. }
  108. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  109. return self.viewModel.listDataArray.count;
  110. }
  111. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  112. YMHomeChildCollectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([YMHomeChildCollectCell class]) forIndexPath:indexPath];
  113. YMHomePageListCellViewModel *cellVM = self.viewModel.listDataArray[indexPath.item];
  114. cellVM.jxCategoryPageIndex = self.jxCategoryPageIndex;
  115. cellVM.jxPageTitle = self.jxPageTitle;
  116. [cellVM updateWithPageIndex];
  117. @weakify(self)
  118. cellVM.changeAccostStatusBlock = ^{
  119. @strongify(self)
  120. [UIView performWithoutAnimation:^{
  121. [self.contentCollectionView reloadItemsAtIndexPaths:@[indexPath]];
  122. }];
  123. };
  124. [cell ym_bindViewModel:cellVM];
  125. return cell;
  126. }
  127. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
  128. UICollectionReusableView *reusableView = nil;
  129. reusableView.backgroundColor = [UIColor clearColor];
  130. return reusableView;
  131. }
  132. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
  133. return CGSizeZero;
  134. }
  135. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{
  136. return CGSizeZero;
  137. }
  138. #pragma mark - UICollectionViewDelegate
  139. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  140. !self.scrollCallback ?: self.scrollCallback(scrollView);
  141. }
  142. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  143. if (self.viewModel.listDataArray[indexPath.item].userId != 0) {
  144. [self.viewModel.gotoPersonalPageSubject sendNext:@(self.viewModel.listDataArray[indexPath.item].userId)];
  145. }
  146. }
  147. #pragma mark - CHTCollectionViewDelegateWaterfallLayout
  148. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  149. return CGSizeMake(adapt(340), adapt(90));
  150. }
  151. ///首页是否隐藏个性化推荐提示
  152. - (void)homePageIsHidePersonalizedRecommendationTips{
  153. if ([[OCUserDefaults objectForKey:kIS_HIDE_PERSONALIZED_RECOMMENDATION_TIPS] boolValue]) {
  154. self.contentCollectionView.hidden = NO;
  155. [self.view ym_hideEmptyView];
  156. } else {
  157. self.contentCollectionView.hidden = YES;
  158. [self.view ym_showEmptyView];
  159. }
  160. }
  161. - (void)refreshHomeData:(NSNotification *)notice{
  162. [self headerRefreshing];
  163. }
  164. - (void)headerRefreshing{
  165. [self.contentCollectionView ym_startLoading];
  166. self.viewModel.currentPage = 1;
  167. [self.viewModel getHomePageListData];
  168. }
  169. - (void)footerRefreshing{
  170. [self.contentCollectionView ym_startLoading];
  171. self.viewModel.currentPage++;
  172. [self.viewModel getHomePageListData];
  173. }
  174. #pragma mark - JXPagingViewListViewDelegate
  175. - (UIView *)listView {
  176. return self.view;
  177. }
  178. - (UIScrollView *)listScrollView {
  179. return self.contentCollectionView;
  180. }
  181. - (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback {
  182. self.scrollCallback = callback;
  183. }
  184. - (void)listWillAppear {
  185. // NSLog(@"%@:%@", self.title, NSStringFromSelector(_cmd));
  186. }
  187. - (void)listDidAppear {
  188. // NSLog(@"%@:%@", self.title, NSStringFromSelector(_cmd));
  189. }
  190. - (void)listWillDisappear {
  191. // NSLog(@"%@:%@", self.title, NSStringFromSelector(_cmd));
  192. }
  193. - (void)listDidDisappear {
  194. // NSLog(@"%@:%@", self.title, NSStringFromSelector(_cmd));
  195. }
  196. - (CHTCollectionViewWaterfallLayout *)contentLayout{
  197. if (!_contentLayout) {
  198. _contentLayout = [[CHTCollectionViewWaterfallLayout alloc] init];
  199. _contentLayout.columnCount = 1;
  200. _contentLayout.sectionInset = UIEdgeInsetsMake(adapt(5), adapt(15), 0, adapt(15));
  201. }
  202. return _contentLayout;
  203. }
  204. - (UICollectionView *)contentCollectionView{
  205. if (!_contentCollectionView) {
  206. _contentCollectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:self.contentLayout];
  207. _contentCollectionView.delegate = self;
  208. _contentCollectionView.dataSource = self;
  209. _contentCollectionView.showsVerticalScrollIndicator = NO;
  210. _contentCollectionView.showsHorizontalScrollIndicator = NO;
  211. _contentCollectionView.backgroundColor = UIColor.whiteColor;
  212. [_contentCollectionView registerClass:[YMHomeChildCollectCell class] forCellWithReuseIdentifier:NSStringFromClass([YMHomeChildCollectCell class])];
  213. _contentCollectionView.mj_footer = self.noLoadMoreFooter;
  214. _contentCollectionView.mj_header = self.refreshHeader;
  215. YMEmptyView *empty = [YMEmptyView emptyViewWithImageStr:@"ym_common_no_data_icon" titleStr:@"暂无数据" detailStr:@""];
  216. empty.imageSize = kEmptyViewSize;
  217. _contentCollectionView.ym_emptyView = empty;
  218. _contentCollectionView.ym_emptyView.autoShowEmptyView = NO;
  219. }
  220. return _contentCollectionView;
  221. }
  222. @end