RoomUserListView.m 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. //
  2. // RoomUserListView.m
  3. // UniversalApp
  4. //
  5. // Created by bogokj on 2019/8/16.
  6. // Copyright © 2019 voidcat. All rights reserved.
  7. //
  8. #import "RoomUserListView.h"
  9. #import "RoomModel.h"
  10. #import "RoomUserListCell.h"
  11. #import "RoomUserInfo.h"
  12. @interface RoomUserListView ()<UITableViewDelegate,UITableViewDataSource>
  13. @property(nonatomic, strong) UITableView *tableView;
  14. @property(nonatomic, strong) NSMutableArray *dataArray;
  15. @property(nonatomic, strong) UILabel *titleLabel;
  16. @property(nonatomic, strong) UIView *shadowView;
  17. //@property(nonatomic, strong) NSString *page;
  18. @property(nonatomic, assign) int page;
  19. @end
  20. @implementation RoomUserListView
  21. - (instancetype)initWithFrame:(CGRect)frame{
  22. if (self = [super initWithFrame:frame]) {
  23. self.backgroundColor = kWhiteColor;
  24. [self initSubview];
  25. self.page = 1;
  26. }
  27. return self;
  28. }
  29. - (void)initSubview{
  30. [self addSubview:self.titleLabel];
  31. [self addSubview:self.tableView];
  32. }
  33. - (void)refreshData{
  34. __weak __typeof(self)weakSelf = self;
  35. //http://www.bogo.voice.broadcast/mapi/public/index.php/api/Voice_api/get_voice_userlist
  36. NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
  37. [dict setValue:@"voice" forKey:@"ctl"];
  38. [dict setValue:@"audience_list" forKey:@"act"];
  39. [dict setValue:self.room_id forKey:@"room_id"];
  40. [dict setValue:@(self.page) forKey:@"page"];
  41. // [[BGHUDHelper sharedInstance] syncLoading];
  42. [[NetHttpsManager manager] POSTWithParameters:dict SuccessBlock:^(NSDictionary *responseJson) {
  43. // [[BGHUDHelper sharedInstance] syncStopLoading];
  44. if ([responseJson toInt:@"status"] == 1) {
  45. if(self.page == 1)
  46. {
  47. [weakSelf.dataArray removeAllObjects];
  48. }
  49. [self.tableView.mj_header endRefreshing];
  50. [self.tableView.mj_footer endRefreshing];
  51. [self.tableView.mj_header setState:MJRefreshStateIdle];
  52. NSMutableArray *data = responseJson[@"data"];
  53. if(data.count == 0)
  54. {
  55. [self.tableView.mj_footer setState:MJRefreshStateNoMoreData];
  56. }
  57. else
  58. {
  59. [self.tableView.mj_footer setState:MJRefreshStateIdle];
  60. }
  61. for (NSDictionary *dict in data) {
  62. RoomUserInfo *model = [RoomUserInfo mj_objectWithKeyValues:dict];
  63. [weakSelf.dataArray addObject:model];
  64. }
  65. [weakSelf.tableView reloadData];
  66. [weakSelf.titleLabel setText:ASLocalizedString(@"在线观众")];
  67. }
  68. } FailureBlock:^(NSError *error) {
  69. // [[BGHUDHelper sharedInstance] syncStopLoading];
  70. }];
  71. /*
  72. NSString *url = [[CYURLUtils sharedCYURLUtils] makeURLWithC:@"Voice_api" A:@"get_voice_userlist"];
  73. [CYNET POSTv2:url parameters:@{@"id":_model.voice.id} responseCache:^(id responseObject) {
  74. //do nothing
  75. } success:^(id responseObject) {
  76. __strong __typeof(weakSelf)strongSelf = weakSelf;
  77. if ([[responseObject objectForKey:@"code"] integerValue] == 1) {
  78. [strongSelf.dataArray removeAllObjects];
  79. for (NSDictionary *dict in responseObject[@"userlist"]) {
  80. RoomUserInfo *model = [RoomUserInfo mj_objectWithKeyValues:dict];
  81. [strongSelf.dataArray addObject:model];
  82. }
  83. [strongSelf.tableView reloadData];
  84. [strongSelf.titleLabel setText:[NSString stringWithFormat:@"在线观众(%ld人)",strongSelf.dataArray.count]];
  85. }
  86. } failure:^(NSString *error) {
  87. [[HUDHelper sharedInstance] tipMessage:error];
  88. } hasCache:NO];*/
  89. }
  90. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  91. return self.dataArray.count;
  92. }
  93. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  94. RoomUserListCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([RoomUserListCell class]) forIndexPath:indexPath];
  95. [cell setModel:self.dataArray[indexPath.row]];
  96. return cell;
  97. }
  98. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  99. return 80;
  100. }
  101. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  102. RoomUserInfo *info = self.dataArray[indexPath.row];
  103. if (self.delegate && [self.delegate respondsToSelector:@selector(listView:didSelectUser:)]) {
  104. [self.delegate listView:self didSelectUser:info];
  105. }
  106. }
  107. - (void)show:(UIView *)superView{
  108. [self refreshData];
  109. [superView addSubview:self.shadowView];
  110. [superView addSubview:self];
  111. [self becomeFirstResponder];
  112. __weak __typeof(self)weakSelf = self;
  113. [UIView animateWithDuration:0.25 animations:^{
  114. __strong __typeof(weakSelf)strongSelf = weakSelf;
  115. strongSelf.frame = CGRectMake(strongSelf.left, kScreenH / 2, strongSelf.width, strongSelf.height);
  116. }];
  117. }
  118. - (void)hide{
  119. __weak __typeof(self)weakSelf = self;
  120. [UIView animateWithDuration:0.25 animations:^{
  121. __strong __typeof(weakSelf)strongSelf = weakSelf;
  122. strongSelf.frame = CGRectMake(strongSelf.left, kScreenH, strongSelf.width, strongSelf.height);
  123. } completion:^(BOOL finished) {
  124. __strong __typeof(weakSelf)strongSelf = weakSelf;
  125. [strongSelf.shadowView removeFromSuperview];
  126. [strongSelf removeFromSuperview];
  127. }];
  128. }
  129. - (UIView *)shadowView{
  130. if (!_shadowView) {
  131. _shadowView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
  132. _shadowView.backgroundColor = kClearColor;
  133. _shadowView.userInteractionEnabled = YES;
  134. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hide)];
  135. [_shadowView addGestureRecognizer:tap];
  136. }
  137. return _shadowView;
  138. }
  139. - (UILabel *)titleLabel{
  140. if (!_titleLabel) {
  141. _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.width, 70)];
  142. _titleLabel.text = ASLocalizedString(@"在线观众");
  143. _titleLabel.font = [UIFont systemFontOfSize:17];
  144. _titleLabel.textColor = kBlackColor;
  145. _titleLabel.textAlignment = NSTextAlignmentCenter;
  146. }
  147. return _titleLabel;
  148. }
  149. - (UITableView *)tableView{
  150. if (!_tableView) {
  151. _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 50, self.width, self.height - 50) style:UITableViewStylePlain];
  152. [_tableView registerNib:[UINib nibWithNibName:NSStringFromClass([RoomUserListCell class]) bundle:[NSBundle mainBundle]] forCellReuseIdentifier:NSStringFromClass([RoomUserListCell class])];
  153. _tableView.delegate = self;
  154. _tableView.dataSource = self;
  155. _tableView.backgroundColor = kClearColor;
  156. _tableView.showsVerticalScrollIndicator = NO;
  157. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  158. //头部刷新
  159. MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(headerRereshing)];
  160. header.automaticallyChangeAlpha = YES;
  161. header.lastUpdatedTimeLabel.hidden = NO;
  162. _tableView.mj_header = header;
  163. //底部刷新
  164. _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(footerRereshing)];
  165. }
  166. return _tableView;
  167. }
  168. -(void)headerRereshing{
  169. self.page = 1;
  170. [self refreshData];
  171. }
  172. -(void)footerRereshing{
  173. self.page++;
  174. [self refreshData];
  175. }
  176. - (NSMutableArray *)dataArray{
  177. if (!_dataArray) {
  178. _dataArray = [NSMutableArray array];
  179. }
  180. return _dataArray;
  181. }
  182. @end