YOUPAIHRChatRoomSubDetailVC.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. //
  2. // YOUPAIHRChatRoomSubDetailVC.m
  3. // VQU
  4. //
  5. // Created by xiaohaoran on 2021/11/2.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAIHRChatRoomSubDetailVC.h"
  9. #import "YOUPAILCHomeCollectionCell.h"
  10. #import "UIScrollView+LZRefresh.h"
  11. #import "YOUPAILZUserShowVC.h"
  12. #import "YOUPAILCVideoChatModel.h"
  13. #import "YOUPAILCVideoRequestVC.h"
  14. #import "YOUPAILZLiveModel.h"
  15. #import "YOUPAILZLiveAudienceVC.h"
  16. #import "YOUPAILZEndLiveHintView.h"
  17. #import "YOUPAIHRChatRoomHomeCell.h"
  18. #import "YOUPAIHRChatRoomSubDetailModel.h"
  19. #import "YOUPAILZChatRoomPasswordWindow.h"
  20. #import "UIViewController+TFPresent.h"
  21. #import "YOUPAILZChatRoomVC.h"
  22. @interface YOUPAIHRChatRoomSubDetailVC ()<UICollectionViewDataSource,UICollectionViewDelegate>
  23. @property (nonatomic, strong) NSMutableArray <YOUPAIHRChatRoomSubDetailModel *>*youpaipdataSource;
  24. @property (nonatomic, strong) NSMutableDictionary *youpaipuserDict;
  25. @property (nonatomic, assign) NSInteger youpaippage;
  26. @property (nonatomic, weak) UICollectionView *youpaipcollectionView;
  27. @end
  28. @implementation YOUPAIHRChatRoomSubDetailVC
  29. - (void)viewDidLoad {
  30. [super viewDidLoad];
  31. [self youpaifinitUI];
  32. [self.youpaipcollectionView.mj_header beginRefreshing];
  33. }
  34. - (void)youpaifinitUI{
  35. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  36. layout.scrollDirection = UICollectionViewScrollDirectionVertical;
  37. layout.minimumLineSpacing = 9.0f;
  38. layout.minimumInteritemSpacing = 1.0f;
  39. layout.sectionInset = UIEdgeInsetsMake(0.0f, 14, 0, 14);
  40. // {top, left, bottom, right};
  41. CGFloat width = (KScreenWidth - 37) / 2.0f;
  42. layout.itemSize = CGSizeMake(width, 169+34);
  43. UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  44. collectionView.alwaysBounceVertical = YES;
  45. collectionView.backgroundColor = LCBkgColor;
  46. collectionView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
  47. collectionView.dataSource = self;
  48. collectionView.delegate = self;
  49. collectionView.scrollEnabled = YES;
  50. collectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  51. [self.view addSubview:collectionView];
  52. self.youpaipcollectionView = collectionView;
  53. @weakify(self);
  54. [collectionView setRefreshHeaderWithBlock:^{
  55. @strongify(self);
  56. [self youpaifrequestListWithStatus:kRefreshHeader];
  57. }];
  58. [collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  59. make.left.right.top.bottom.offset(0.0f);
  60. }];
  61. }
  62. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  63. UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
  64. cell.userInteractionEnabled = NO;
  65. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  66. cell.userInteractionEnabled = YES;
  67. });
  68. YOUPAIHRChatRoomSubDetailModel *model = self.youpaipdataSource[indexPath.item];
  69. NSString *roomId = [NSString stringWithFormat:@"%@",@(model.youpaiproom_id)];
  70. if ([[YOUPAILZChatRoomManager shareManager].chatroomModel.youpaiproom_id isEqual:roomId] && [YOUPAILZChatRoomManager shareManager].chatroomController != nil) {
  71. [[YOUPAILZChatRoomManager shareManager] youpaifshowChatRoom];
  72. return;
  73. }
  74. [self youpaifshowPasswordWindowWithRoomId:roomId youpaipis_comein_room_hide:0];
  75. }
  76. - (void)youpaifshowPasswordWindowWithRoomId:(NSString *)roomId youpaipis_comein_room_hide:(NSInteger)youpaipis_comein_room_hide{
  77. @weakify(self);
  78. [LCHttpHelper requestWithURLString:GetRoomStatus parameters:@{@"room_id":roomId} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  79. @strongify(self);
  80. NSDictionary* dict = (NSDictionary*)responseObject;
  81. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  82. if (code==0) {
  83. NSDictionary *data = [dict objectForKey:@"data"];
  84. if ([[data objectForKey:@"pwd"] integerValue] == 1) { // 有密码
  85. YOUPAILZChatRoomPasswordWindow *window = [[YOUPAILZChatRoomPasswordWindow alloc] init];
  86. [window setYoupaippasswordBlock:^(NSString * _Nonnull password, YOUPAILZChatRoomPasswordWindow * _Nonnull window) {
  87. @strongify(self);
  88. [self youpaifgoChatRoomVCWithPwd:password RoomId:roomId youpaipis_comein_room_hide:youpaipis_comein_room_hide window:window];
  89. }];
  90. [self TFPresentVC:window completion:^{}];
  91. }else{
  92. [self youpaifgoChatRoomVCWithPwd:@"" RoomId:roomId youpaipis_comein_room_hide:youpaipis_comein_room_hide window:nil];
  93. }
  94. }
  95. } failure:^(NSError *error) {
  96. }];
  97. }
  98. /// 加入语聊房
  99. /// @param pwd 密码
  100. /// @param roomId 房间号
  101. /// @param youpaipis_comein_room_hide 是否悄悄进房
  102. /// @param window 密码框
  103. - (void)youpaifgoChatRoomVCWithPwd:(NSString *)pwd RoomId:(NSString *)roomId youpaipis_comein_room_hide:(NSInteger)youpaipis_comein_room_hide window:(YOUPAILZChatRoomPasswordWindow *)window{
  104. [ZCHUDHelper show];
  105. @weakify(self);
  106. [LCHttpHelper requestWithURLString:JoinTalk parameters:@{@"room_id":roomId,@"pwd":pwd,@"is_comein_room_hide":@(youpaipis_comein_room_hide)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  107. [ZCHUDHelper dismiss];
  108. @strongify(self);
  109. NSDictionary* dict = (NSDictionary*)responseObject;
  110. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  111. if (code==0) {
  112. if (window != nil) {
  113. [window dismissViewControllerAnimated:YES completion:^{}];
  114. }
  115. [[YOUPAILZChatRoomManager shareManager] youpaifleaveChannel];
  116. YOUPAILZChatRoomModel *youpaipchatroomModel = [YOUPAILZChatRoomModel mj_objectWithKeyValues:dict[@"data"]];
  117. // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  118. YOUPAILZChatRoomVC *vc = [[YOUPAILZChatRoomVC alloc] init];
  119. vc.youpaipchatroomModel = youpaipchatroomModel;
  120. [self.navigationController pushViewController:vc animated:YES];
  121. [YOUPAILZChatRoomManager shareManager].chatroomModel = vc.youpaipchatroomModel;
  122. [YOUPAILZChatRoomManager shareManager].chatroomController = vc;
  123. // });
  124. }else{
  125. if (window != nil) {
  126. [window youpaifshowHUDWithTitle:[dict objectForKey:@"message"]];
  127. }else{
  128. [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
  129. }
  130. }
  131. } failure:^(NSError *error) {
  132. [ZCHUDHelper dismiss];
  133. }];
  134. }
  135. #pragma mark - UICollectionViewDataSource
  136. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  137. return self.youpaipdataSource.count;
  138. }
  139. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  140. NSString *ID = @"HRChatRoomHomeCellID";
  141. [collectionView registerClass:[YOUPAIHRChatRoomHomeCell class] forCellWithReuseIdentifier:ID];
  142. YOUPAIHRChatRoomHomeCell *cell = (YOUPAIHRChatRoomHomeCell *)[collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
  143. YOUPAIHRChatRoomSubDetailModel *model = self.youpaipdataSource[indexPath.row];
  144. cell.youpaiphomeListModel = model;
  145. UILongPressGestureRecognizer* longgs = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(youpaiflongpress:)];
  146. [cell addGestureRecognizer:longgs];//为cell添加手势
  147. longgs.minimumPressDuration = 0.25f;//定义长按识别时长
  148. longgs.view.tag = indexPath.item;//将手势和cell的序号绑定
  149. return cell;
  150. }
  151. - (void)youpaiflongpress:(UILongPressGestureRecognizer *)ges{
  152. if(ges.state == UIGestureRecognizerStateEnded){
  153. NSInteger index = ges.view.tag;
  154. YOUPAIHRChatRoomSubDetailModel *model = self.youpaipdataSource[index];
  155. NSString *roomId = [NSString stringWithFormat:@"%@",@(model.youpaiproom_id)];
  156. if ([[YOUPAILZChatRoomManager shareManager].chatroomModel.youpaiproom_id isEqual:roomId] && [YOUPAILZChatRoomManager shareManager].chatroomController != nil) {
  157. [[YOUPAILZChatRoomManager shareManager] youpaifshowChatRoom];
  158. return;
  159. }
  160. if(model.youpaipis_comein_room_hide == 1){
  161. @weakify(self);
  162. ZCAlertAction* action = [ZCAlertAction actionWithTitle:@"悄悄进房" andblock:^{//举报
  163. @strongify(self);
  164. [self youpaifshowPasswordWindowWithRoomId:roomId youpaipis_comein_room_hide:model.youpaipis_comein_room_hide];
  165. }];
  166. ZCAlertSheetView* alertSheet = [[ZCAlertSheetView alloc]initWithTitle:nil andShowCancelButton:YES andAction:@[action]];
  167. alertSheet.alertWindow.hidden = NO;
  168. [alertSheet show];
  169. }
  170. }
  171. }
  172. /// 设置加载更多
  173. - (void)youpaifrefreshFooterWithHidden:(BOOL)hidden{
  174. @weakify(self);
  175. [self.youpaipcollectionView setRefreshFooter:hidden withBlock:^{
  176. @strongify(self);
  177. [self youpaifrequestListWithStatus:kRefreshFooter];
  178. }];
  179. }
  180. /// 获取列表数据
  181. - (void)youpaifrequestListWithStatus:(kRefreshStatus)status{
  182. if (status == kRefreshFooter) {
  183. self.youpaippage ++;
  184. }else{
  185. self.youpaippage = 1;
  186. }
  187. @weakify(self);
  188. [LCHttpHelper requestWithURLString:GetHotRecommend parameters:@{@"page":@(self.youpaippage),@"type":[NSString stringWithFormat:@"%ld",self.youpaiptype],@"number":[NSString stringWithFormat:@"%d",15]} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  189. @strongify(self);
  190. [self.youpaipcollectionView endRefreshing:kRefreshAll];
  191. NSDictionary* dict = (NSDictionary*)responseObject;
  192. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  193. if (code == 0) {//成功
  194. if (status != kRefreshFooter) {
  195. [self.youpaipdataSource removeAllObjects];
  196. [self.youpaipuserDict removeAllObjects];
  197. }
  198. NSInteger youpaiptotalPage = [[[dict objectForKey:@"data"] objectForKey:@"total_page"]integerValue];
  199. NSArray* array = [[dict objectForKey:@"data"]objectForKey:@"list"];
  200. [array enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  201. YOUPAIHRChatRoomSubDetailModel *model = [YOUPAIHRChatRoomSubDetailModel mj_objectWithKeyValues:obj];
  202. [self.youpaipdataSource addObject:model];
  203. }];
  204. // [self.dataSource addObjectsFromArray:list];
  205. NSInteger currentPage = [[[dict objectForKey:@"data"] objectForKey:@"page"]integerValue];
  206. if(currentPage>0&&currentPage%5==0)
  207. {
  208. [[SDImageCache sharedImageCache]clearMemory];
  209. }
  210. [self.youpaipcollectionView reloadData];
  211. [self youpaifrefreshFooterWithHidden:self.youpaippage >= youpaiptotalPage];
  212. if (self.youpaipdataSource.count != 0) {
  213. [self.youpaipcollectionView lz_hideEmptyView];
  214. }else{
  215. NSDictionary *des =[[dict objectForKey:@"data"]objectForKey:@"des"];
  216. [self.youpaipcollectionView lz_showEmptyViewWithUrl:[LCTools getImageUrlWithAddress:des[@"talk_img"]] content:des[@"talk_des"]];
  217. }
  218. }
  219. } failure:^(NSError *error) {
  220. [self.youpaipcollectionView endRefreshing:kRefreshAll];
  221. }];
  222. }
  223. #pragma mark - getter and setter
  224. - (NSMutableArray<YOUPAIHRChatRoomSubDetailModel *> *)youpaipdataSource{
  225. if (!_youpaipdataSource) {
  226. _youpaipdataSource = [NSMutableArray array];
  227. }
  228. return _youpaipdataSource;
  229. }
  230. - (NSMutableDictionary *)youpaipuserDict{
  231. if (!_youpaipuserDict) {
  232. _youpaipuserDict = [NSMutableDictionary dictionary];
  233. }
  234. return _youpaipuserDict;
  235. }
  236. #pragma mark - JXCategoryListContainerView
  237. - (UIView *)listView{
  238. return self.view;
  239. }
  240. @end