YOUPAILZLiveCallWindow.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. //
  2. // YOUPAILZLiveCallWindow.m
  3. // TIANYAN
  4. //
  5. // Created by CY on 2021/5/29.
  6. // Copyright © 2021 leo. All rights reserved.
  7. //
  8. #import "YOUPAILZLiveCallWindow.h"
  9. @interface YOUPAILZLiveCallWindow ()
  10. @property (nonatomic,assign)LZLiveInviteState youpaipstate;
  11. @property (nonatomic,assign)LZLiveInviteType youpaiptype;
  12. @property (nonatomic,strong)YOUPAILZLiveStartPKModel *youpaipmodel;
  13. @property (nonatomic,strong)NSTimer *timer;
  14. @property (nonatomic,assign)NSInteger youpaiptimeCount;
  15. @property (nonatomic,strong)NSMutableArray <UIButton *>*youpaipbtns;
  16. @end
  17. @implementation YOUPAILZLiveCallWindow
  18. - (void)dealloc{
  19. [self youpaifstopTimer];
  20. [[NSNotificationCenter defaultCenter] removeObserver:self];
  21. }
  22. -(instancetype)initWithState:(LZLiveInviteState)state type:(LZLiveInviteType)type model:(nonnull YOUPAILZLiveStartPKModel *)model{
  23. if (self = [super init]) {
  24. _youpaipstate = state;
  25. _youpaiptype = type;
  26. _youpaipmodel = model;
  27. }
  28. return self;
  29. }
  30. - (void)viewDidLoad {
  31. [super viewDidLoad];
  32. self.baseView.hidden = YES;
  33. [self youpaifinitUI];
  34. if (self.youpaipstate == LZLiveInviteStateCall) {
  35. self.youpaiptimeCount = 15;
  36. NSTimer * timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(youpaifcountDown) userInfo:nil repeats:YES];
  37. self.timer = timer;
  38. [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
  39. }
  40. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifdismissVC) name:@"RemoveLiveCallWindow" object:nil];
  41. }
  42. - (void)youpaifdismissVC{
  43. [self youpaifstopTimer];
  44. [self dismissViewControllerAnimated:YES completion:nil];
  45. }
  46. - (void)youpaifcountDown{
  47. self.youpaiptimeCount --;
  48. if (self.youpaiptimeCount <= 0) {
  49. [self youpaifstopTimer];
  50. [self youpaifcancelLianMaiOrPK:@"已超时"];
  51. }
  52. if (self.youpaipbtns.count != 0) {
  53. UIButton *btn = self.youpaipbtns[0];
  54. [btn setTitle:[NSString stringWithFormat:@"取消(%@s)",@(self.youpaiptimeCount)] forState:UIControlStateNormal];
  55. }
  56. }
  57. - (void)youpaifstopTimer{
  58. [self.timer invalidate];
  59. self.timer = nil;
  60. }
  61. - (void)youpaifinitUI{
  62. UIView *bgV = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, KScreenWidth, ScaleSize(267.0f))];
  63. bgV.layer.borderColor = HexColorFromRGB(0x4F4B5B).CGColor;
  64. bgV.layer.borderWidth = 0.5f;
  65. bgV.backgroundColor = LCBkgColor;
  66. [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerTopRight View:bgV size:CGSizeMake(20.0f, 20.0f)];
  67. [self.view addSubview:bgV];
  68. [bgV mas_makeConstraints:^(MASConstraintMaker *make) {
  69. make.left.right.bottom.offset(0.0f);
  70. make.height.offset(ScaleSize(267.0f));
  71. }];
  72. UILabel *titleL = [[UILabel alloc] init];
  73. titleL.font = LCFont17;
  74. titleL.textColor = [UIColor whiteColor];
  75. titleL.textAlignment = NSTextAlignmentCenter;
  76. titleL.text = self.titleStr;
  77. [bgV addSubview:titleL];
  78. [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
  79. make.left.top.right.offset(0.0f);
  80. make.height.offset(49.0f);
  81. }];
  82. UIImageView *callImgV = [[UIImageView alloc] init];
  83. callImgV.image = self.callImage;
  84. [bgV addSubview:callImgV];
  85. [callImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  86. make.top.equalTo(titleL.mas_bottom).offset(ScaleSize(45.0f));
  87. make.centerX.equalTo(bgV.mas_centerX);
  88. make.size.mas_offset(CGSizeMake(41.0f, 47.0f));
  89. }];
  90. UIImageView *formAvatarImgV = [[UIImageView alloc] init];
  91. formAvatarImgV.contentMode = UIViewContentModeScaleAspectFill;
  92. formAvatarImgV.layer.cornerRadius = 23.0f;
  93. formAvatarImgV.clipsToBounds = YES;
  94. formAvatarImgV.layer.borderColor = HexColorFromRGB(0xB6DEFA).CGColor;
  95. formAvatarImgV.layer.borderWidth = 1.0f;
  96. [formAvatarImgV sd_setImageWithURL:[LCTools getImageUrlWithAddress:self.youpaipmodel.youpaipfrom_user.youpaipavatar]];
  97. [bgV addSubview:formAvatarImgV];
  98. [formAvatarImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  99. make.right.equalTo(callImgV.mas_left).offset(-ScaleSize(60.0f));
  100. make.top.equalTo(titleL.mas_bottom).offset(ScaleSize(36.0f));
  101. make.size.mas_offset(CGSizeMake(46.0f, 46.0f));
  102. }];
  103. UILabel *formNicknameL = [[UILabel alloc] init];
  104. formNicknameL.font = LCFont14;
  105. formNicknameL.textColor = [UIColor whiteColor];
  106. formNicknameL.text = self.youpaipmodel.youpaipfrom_user.youpaipnickname;
  107. [bgV addSubview:formNicknameL];
  108. [formNicknameL mas_makeConstraints:^(MASConstraintMaker *make) {
  109. make.top.equalTo(formAvatarImgV.mas_bottom).offset(7.0f);
  110. make.centerX.equalTo(formAvatarImgV.mas_centerX);
  111. }];
  112. UIImageView *toAvatarImgV = [[UIImageView alloc] init];
  113. toAvatarImgV.contentMode = UIViewContentModeScaleAspectFill;
  114. toAvatarImgV.layer.cornerRadius = 23.0f;
  115. toAvatarImgV.clipsToBounds = YES;
  116. toAvatarImgV.layer.borderColor = HexColorFromRGB(0xB6DEFA).CGColor;
  117. toAvatarImgV.layer.borderWidth = 1.0f;
  118. [toAvatarImgV sd_setImageWithURL:[LCTools getImageUrlWithAddress:self.youpaipmodel.youpaipto_user.youpaipavatar]];
  119. [bgV addSubview:toAvatarImgV];
  120. [toAvatarImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  121. make.left.equalTo(callImgV.mas_right).offset(ScaleSize(60.0f));
  122. make.top.equalTo(titleL.mas_bottom).offset(ScaleSize(36.0f));
  123. make.size.mas_offset(CGSizeMake(46.0f, 46.0f));
  124. }];
  125. UILabel *toNicknameL = [[UILabel alloc] init];
  126. toNicknameL.font = LCFont14;
  127. toNicknameL.textColor = [UIColor whiteColor];
  128. toNicknameL.text = self.youpaipmodel.youpaipto_user.youpaipnickname;
  129. [bgV addSubview:toNicknameL];
  130. [toNicknameL mas_makeConstraints:^(MASConstraintMaker *make) {
  131. make.top.equalTo(toAvatarImgV.mas_bottom).offset(7.0f);
  132. make.centerX.equalTo(toAvatarImgV.mas_centerX);
  133. }];
  134. NSArray *btnTitles = @[];
  135. if (self.youpaipstate == LZLiveInviteStateCall) {
  136. btnTitles = @[@"取消(15s)"];
  137. }else{
  138. btnTitles = @[@"拒绝",@"接受"];
  139. }
  140. for (NSInteger i = 0; i < btnTitles.count; i ++) {
  141. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  142. [btn setBackgroundImage:self.btnBgImages[i] forState:UIControlStateNormal];
  143. [btn setBackgroundImage:self.btnBgImages[i] forState:UIControlStateHighlighted];
  144. btn.layer.cornerRadius = 17.0f;
  145. btn.clipsToBounds = YES;
  146. [btn setTitle:btnTitles[i] forState:UIControlStateNormal];
  147. [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  148. btn.titleLabel.font = self.btnFont;
  149. btn.tag = i;
  150. [btn addTarget:self action:@selector(youpaifbtnClick:) forControlEvents:UIControlEventTouchUpInside];
  151. [bgV addSubview:btn];
  152. [self.youpaipbtns addObject:btn];
  153. if (btnTitles.count == 1) {
  154. [btn mas_makeConstraints:^(MASConstraintMaker *make) {
  155. make.bottom.offset(ScaleSize(-42.0f));
  156. make.centerX.equalTo(bgV.mas_centerX);
  157. make.size.mas_offset(CGSizeMake(93.0f, 34.0f));
  158. }];
  159. }else if (btnTitles.count == 2){
  160. [btn mas_makeConstraints:^(MASConstraintMaker *make) {
  161. make.bottom.offset(ScaleSize(-42.0f));
  162. if (i == 0) {
  163. make.right.equalTo(bgV.mas_centerX).offset(-ScaleSize(35.5f));
  164. }else{
  165. make.left.equalTo(bgV.mas_centerX).offset(ScaleSize(35.5f));
  166. }
  167. make.size.mas_offset(CGSizeMake(93.0f, 34.0f));
  168. }];
  169. }
  170. }
  171. }
  172. - (void)youpaifbtnClick:(UIButton *)sender{
  173. if (sender.tag == 0) {
  174. if (self.youpaipstate == LZLiveInviteStateCall) {
  175. [self youpaifcancelLianMaiOrPK:@"已取消"];
  176. }else{
  177. [self youpaifoperateToWithEvent:@"refuse" text:@"已拒绝"];
  178. }
  179. }else if (sender.tag == 1){
  180. [self youpaifoperateToWithEvent:@"connect" text:nil];
  181. }
  182. }
  183. - (void)youpaifoperateToWithEvent:(NSString *)event text:(NSString *)text{
  184. NSDictionary *params = @{
  185. @"pk_id":self.youpaipmodel.youpaippk_id,
  186. @"event":event
  187. };
  188. WeakSelf;
  189. [LCHttpHelper requestWithURLString:OperateTo parameters:params needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  190. NSDictionary* dict = (NSDictionary*)responseObject;
  191. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  192. if (code == 0) {
  193. if (text.length != 0) {
  194. [ZCHUDHelper showTitle:text];
  195. }
  196. if ([event isEqual:@"connect"] && self.youpaipstartConnectBlock != nil) {
  197. weakSelf.youpaipstartConnectBlock(self.youpaipmodel);
  198. }
  199. [weakSelf youpaifdismissVC];
  200. }else{
  201. [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
  202. }
  203. } failure:^(NSError *error) {
  204. [ZCHUDHelper showTitle:error.localizedDescription];
  205. }];
  206. }
  207. - (void)youpaifcancelLianMaiOrPK:(NSString *)text{
  208. NSDictionary *params = @{
  209. @"pk_id":self.youpaipmodel.youpaippk_id,
  210. @"event":@"cancel"
  211. };
  212. WeakSelf;
  213. [LCHttpHelper requestWithURLString:OperateFrom parameters:params needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  214. NSDictionary* dict = (NSDictionary*)responseObject;
  215. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  216. if (code == 0) {
  217. [ZCHUDHelper showTitle:text];
  218. [weakSelf youpaifdismissVC];
  219. }else{
  220. [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
  221. }
  222. } failure:^(NSError *error) {
  223. [ZCHUDHelper showTitle:error.localizedDescription];
  224. }];
  225. }
  226. - (NSMutableArray<UIButton *> *)youpaipbtns{
  227. if (!_youpaipbtns) {
  228. _youpaipbtns = [NSMutableArray array];
  229. }
  230. return _youpaipbtns;
  231. }
  232. /// 中间电话的图片
  233. - (UIImage *)callImage{
  234. return [UIImage imageNamed:@"vqu_images_L_live_call_phone"];
  235. }
  236. - (UIFont *)btnFont{
  237. if (self.youpaipstate == LZLiveInviteStateCall) {
  238. return LCFont12;
  239. }else{
  240. return LCFont14;
  241. }
  242. }
  243. - (NSArray <UIImage *>*)btnBgImages{
  244. if (self.youpaipstate == LZLiveInviteStateCall) {
  245. return @[[LCTools ColorImage:CGSizeMake(93.0f, 34.0f) FromColors:@[HexColorFromRGB(0x75DFFF),HexColorFromRGB(0x0038FF)] ByGradientType:GradientLeftToRight]];
  246. }else{
  247. return @[[LCTools ColorImage:CGSizeMake(93.0f, 34.0f) FromColors:@[HexColorFromRGB(0x75DFFF),HexColorFromRGB(0x0038FF)] ByGradientType:GradientLeftToRight],
  248. [LCTools ColorImage:CGSizeMake(93.0f, 34.0f) FromColors:@[HexColorFromRGB(0xFF3BDC),HexColorFromRGB(0xFC2F55)] ByGradientType:GradientLeftToRight],
  249. ];
  250. }
  251. }
  252. - (NSString *)titleStr{
  253. if (self.youpaiptype == LZLiveInviteTypePK) {
  254. return @"约战邀请";
  255. }else{
  256. return @"连麦邀请";
  257. }
  258. }
  259. @end