YOUPAILCFollowVC.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. //
  2. // YOUPAILCFollowVC.m
  3. // LiveChat
  4. //
  5. // Created by 张灿 on 2018/8/26.
  6. // Copyright © 2018年 caicai. All rights reserved.
  7. //
  8. #import "YOUPAILCFollowVC.h"
  9. #import "YOUPAILCRelationCell.h"
  10. #import "YOUPAILZUserShowVC.h"
  11. #import "YOUPAILZLiveModel.h"
  12. #import "YOUPAILZLiveAudienceVC.h"
  13. #import "YOUPAILZEndLiveHintView.h"
  14. @interface YOUPAILCFollowVC ()<UITableViewDelegate,UITableViewDataSource>
  15. @property(nonatomic,assign)NSInteger youpaipcurrentPage;
  16. @property(nonatomic,assign)NSInteger youpaiptotalPage;
  17. @property(nonatomic,strong)NSMutableArray* youpaipuserArray;
  18. @property(nonatomic,strong)NSMutableArray* youpaipuserIdArray;
  19. @end
  20. @implementation YOUPAILCFollowVC
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(youpaifchangeFollowStateNotification:) name:@"ChangeFollowState" object:nil];;
  24. self.title = @"我的关注";
  25. self.view.backgroundColor = [UIColor whiteColor];
  26. self.youpaipuserArray = [NSMutableArray array];
  27. self.youpaipuserIdArray = [NSMutableArray array];
  28. [self youpaifsetupTableView];
  29. self.tableView.backgroundColor = [UIColor clearColor];
  30. [self.tableView.mj_header beginRefreshing];
  31. }
  32. - (void)youpaifchangeFollowStateNotification:(NSNotification *)notification{
  33. NSDictionary *dict = [notification userInfo];
  34. NSString *idStr = dict[@"follow_uid"];
  35. NSInteger isfollow = [dict[@"is_follow"] intValue];
  36. NSArray *arr = self.youpaipuserArray;
  37. NSMutableArray *arrM = [NSMutableArray new];
  38. if (arr.count>0) {
  39. NSIndexPath *index;
  40. for (int i = 0; i<arr.count; i++) {
  41. YOUPAILCRelationModel *model = arr[i];
  42. if ([model.youpaipuserid isEqualToString:idStr]) {
  43. model.youpaipis_follow = isfollow;
  44. index = [NSIndexPath indexPathForRow:i inSection:0];
  45. [arrM addObject:index];
  46. }
  47. }
  48. [self.tableView reloadRowsAtIndexPaths:arrM withRowAnimation:UITableViewRowAnimationFade];
  49. }
  50. NSLog(@"%@",dict[@"follow_uid"]);
  51. }
  52. -(void)dealloc{
  53. [[NSNotificationCenter defaultCenter]removeObserver:self];
  54. }
  55. - (void)youpaifsetupTableView{
  56. self.tableView.frame = CGRectMake(0, NavBarHeight, KScreenWidth, KScreenHeight-NavBarHeight);
  57. self.tableView.showsVerticalScrollIndicator = NO;
  58. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  59. self.tableView.estimatedRowHeight = 74;
  60. self.tableView.delegate = self;
  61. self.tableView.dataSource= self;
  62. self.isAllowScroll = YES;
  63. [self.view addSubview:self.tableView];
  64. self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(youpaifloadNewData)];
  65. MJRefreshAutoNormalFooter* normalFooter = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(youpaifloadMoreData)];
  66. [normalFooter setTitle:@"正在加载..." forState:(MJRefreshStateRefreshing)];
  67. [normalFooter setTitle:@"" forState:(MJRefreshStateNoMoreData)];
  68. self.tableView.mj_footer = normalFooter;
  69. self.tableView.mj_footer.automaticallyHidden = YES;
  70. }
  71. - (void)youpaifloadNewData{
  72. self.tableView.mj_footer.hidden = YES;
  73. [self.tableView.mj_footer endRefreshing];//先结束上拉,假如有的话
  74. self.youpaipcurrentPage = 1;
  75. [LCHttpHelper requestWithURLString:FollowList parameters:@{@"page":@(self.youpaipcurrentPage)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  76. NSDictionary* dict = (NSDictionary*)responseObject;
  77. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  78. if (code==0) {//成功
  79. [self.youpaipuserArray removeAllObjects];
  80. [self.youpaipuserIdArray removeAllObjects];
  81. NSArray* array = [[dict objectForKey:@"data"]objectForKey:@"list"];
  82. NSMutableArray* modelArray = [YOUPAILCRelationModel mj_objectArrayWithKeyValuesArray:array];
  83. NSMutableArray* tempArray = [NSMutableArray arrayWithArray:(NSArray*)modelArray];
  84. for (YOUPAILCRelationModel* model in modelArray) {
  85. if ([self.youpaipuserArray containsObject:model.youpaipuserid]) {
  86. [tempArray removeObject:model];
  87. }else{
  88. [self.youpaipuserIdArray addObject:model.youpaipuserid];
  89. }
  90. }
  91. [self.youpaipuserArray addObjectsFromArray:tempArray];
  92. self.youpaiptotalPage = [[[dict objectForKey:@"data"]objectForKey:@"total_page"]integerValue];
  93. self.youpaipcurrentPage = [[[dict objectForKey:@"data"]objectForKey:@"page"]integerValue];
  94. [self.tableView reloadData];
  95. if (self.youpaipcurrentPage>=self.youpaiptotalPage) {
  96. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  97. self.tableView.mj_footer.hidden = YES;
  98. }
  99. if (self.youpaipuserArray.count != 0) {
  100. [self.tableView lz_hideEmptyView];
  101. }else{
  102. [self.tableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_home_data"] content:@"暂无数据"];
  103. }
  104. [self.tableView.mj_header endRefreshing];
  105. }else{
  106. [self.tableView.mj_header endRefreshing];
  107. }
  108. } failure:^(NSError *error) {
  109. [self.tableView.mj_header endRefreshing];
  110. }];
  111. }
  112. - (void)youpaifloadMoreData{
  113. [self.tableView.mj_header endRefreshing];
  114. self.tableView.mj_footer.hidden = YES;
  115. [self.tableView.mj_footer endRefreshing];
  116. self.youpaipcurrentPage+=1;
  117. [LCHttpHelper requestWithURLString:FollowList parameters:@{@"page":@(self.youpaipcurrentPage)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  118. NSDictionary* dict = (NSDictionary*)responseObject;
  119. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  120. if (code==0) {//成功
  121. NSArray* array = [[dict objectForKey:@"data"]objectForKey:@"list"];
  122. NSMutableArray* modelArray = [YOUPAILCRelationModel mj_objectArrayWithKeyValuesArray:array];
  123. NSMutableArray* tempArray = [NSMutableArray arrayWithArray:(NSArray*)modelArray];
  124. for (YOUPAILCRelationModel* model in modelArray) {
  125. if ([self.youpaipuserArray containsObject:model.youpaipuserid]) {
  126. [tempArray removeObject:model];
  127. }else{
  128. [self.youpaipuserIdArray addObject:model.youpaipuserid];
  129. }
  130. }
  131. [self.youpaipuserArray addObjectsFromArray:tempArray];
  132. self.youpaiptotalPage = [[[dict objectForKey:@"data"]objectForKey:@"total_page"]integerValue];
  133. self.youpaipcurrentPage = [[[dict objectForKey:@"data"]objectForKey:@"page"]integerValue];
  134. [self.tableView reloadData];
  135. if (self.youpaipcurrentPage>=self.youpaiptotalPage) {
  136. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  137. self.tableView.mj_footer.hidden = YES;
  138. }
  139. [self.tableView.mj_header endRefreshing];
  140. }else{
  141. [self.tableView.mj_header endRefreshing];
  142. }
  143. } failure:^(NSError *error) {
  144. [self.tableView.mj_header endRefreshing];
  145. }];
  146. }
  147. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  148. return 70;
  149. }
  150. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  151. return self.youpaipuserArray.count;
  152. }
  153. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  154. YOUPAILCRelationCell* cell = [[YOUPAILCRelationCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"LCRelationCellfollow"];
  155. YOUPAILCRelationModel* model = self.youpaipuserArray[indexPath.row];
  156. cell.youpaiprelationType = @"follow";
  157. cell.youpaiprelationModel = model;
  158. @weakify(self);
  159. [cell setYoupaipdidIconBlock:^(YOUPAILCRelationModel *model) {
  160. @strongify(self);
  161. [self youpaifjoinLive:model.youpaiproom_id];
  162. }];
  163. return cell;
  164. }
  165. -(void)youpaifjoinLive:(NSString*)roomid{
  166. if (roomid) {
  167. [ZCHUDHelper showWithStatus:nil];
  168. [LCHttpHelper requestWithURLString:JoinLive parameters:@{@"room_id":roomid} needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  169. NSDictionary* dict = (NSDictionary*)responseObject;
  170. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  171. if (code == 0) {
  172. [ZCHUDHelper dismiss];
  173. [[YOUPAILZChatRoomManager shareManager] youpaifcloseChatRoom];
  174. YOUPAILZLiveModel *liveModel = [YOUPAILZLiveModel mj_objectWithKeyValues:[dict objectForKey:@"data"]];
  175. if(liveModel.youpaiptype == 0){
  176. YOUPAILZEndLiveHintModel *model1 = [YOUPAILZEndLiveHintModel mj_objectWithKeyValues:dict[@"data"][@"user_info"]];
  177. YOUPAILZEndLiveHintView *view = [[YOUPAILZEndLiveHintView alloc]initWithFrame:CGRectZero Model:model1];
  178. }else{
  179. [ZCHUDHelper dismiss];
  180. [LCSaveData saveLiveRankTopThere:liveModel.youpaiprank_top_three];
  181. [[NSNotificationCenter defaultCenter] postNotificationName:@"MeCallVideo" object:nil userInfo:nil];
  182. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  183. YOUPAILZLiveAudienceVC *audienceVC = [[YOUPAILZLiveAudienceVC alloc] initWithModel:liveModel];
  184. [self.navigationController pushViewController:audienceVC animated:NO];
  185. });
  186. }
  187. }else{
  188. [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
  189. }
  190. } failure:^(NSError *error) {
  191. [ZCHUDHelper showTitle:error.localizedDescription];
  192. }];
  193. }
  194. }
  195. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  196. YOUPAILCRelationModel* model = self.youpaipuserArray[indexPath.row];
  197. model.youpaipis_watch = 1;
  198. [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  199. YOUPAILZUserShowVC *userShow = [[YOUPAILZUserShowVC alloc] init];
  200. userShow.youpaipuserId = model.youpaipuserid;
  201. [self.navigationController pushViewController:userShow animated:YES];
  202. }
  203. @end