XYChatRoomCollectionListViewController.m 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. //
  2. // XYChatRoomCollectionListViewController.m
  3. // Starbuds
  4. //
  5. // Created by 翟玉磊 on 2020/6/19.
  6. // Copyright © 2020 翟玉磊. All rights reserved.
  7. //
  8. #import "XYChatRoomCollectionListViewController.h"
  9. #import "XYChatRoomListViewModel.h"
  10. #import "XYChatRoomListModel.h"
  11. #import "XYChatRoomListCollectionViewCell.h"
  12. #import "XYChatRoomOneBigImageCollectionViewCell.h"
  13. #import "XYChatRoomOneGraphicCollectionViewCell.h"
  14. #import "XYChatRoomCategoriesModel.h"
  15. #import "XYCarefulPersonCell.h"
  16. @interface XYChatRoomCollectionListViewController ()
  17. @property (nonatomic, strong) XYChatRoomListViewModel *viewModel;
  18. @end
  19. @implementation XYChatRoomCollectionListViewController
  20. /// 重写init方法,配置你想要的属性
  21. - (instancetype)init
  22. {
  23. self = [super init];
  24. if (self) {
  25. }
  26. return self;
  27. }
  28. - (void)viewWillAppear:(BOOL)animated {
  29. [super viewWillAppear:animated];
  30. if (self.categoriesModel.chatRoom_Type == XYChatRoom_Type_Collect) {
  31. // [self collectionViewDidTriggerHeaderRefresh];
  32. }
  33. }
  34. - (void)viewDidLoad {
  35. [super viewDidLoad];
  36. /// 设置
  37. [self _setup];
  38. /// 设置导航栏
  39. [self _setupNavigationItem];
  40. /// 设置子控件
  41. [self _setupSubViews];
  42. /// 布局子空间
  43. [self _makeSubViewsConstraints];
  44. // 注册cell
  45. [self.collectionView registerCell:NSStringFromClass([XYCarefulPersonCell class])];
  46. [self.collectionView registerCell:NSStringFromClass([XYChatRoomListCollectionViewCell class])];
  47. [self.collectionView registerCell:NSStringFromClass([XYChatRoomOneBigImageCollectionViewCell class])];
  48. [self.collectionView registerCell:NSStringFromClass([XYChatRoomOneGraphicCollectionViewCell class])];
  49. //[self collectionViewDidTriggerHeaderRefresh];
  50. if (self.categoriesModel.autoLoad) {
  51. [self base_reloadListData];
  52. }
  53. }
  54. #pragma mark — Override
  55. - (UIEdgeInsets)contentInset {
  56. return UIEdgeInsetsMake(0, 0, TABBAR_HEIGHT, 0);
  57. }
  58. - (void)bindViewModel {
  59. self.viewModel = XYChatRoomListViewModel.new;
  60. self.viewModel.categoriesModel = self.categoriesModel;
  61. if (self.categoriesModel.chatRoom_Type == XYChatRoom_Type_Friends) {
  62. self.viewModel.shouldPullDownToRefresh = YES;
  63. }
  64. }
  65. - (void)base_reloadListData {
  66. [self collectionViewDidTriggerHeaderRefresh];
  67. }
  68. - (void)collectionViewDidTriggerHeaderRefresh {
  69. self.viewModel.pullDown = YES;
  70. [self.viewModel loadData:^(id _Nullable responseModel) {
  71. [self collectionViewDidFinishTriggerHeader:YES reload:YES];
  72. [self.collectionView zyl_configEmptyViewWithType:ZYLEmptyDataViewTypeDefault emptyInfo:@"" errorInfo:@"" offsetTop:150.0f hasData:self.viewModel.dataSource.count>0 hasError:NO reloadBlock:nil];
  73. if (self.delegate && [self.delegate respondsToSelector:@selector(headerRefreshEnding)]) {
  74. [self.delegate headerRefreshEnding];
  75. }
  76. } failure:^(ZYLNetworkError * _Nullable error) {
  77. [self collectionViewDidFinishTriggerHeader:YES reload:NO];
  78. [self.collectionView zyl_configEmptyViewWithType:ZYLEmptyDataViewTypeDefault emptyInfo:@"" errorInfo:error.domain offsetTop:150.0f hasData:self.viewModel.dataSource.count>0 hasError:error!=nil reloadBlock:nil];
  79. if (self.delegate && [self.delegate respondsToSelector:@selector(headerRefreshEnding)]) {
  80. [self.delegate headerRefreshEnding];
  81. }
  82. }];
  83. }
  84. - (void)collectionViewDidTriggerFooterRefresh {
  85. [super collectionViewDidTriggerFooterRefresh];
  86. }
  87. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath {
  88. if (self.categoriesModel.layout == XYVoiceRoomListLayoutOneGraphic) {
  89. return [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XYChatRoomOneGraphicCollectionViewCell class]) forIndexPath:indexPath];
  90. }else if (self.categoriesModel.layout == XYVoiceRoomListLayoutOneBigImage) {
  91. return [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XYChatRoomOneBigImageCollectionViewCell class]) forIndexPath:indexPath];
  92. }else {
  93. XYChatRoomListModel *model = [self.viewModel.dataSource objectAtIndex:indexPath.row];
  94. if (model.carefulPerson) {
  95. return [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XYCarefulPersonCell class]) forIndexPath:indexPath];
  96. }
  97. return [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XYChatRoomListCollectionViewCell class]) forIndexPath:indexPath];
  98. }
  99. }
  100. - (void)configureCell:(XYChatRoomOneGraphicCollectionViewCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object {
  101. [cell configureModel:object];
  102. }
  103. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  104. if (self.categoriesModel.layout == XYVoiceRoomListLayoutOneGraphic) {
  105. return CGSizeMake(SCREEN_WIDTH, 88.0f);
  106. }else if (self.categoriesModel.layout == XYVoiceRoomListLayoutOneBigImage) {
  107. return CGSizeMake(SCREEN_WIDTH - 10.0f * 2, 120.0f + 8.0f + 20.0f);
  108. }else {
  109. XYChatRoomListModel *model = [self.viewModel.dataSource objectAtIndex:indexPath.row];
  110. if (model.carefulPerson) {
  111. return CGSizeMake(SCREEN_WIDTH - 32.0f , 140.0f);
  112. }
  113. CGFloat width = (SCREEN_WIDTH - 32.0f - 7.0f)/2;
  114. return CGSizeMake(width, width + 8.0f + 20.0f + 8.0f);
  115. }
  116. }
  117. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
  118. if (self.categoriesModel.layout == XYVoiceRoomListLayoutOneGraphic) {
  119. return 0.0f;
  120. }else if (self.categoriesModel.layout == XYVoiceRoomListLayoutOneBigImage) {
  121. return 16.0f;
  122. }else {
  123. return 12.0f;
  124. }
  125. }
  126. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
  127. if (self.categoriesModel.layout == XYVoiceRoomListLayoutOneGraphic) {
  128. return 0.0f;
  129. }else if (self.categoriesModel.layout == XYVoiceRoomListLayoutOneBigImage) {
  130. return 16.0f;
  131. }else {
  132. return 7.0f;
  133. }
  134. }
  135. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
  136. if (self.categoriesModel.layout == XYVoiceRoomListLayoutOneGraphic) {
  137. return UIEdgeInsetsMake(0.0f, 0.0f, 0.0f, 0.0f);
  138. }else if (self.categoriesModel.layout == XYVoiceRoomListLayoutOneBigImage) {
  139. return UIEdgeInsetsMake(8.0f, 16.0f, 8.0f, 16.0f);
  140. }else {
  141. return UIEdgeInsetsMake(8.0f, 16.0f, 0.0f, 16.0f);
  142. }
  143. }
  144. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  145. [collectionView deselectItemAtIndexPath:indexPath animated:YES];
  146. XYChatRoomListModel *model = [self.viewModel.dataSource objectAtIndex:indexPath.row];
  147. if (model.carefulPerson) {
  148. return;
  149. }
  150. if ([model.categoryName isEqualToString:kLocalizedString(@"收藏")]) {
  151. // 派对Tab,点分类-收藏-[房间封面]的次数
  152. [StatisticsManager event:@"party_sort_collection_roomcover_click"];
  153. }else if ([model.categoryName isEqualToString:kLocalizedString(@"热门")]) {
  154. // 派对Tab,点分类-热门-房间封面的次数
  155. [StatisticsManager event:@"party_sort_hot_roomcover_click"];
  156. }
  157. [[XYChatRoomManager sharedInstance] showChatRoomWithRoomId:model.roomId roomCoverUrl:model.roomCover completion:^{
  158. }];
  159. }
  160. #pragma mark - JXCategoryListContentViewDelegate
  161. - (UIView *)listView {
  162. return self.view;
  163. }
  164. #pragma mark - 事件处理Or辅助方法
  165. #pragma mark - 初始化
  166. - (void)_setup{
  167. //self.view.backgroundColor = Color_White;
  168. //self.collectionView.backgroundColor = Color_White;
  169. [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  170. make.edges.equalTo(self.view);
  171. }];
  172. }
  173. #pragma mark - 设置导航栏
  174. - (void)_setupNavigationItem{
  175. }
  176. #pragma mark - 设置子控件
  177. - (void)_setupSubViews{
  178. }
  179. #pragma mark - 布局子控件
  180. - (void)_makeSubViewsConstraints{
  181. }
  182. #pragma mark - Setter & Getter
  183. @end