123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- //
- // YOUPAIHRChatRoomSubDetailVC.m
- // VQU
- //
- // Created by xiaohaoran on 2021/11/2.
- // Copyright © 2021 MS. All rights reserved.
- //
- #import "YOUPAIHRChatRoomSubDetailVC.h"
- #import "YOUPAILCHomeCollectionCell.h"
- #import "UIScrollView+LZRefresh.h"
- #import "YOUPAILZUserShowVC.h"
- #import "YOUPAILCVideoChatModel.h"
- #import "YOUPAILCVideoRequestVC.h"
- #import "YOUPAILZLiveModel.h"
- #import "YOUPAILZLiveAudienceVC.h"
- #import "YOUPAILZEndLiveHintView.h"
- #import "YOUPAIHRChatRoomHomeCell.h"
- #import "YOUPAIHRChatRoomSubDetailModel.h"
- #import "YOUPAILZChatRoomPasswordWindow.h"
- #import "UIViewController+TFPresent.h"
- #import "YOUPAILZChatRoomVC.h"
- @interface YOUPAIHRChatRoomSubDetailVC ()<UICollectionViewDataSource,UICollectionViewDelegate>
- @property (nonatomic, strong) NSMutableArray <YOUPAIHRChatRoomSubDetailModel *>*youpaipdataSource;
- @property (nonatomic, strong) NSMutableDictionary *youpaipuserDict;
- @property (nonatomic, assign) NSInteger youpaippage;
- @property (nonatomic, weak) UICollectionView *youpaipcollectionView;
- @end
- @implementation YOUPAIHRChatRoomSubDetailVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self youpaifinitUI];
- [self.youpaipcollectionView.mj_header beginRefreshing];
- }
- - (void)youpaifinitUI{
- UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
-
- layout.scrollDirection = UICollectionViewScrollDirectionVertical;
- layout.minimumLineSpacing = 9.0f;
- layout.minimumInteritemSpacing = 1.0f;
- layout.sectionInset = UIEdgeInsetsMake(0.0f, 14, 0, 14);
- // {top, left, bottom, right};
- CGFloat width = (KScreenWidth - 37) / 2.0f;
- layout.itemSize = CGSizeMake(width, 169+34);
- UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
- collectionView.alwaysBounceVertical = YES;
- collectionView.backgroundColor = LCBkgColor;
- collectionView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
- collectionView.dataSource = self;
- collectionView.delegate = self;
- collectionView.scrollEnabled = YES;
-
- collectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
-
-
- [self.view addSubview:collectionView];
- self.youpaipcollectionView = collectionView;
- @weakify(self);
- [collectionView setRefreshHeaderWithBlock:^{
- @strongify(self);
- [self youpaifrequestListWithStatus:kRefreshHeader];
- }];
- [collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.bottom.offset(0.0f);
- }];
- }
- -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
-
- UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
- cell.userInteractionEnabled = NO;
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- cell.userInteractionEnabled = YES;
- });
-
- YOUPAIHRChatRoomSubDetailModel *model = self.youpaipdataSource[indexPath.item];
- NSString *roomId = [NSString stringWithFormat:@"%@",@(model.youpaiproom_id)];
-
- if ([[YOUPAILZChatRoomManager shareManager].chatroomModel.youpaiproom_id isEqual:roomId] && [YOUPAILZChatRoomManager shareManager].chatroomController != nil) {
- [[YOUPAILZChatRoomManager shareManager] youpaifshowChatRoom];
- return;
- }
- [self youpaifshowPasswordWindowWithRoomId:roomId youpaipis_comein_room_hide:0];
- }
- - (void)youpaifshowPasswordWindowWithRoomId:(NSString *)roomId youpaipis_comein_room_hide:(NSInteger)youpaipis_comein_room_hide{
- @weakify(self);
- [LCHttpHelper requestWithURLString:GetRoomStatus parameters:@{@"room_id":roomId} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- @strongify(self);
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code==0) {
- NSDictionary *data = [dict objectForKey:@"data"];
- if ([[data objectForKey:@"pwd"] integerValue] == 1) { // 有密码
- YOUPAILZChatRoomPasswordWindow *window = [[YOUPAILZChatRoomPasswordWindow alloc] init];
- [window setYoupaippasswordBlock:^(NSString * _Nonnull password, YOUPAILZChatRoomPasswordWindow * _Nonnull window) {
- @strongify(self);
- [self youpaifgoChatRoomVCWithPwd:password RoomId:roomId youpaipis_comein_room_hide:youpaipis_comein_room_hide window:window];
- }];
- [self TFPresentVC:window completion:^{}];
- }else{
- [self youpaifgoChatRoomVCWithPwd:@"" RoomId:roomId youpaipis_comein_room_hide:youpaipis_comein_room_hide window:nil];
- }
- }
- } failure:^(NSError *error) {
-
- }];
- }
- /// 加入语聊房
- /// @param pwd 密码
- /// @param roomId 房间号
- /// @param youpaipis_comein_room_hide 是否悄悄进房
- /// @param window 密码框
- - (void)youpaifgoChatRoomVCWithPwd:(NSString *)pwd RoomId:(NSString *)roomId youpaipis_comein_room_hide:(NSInteger)youpaipis_comein_room_hide window:(YOUPAILZChatRoomPasswordWindow *)window{
- [ZCHUDHelper show];
- @weakify(self);
- [LCHttpHelper requestWithURLString:JoinTalk parameters:@{@"room_id":roomId,@"pwd":pwd,@"is_comein_room_hide":@(youpaipis_comein_room_hide)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- [ZCHUDHelper dismiss];
- @strongify(self);
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code==0) {
- if (window != nil) {
- [window dismissViewControllerAnimated:YES completion:^{}];
- }
- [[YOUPAILZChatRoomManager shareManager] youpaifleaveChannel];
- YOUPAILZChatRoomModel *youpaipchatroomModel = [YOUPAILZChatRoomModel mj_objectWithKeyValues:dict[@"data"]];
- // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- YOUPAILZChatRoomVC *vc = [[YOUPAILZChatRoomVC alloc] init];
- vc.youpaipchatroomModel = youpaipchatroomModel;
- [self.navigationController pushViewController:vc animated:YES];
- [YOUPAILZChatRoomManager shareManager].chatroomModel = vc.youpaipchatroomModel;
- [YOUPAILZChatRoomManager shareManager].chatroomController = vc;
- // });
-
- }else{
- if (window != nil) {
- [window youpaifshowHUDWithTitle:[dict objectForKey:@"message"]];
- }else{
- [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
- }
-
- }
- } failure:^(NSError *error) {
- [ZCHUDHelper dismiss];
- }];
- }
- #pragma mark - UICollectionViewDataSource
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- return self.youpaipdataSource.count;
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
-
- NSString *ID = @"HRChatRoomHomeCellID";
- [collectionView registerClass:[YOUPAIHRChatRoomHomeCell class] forCellWithReuseIdentifier:ID];
- YOUPAIHRChatRoomHomeCell *cell = (YOUPAIHRChatRoomHomeCell *)[collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
- YOUPAIHRChatRoomSubDetailModel *model = self.youpaipdataSource[indexPath.row];
- cell.youpaiphomeListModel = model;
-
- UILongPressGestureRecognizer* longgs = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(youpaiflongpress:)];
- [cell addGestureRecognizer:longgs];//为cell添加手势
- longgs.minimumPressDuration = 0.25f;//定义长按识别时长
- longgs.view.tag = indexPath.item;//将手势和cell的序号绑定
- return cell;
- }
- - (void)youpaiflongpress:(UILongPressGestureRecognizer *)ges{
- if(ges.state == UIGestureRecognizerStateEnded){
- NSInteger index = ges.view.tag;
- YOUPAIHRChatRoomSubDetailModel *model = self.youpaipdataSource[index];
- NSString *roomId = [NSString stringWithFormat:@"%@",@(model.youpaiproom_id)];
- if ([[YOUPAILZChatRoomManager shareManager].chatroomModel.youpaiproom_id isEqual:roomId] && [YOUPAILZChatRoomManager shareManager].chatroomController != nil) {
- [[YOUPAILZChatRoomManager shareManager] youpaifshowChatRoom];
- return;
- }
- if(model.youpaipis_comein_room_hide == 1){
- @weakify(self);
- ZCAlertAction* action = [ZCAlertAction actionWithTitle:@"悄悄进房" andblock:^{//举报
- @strongify(self);
- [self youpaifshowPasswordWindowWithRoomId:roomId youpaipis_comein_room_hide:model.youpaipis_comein_room_hide];
- }];
- ZCAlertSheetView* alertSheet = [[ZCAlertSheetView alloc]initWithTitle:nil andShowCancelButton:YES andAction:@[action]];
- alertSheet.alertWindow.hidden = NO;
- [alertSheet show];
- }
- }
- }
- /// 设置加载更多
- - (void)youpaifrefreshFooterWithHidden:(BOOL)hidden{
- @weakify(self);
- [self.youpaipcollectionView setRefreshFooter:hidden withBlock:^{
- @strongify(self);
- [self youpaifrequestListWithStatus:kRefreshFooter];
- }];
- }
- /// 获取列表数据
- - (void)youpaifrequestListWithStatus:(kRefreshStatus)status{
- if (status == kRefreshFooter) {
- self.youpaippage ++;
- }else{
- self.youpaippage = 1;
- }
- @weakify(self);
- [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) {
- @strongify(self);
- [self.youpaipcollectionView endRefreshing:kRefreshAll];
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {//成功
- if (status != kRefreshFooter) {
- [self.youpaipdataSource removeAllObjects];
- [self.youpaipuserDict removeAllObjects];
- }
- NSInteger youpaiptotalPage = [[[dict objectForKey:@"data"] objectForKey:@"total_page"]integerValue];
- NSArray* array = [[dict objectForKey:@"data"]objectForKey:@"list"];
-
- [array enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- YOUPAIHRChatRoomSubDetailModel *model = [YOUPAIHRChatRoomSubDetailModel mj_objectWithKeyValues:obj];
- [self.youpaipdataSource addObject:model];
- }];
-
- // [self.dataSource addObjectsFromArray:list];
- NSInteger currentPage = [[[dict objectForKey:@"data"] objectForKey:@"page"]integerValue];
- if(currentPage>0&¤tPage%5==0)
- {
- [[SDImageCache sharedImageCache]clearMemory];
- }
- [self.youpaipcollectionView reloadData];
-
- [self youpaifrefreshFooterWithHidden:self.youpaippage >= youpaiptotalPage];
- if (self.youpaipdataSource.count != 0) {
- [self.youpaipcollectionView lz_hideEmptyView];
- }else{
-
- NSDictionary *des =[[dict objectForKey:@"data"]objectForKey:@"des"];
-
- [self.youpaipcollectionView lz_showEmptyViewWithUrl:[LCTools getImageUrlWithAddress:des[@"talk_img"]] content:des[@"talk_des"]];
- }
- }
- } failure:^(NSError *error) {
- [self.youpaipcollectionView endRefreshing:kRefreshAll];
- }];
- }
- #pragma mark - getter and setter
- - (NSMutableArray<YOUPAIHRChatRoomSubDetailModel *> *)youpaipdataSource{
- if (!_youpaipdataSource) {
- _youpaipdataSource = [NSMutableArray array];
- }
- return _youpaipdataSource;
- }
- - (NSMutableDictionary *)youpaipuserDict{
- if (!_youpaipuserDict) {
- _youpaipuserDict = [NSMutableDictionary dictionary];
- }
- return _youpaipuserDict;
- }
- #pragma mark - JXCategoryListContainerView
- - (UIView *)listView{
- return self.view;
- }
- @end
|