guardShowView.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. //
  2. // guardShowView.m
  3. // yunbaolive
  4. //
  5. // Created by Boom on 2018/11/12.
  6. // Copyright © 2018年 cat. All rights reserved.
  7. //
  8. #import "guardShowView.h"
  9. #import "guardListCell.h"
  10. #import "guardListModel.h"
  11. @implementation guardShowView{
  12. NSString *liveUID;
  13. NSDictionary *userMsg;
  14. int page;
  15. UIView *whiteView;
  16. UITableView *listTable;
  17. UILabel *numL;
  18. NSMutableArray *infoArray;
  19. }
  20. - (instancetype)initWithFrame:(CGRect)frame andUserGuardMsg:(NSDictionary *)dic andLiveUid:(NSString *)uid{
  21. self = [super initWithFrame:frame];
  22. liveUID = uid;
  23. userMsg = dic;
  24. infoArray = [NSMutableArray array];
  25. page = 1;
  26. if (self) {
  27. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hideSelf)];
  28. [self addGestureRecognizer:tap];
  29. [self creatUI];
  30. [self requestData];
  31. }
  32. return self;
  33. }
  34. - (void)hidKeyBoard{
  35. }
  36. - (void)creatUI{
  37. whiteView = [[UIView alloc]initWithFrame:CGRectMake(_window_width*0.1, _window_height, _window_width*0.8, _window_width*0.8*1.4)];
  38. whiteView.backgroundColor = [UIColor whiteColor];
  39. whiteView.layer.cornerRadius = 18.0;
  40. whiteView.layer.masksToBounds = YES;
  41. [self addSubview:whiteView];
  42. UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hidKeyBoard)];
  43. [whiteView addGestureRecognizer:tap2];
  44. UIImageView *imgV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, whiteView.width, whiteView.height*2/21)];
  45. imgV.image = [UIImage imageNamed:@"guard_header"];
  46. imgV.contentMode = UIViewContentModeScaleAspectFill;
  47. imgV.clipsToBounds = YES;
  48. [whiteView addSubview:imgV];
  49. numL = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, whiteView.width, whiteView.height*2/21)];
  50. numL.textAlignment = NSTextAlignmentCenter;
  51. numL.font = [UIFont systemFontOfSize:15];
  52. numL.textColor = [UIColor whiteColor];
  53. numL.userInteractionEnabled = YES;
  54. [whiteView addSubview:numL];
  55. [PublicObj lineViewWithFrame:CGRectMake(0, numL.bottom, whiteView.width, 1) andColor:RGB_COLOR(@"#F4F5F6", 1) andView:whiteView];
  56. listTable = [[UITableView alloc]initWithFrame:CGRectMake(0, numL.bottom+1, whiteView.width, whiteView.height*33/42-2) style:0];
  57. listTable.delegate = self;
  58. listTable.dataSource = self;
  59. listTable.separatorStyle = 0;
  60. [whiteView addSubview:listTable];
  61. listTable.mj_header = [MJRefreshHeader headerWithRefreshingBlock:^{
  62. page = 1;
  63. [self requestData];
  64. }];
  65. // listTable.mj_footer = [MJRefreshBackFooter footerWithRefreshingBlock:^{
  66. // page ++;
  67. // [self requestData];
  68. // }];
  69. if (![liveUID isEqual:[Config getOwnID]]) {
  70. [PublicObj lineViewWithFrame:CGRectMake(0, listTable.bottom, whiteView.width, 1) andColor:RGB_COLOR(@"#F4F5F6", 1) andView:whiteView];
  71. UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(15, listTable.bottom+1, whiteView.width-120, whiteView.height*5/42)];
  72. label.font = [UIFont systemFontOfSize:11];
  73. label.textColor = RGB_COLOR(@"#636465", 1);
  74. label.userInteractionEnabled = YES;
  75. label.numberOfLines = 0;
  76. [whiteView addSubview:label];
  77. UIButton *button = [UIButton buttonWithType:0];
  78. button.frame = CGRectMake(whiteView.width-105, label.top + label.height/2-15, 90, 30);
  79. button.layer.cornerRadius = 15;
  80. button.layer.masksToBounds = YES;
  81. button.titleLabel.adjustsFontSizeToFitWidth = YES;
  82. [PublicObj addGradientWithFromColor:RGB_COLOR(@"#872ae7", 1) andEndColor:RGB_COLOR(@"#cb16e1", 1) andView:button direction:0];
  83. button.titleLabel.font = [UIFont systemFontOfSize:13];
  84. [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
  85. [whiteView addSubview:button];
  86. if ([minstr([userMsg valueForKey:@"type"]) isEqual:@"1"]) {
  87. label.text = [NSString stringWithFormat:@"%@ %@",YZMsg(@"您是当前主播的月守护\n守护日期截止到"),minstr([userMsg valueForKey:@"endtime"])];
  88. [button setTitle:YZMsg(@"续费守护") forState:0];
  89. }else if([minstr([userMsg valueForKey:@"type"]) isEqual:@"2"]){
  90. label.text = [NSString stringWithFormat:@"%@ %@",YZMsg(@"您是当前主播的年守护\n守护日期截止到"),minstr([userMsg valueForKey:@"endtime"])];
  91. [button setTitle:YZMsg(@"续费守护") forState:0];
  92. }else{
  93. label.text = YZMsg(@"快去为喜欢的主播开通守护吧");
  94. [button setTitle:YZMsg(@"开通守护") forState:0];
  95. }
  96. }else{
  97. listTable.height = whiteView.height*38/42-1;
  98. }
  99. }
  100. - (void)buttonClick:(UIButton *)sender{
  101. [self.delegate buyOrRenewGuard];
  102. }
  103. - (void)requestData{
  104. NSDictionary *dic = @{@"liveuid":liveUID,@"p":@(page)};
  105. [YBNetworking postWithUrl:@"Guard.GetGuardList" Dic:dic Suc:^(int code, id info, NSString *msg) {
  106. [listTable.mj_header endRefreshing];
  107. [listTable.mj_footer endRefreshing];
  108. if (code == 0) {
  109. if (page == 1) {
  110. [infoArray removeAllObjects];
  111. }
  112. NSArray *infos = info;
  113. [infoArray addObjectsFromArray:infos];
  114. [listTable reloadData];
  115. if (infoArray.count == 0) {
  116. [self creatTableHeader:nil];
  117. }else{
  118. [self creatTableHeader:[infoArray firstObject]];
  119. }
  120. numL.text = [NSString stringWithFormat:@"%@(%ld)",YZMsg(@"守护"),infoArray.count];
  121. }else{
  122. if (infoArray.count == 0) {
  123. [self creatTableHeader:nil];
  124. }
  125. }
  126. } Fail:^(id fail) {
  127. [listTable.mj_header endRefreshing];
  128. [listTable.mj_footer endRefreshing];
  129. [self creatTableHeader:nil];
  130. }];
  131. }
  132. - (void)creatTableHeader:(NSDictionary *)dic{
  133. UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, whiteView.width, whiteView.height*40/82)];
  134. UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(view.width/4, view.height *3/40, view.width/2, view.height*22/40)];
  135. [view addSubview:imgView];
  136. if (dic) {
  137. imgView.image = [UIImage imageNamed:getImagename(@"守护之星")];
  138. UIImageView *iconImgView = [[UIImageView alloc]initWithFrame:CGRectMake(imgView.left+imgView.width*95/300, imgView.top + imgView.height*85/220, imgView.width*110/300, imgView.width*110/300)];
  139. iconImgView.layer.cornerRadius = imgView.width*110/600;
  140. iconImgView.layer.masksToBounds = YES;
  141. [iconImgView sd_setImageWithURL:[NSURL URLWithString:minstr([dic valueForKey:@"avatar_thumb"])]];
  142. [view addSubview:iconImgView];
  143. [view sendSubviewToBack:iconImgView];
  144. //UILabel *nameL = [[UILabel alloc]initWithFrame:CGRectMake(0, imgView.bottom, view.width, view.height*60/400)];
  145. UILabel *nameL = [[UILabel alloc]init];
  146. nameL.textAlignment = NSTextAlignmentCenter;
  147. nameL.font = [UIFont boldSystemFontOfSize:15];
  148. nameL.textColor = RGB_COLOR(@"#333333", 1);
  149. nameL.text = minstr([dic valueForKey:@"user_nickname"]);
  150. [view addSubview:nameL];
  151. [nameL mas_makeConstraints:^(MASConstraintMaker *make) {
  152. make.centerX.equalTo(imgView.mas_centerX).offset(-10);
  153. make.top.equalTo(imgView.mas_bottom).offset(10);
  154. }];
  155. //UIImageView *sexImgView = [[UIImageView alloc]initWithFrame:CGRectMake(view.width/2-view.width*50/600, nameL.bottom, view.width*36/600, view.width*30/600)];
  156. UIImageView *sexImgView = [[UIImageView alloc]init];
  157. if ([minstr([dic valueForKey:@"sex"]) isEqual:@"1"]) {
  158. sexImgView.image = [UIImage imageNamed:@"bullet-男"];
  159. }else{
  160. sexImgView.image = [UIImage imageNamed:@"bullet-女"];
  161. }
  162. [view addSubview:sexImgView];
  163. [sexImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  164. make.width.mas_equalTo(15);//18
  165. make.height.mas_equalTo(15);
  166. make.centerY.equalTo(nameL);
  167. make.left.equalTo(nameL.mas_right).offset(1);
  168. }];
  169. /*
  170. UIImageView *levelImgView = [[UIImageView alloc]initWithFrame:CGRectMake(sexImgView.right +view.width*20/600, nameL.bottom, view.width*60/600, view.width*30/600)];
  171. NSDictionary *levelDic = [common getUserLevelMessage:minstr([dic valueForKey:@"level"])];
  172. [levelImgView sd_setImageWithURL:[NSURL URLWithString:minstr([levelDic valueForKey:@"thumb"])]];
  173. [view addSubview:levelImgView];
  174. */
  175. //UILabel *votesL = [[UILabel alloc]initWithFrame:CGRectMake(0, sexImgView.bottom, view.width, view.height*60/400)];
  176. UILabel *votesL = [[UILabel alloc]init];
  177. votesL.textAlignment = NSTextAlignmentCenter;
  178. votesL.font = [UIFont systemFontOfSize:13];
  179. votesL.textColor = RGB_COLOR(@"#C8C9CA", 1);
  180. [votesL setAttributedText:[self coinLabel:minstr([dic valueForKey:@"contribute"])]];
  181. [view addSubview:votesL];
  182. [votesL mas_makeConstraints:^(MASConstraintMaker *make) {
  183. make.top.equalTo(sexImgView.mas_bottom).offset(15);
  184. make.centerX.equalTo(imgView);
  185. }];
  186. [PublicObj lineViewWithFrame:CGRectMake(0, view.bottom-1, whiteView.width, 1) andColor:RGB_COLOR(@"#F4F5F6", 1) andView:view];
  187. }else{
  188. imgView.image = [UIImage imageNamed:getImagename(@"虚位以待")];
  189. UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, imgView.bottom+15, view.width, 20)];
  190. label.textAlignment = NSTextAlignmentCenter;
  191. if ([liveUID isEqual:[Config getOwnID]]) {
  192. label.text = YZMsg(@"你还没有守护哦");
  193. }else{
  194. label.text = YZMsg(@"成为TA的第一个守护");
  195. }
  196. label.font = [UIFont systemFontOfSize:13];
  197. label.textColor = RGB_COLOR(@"#959697", 1);
  198. [view addSubview:label];
  199. }
  200. //[view addSubview:imgView];
  201. listTable.tableHeaderView = view;
  202. }
  203. - (NSMutableAttributedString *)coinLabel:(NSString *)coin{
  204. NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc]init];
  205. NSAttributedString *str1 = [[NSAttributedString alloc]initWithString:YZMsg(@"本周贡献")];
  206. [attStr appendAttributedString:str1];
  207. NSMutableAttributedString *str2 = [[NSMutableAttributedString alloc]initWithString:coin];
  208. [str2 addAttribute:NSForegroundColorAttributeName value:Pink_Cor range:NSMakeRange(0, [coin length])];//RGB_COLOR(@"#FF6131", 1)-橘黄
  209. [attStr appendAttributedString:str2];
  210. NSAttributedString *str3 = [[NSAttributedString alloc]initWithString:[NSString stringWithFormat:@" %@",[common name_votes]]];
  211. [attStr appendAttributedString:str3];
  212. return attStr;
  213. }
  214. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  215. return infoArray.count-1;
  216. }
  217. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  218. guardListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"guardListCELL"];
  219. if (!cell) {
  220. cell = [[[NSBundle mainBundle] loadNibNamed:@"guardListCell" owner:nil options:nil] lastObject];
  221. }
  222. guardListModel *model = [[guardListModel alloc]initWithDic:infoArray[indexPath.row +1]];
  223. cell.model = model;
  224. return cell;
  225. }
  226. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  227. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  228. }
  229. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  230. return 60;
  231. }
  232. - (void)show{
  233. [UIView animateWithDuration:0.3 animations:^{
  234. whiteView.y = (_window_height-whiteView.height)/2;
  235. }];
  236. }
  237. - (void)hideSelf{
  238. [UIView animateWithDuration:0.3 animations:^{
  239. whiteView.y = _window_height;
  240. } completion:^(BOOL finished) {
  241. [self.delegate removeShouhuView];
  242. }];
  243. }
  244. @end