123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- //
- // 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 ()<UITableViewDelegate,UITableViewDataSource>
- @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<arr.count; i++) {
- YOUPAILCRelationModel *model = arr[i];
- if ([model.youpaipuserid isEqualToString:idStr]) {
- model.youpaipis_follow = isfollow;
- index = [NSIndexPath indexPathForRow:i inSection:0];
- [arrM addObject:index];
- }
-
- }
- [self.tableView reloadRowsAtIndexPaths:arrM withRowAnimation:UITableViewRowAnimationFade];
- }
-
- NSLog(@"%@",dict[@"follow_uid"]);
- }
- -(void)dealloc{
-
- [[NSNotificationCenter defaultCenter]removeObserver:self];
- }
- - (void)youpaifsetupTableView{
- self.tableView.frame = CGRectMake(0, NavBarHeight, KScreenWidth, KScreenHeight-NavBarHeight);
- self.tableView.showsVerticalScrollIndicator = NO;
- self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- self.tableView.estimatedRowHeight = 74;
- self.tableView.delegate = self;
- self.tableView.dataSource= self;
- self.isAllowScroll = YES;
- [self.view addSubview:self.tableView];
-
- self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(youpaifloadNewData)];
- MJRefreshAutoNormalFooter* normalFooter = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(youpaifloadMoreData)];
- [normalFooter setTitle:@"正在加载..." forState:(MJRefreshStateRefreshing)];
- [normalFooter setTitle:@"" forState:(MJRefreshStateNoMoreData)];
- self.tableView.mj_footer = normalFooter;
- self.tableView.mj_footer.automaticallyHidden = YES;
- }
- - (void)youpaifloadNewData{
- 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) {//成功
- [self.youpaipuserArray removeAllObjects];
- [self.youpaipuserIdArray removeAllObjects];
- 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;
- }
- 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
|