// // YOUPAILCFollowVC.m // LiveChat // // Created by 张灿 on 2018/8/26. // Copyright © 2018年 caicai. All rights reserved. // #import "YOUPAILCFollowVC.h" #import "YOUPAILCRelationCell.h" #import "YOUPAILZUserShowVC.h" #import "YOUPAILZLiveModel.h" #import "YOUPAILZLiveAudienceVC.h" #import "YOUPAILZEndLiveHintView.h" @interface YOUPAILCFollowVC () @property(nonatomic,assign)NSInteger youpaipcurrentPage; @property(nonatomic,assign)NSInteger youpaiptotalPage; @property(nonatomic,strong)NSMutableArray* youpaipuserArray; @property(nonatomic,strong)NSMutableArray* youpaipuserIdArray; @end @implementation YOUPAILCFollowVC - (void)viewDidLoad { [super viewDidLoad]; [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(youpaifchangeFollowStateNotification:) name:@"ChangeFollowState" object:nil];; self.title = @"我的关注"; self.view.backgroundColor = [UIColor whiteColor]; self.youpaipuserArray = [NSMutableArray array]; self.youpaipuserIdArray = [NSMutableArray array]; [self youpaifsetupTableView]; self.tableView.backgroundColor = [UIColor clearColor]; [self.tableView.mj_header beginRefreshing]; } - (void)youpaifchangeFollowStateNotification:(NSNotification *)notification{ NSDictionary *dict = [notification userInfo]; NSString *idStr = dict[@"follow_uid"]; NSInteger isfollow = [dict[@"is_follow"] intValue]; NSArray *arr = self.youpaipuserArray; NSMutableArray *arrM = [NSMutableArray new]; if (arr.count>0) { NSIndexPath *index; for (int i = 0; i=self.youpaiptotalPage) { [self.tableView.mj_footer endRefreshingWithNoMoreData]; self.tableView.mj_footer.hidden = YES; } if (self.youpaipuserArray.count != 0) { [self.tableView lz_hideEmptyView]; }else{ [self.tableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_home_data"] content:@"暂无数据"]; } [self.tableView.mj_header endRefreshing]; }else{ [self.tableView.mj_header endRefreshing]; } } failure:^(NSError *error) { [self.tableView.mj_header endRefreshing]; }]; } - (void)youpaifloadMoreData{ [self.tableView.mj_header endRefreshing]; self.tableView.mj_footer.hidden = YES; [self.tableView.mj_footer endRefreshing]; self.youpaipcurrentPage+=1; [LCHttpHelper requestWithURLString:FollowList parameters:@{@"page":@(self.youpaipcurrentPage)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 NSArray* array = [[dict objectForKey:@"data"]objectForKey:@"list"]; NSMutableArray* modelArray = [YOUPAILCRelationModel mj_objectArrayWithKeyValuesArray:array]; NSMutableArray* tempArray = [NSMutableArray arrayWithArray:(NSArray*)modelArray]; for (YOUPAILCRelationModel* model in modelArray) { if ([self.youpaipuserArray containsObject:model.youpaipuserid]) { [tempArray removeObject:model]; }else{ [self.youpaipuserIdArray addObject:model.youpaipuserid]; } } [self.youpaipuserArray addObjectsFromArray:tempArray]; self.youpaiptotalPage = [[[dict objectForKey:@"data"]objectForKey:@"total_page"]integerValue]; self.youpaipcurrentPage = [[[dict objectForKey:@"data"]objectForKey:@"page"]integerValue]; [self.tableView reloadData]; if (self.youpaipcurrentPage>=self.youpaiptotalPage) { [self.tableView.mj_footer endRefreshingWithNoMoreData]; self.tableView.mj_footer.hidden = YES; } [self.tableView.mj_header endRefreshing]; }else{ [self.tableView.mj_header endRefreshing]; } } failure:^(NSError *error) { [self.tableView.mj_header endRefreshing]; }]; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 70; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.youpaipuserArray.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ YOUPAILCRelationCell* cell = [[YOUPAILCRelationCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"LCRelationCellfollow"]; YOUPAILCRelationModel* model = self.youpaipuserArray[indexPath.row]; cell.youpaiprelationType = @"follow"; cell.youpaiprelationModel = model; @weakify(self); [cell setYoupaipdidIconBlock:^(YOUPAILCRelationModel *model) { @strongify(self); [self youpaifjoinLive:model.youpaiproom_id]; }]; return cell; } -(void)youpaifjoinLive:(NSString*)roomid{ if (roomid) { [ZCHUDHelper showWithStatus:nil]; [LCHttpHelper requestWithURLString:JoinLive parameters:@{@"room_id":roomid} needToken:YES type:HttpRequestTypePost success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { [ZCHUDHelper dismiss]; [[YOUPAILZChatRoomManager shareManager] youpaifcloseChatRoom]; YOUPAILZLiveModel *liveModel = [YOUPAILZLiveModel mj_objectWithKeyValues:[dict objectForKey:@"data"]]; if(liveModel.youpaiptype == 0){ YOUPAILZEndLiveHintModel *model1 = [YOUPAILZEndLiveHintModel mj_objectWithKeyValues:dict[@"data"][@"user_info"]]; YOUPAILZEndLiveHintView *view = [[YOUPAILZEndLiveHintView alloc]initWithFrame:CGRectZero Model:model1]; }else{ [ZCHUDHelper dismiss]; [LCSaveData saveLiveRankTopThere:liveModel.youpaiprank_top_three]; [[NSNotificationCenter defaultCenter] postNotificationName:@"MeCallVideo" object:nil userInfo:nil]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ YOUPAILZLiveAudienceVC *audienceVC = [[YOUPAILZLiveAudienceVC alloc] initWithModel:liveModel]; [self.navigationController pushViewController:audienceVC animated:NO]; }); } }else{ [ZCHUDHelper showTitle:[dict objectForKey:@"message"]]; } } failure:^(NSError *error) { [ZCHUDHelper showTitle:error.localizedDescription]; }]; } } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ YOUPAILCRelationModel* model = self.youpaipuserArray[indexPath.row]; model.youpaipis_watch = 1; [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone]; YOUPAILZUserShowVC *userShow = [[YOUPAILZUserShowVC alloc] init]; userShow.youpaipuserId = model.youpaipuserid; [self.navigationController pushViewController:userShow animated:YES]; } @end