playerShowSecretkeyView.m 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. //
  2. // playerShowSecretkeyView.m
  3. //
  4. //
  5. // Created David on 2023/11/6.
  6. //
  7. #import "playerShowSecretkeyView.h"
  8. #import "RSATool.h"
  9. @interface playerShowSecretkeyView()
  10. @property(nonatomic,strong)UIView *whiteBgView;
  11. @property(nonatomic,strong)UIButton *closeBut;
  12. @property(nonatomic,strong)NSTimer *curTimer;
  13. @property(nonatomic,assign) NSInteger coundDownNumber;
  14. @end
  15. @implementation playerShowSecretkeyView
  16. - (id)initWithFrame:(CGRect)frame{
  17. self = [super initWithFrame:frame];
  18. self.backgroundColor = [UIColor hwColor:@"000000" alpha:0.6];
  19. [self drawAnyView];
  20. return self;
  21. }
  22. - (void)drawAnyView{
  23. _whiteBgView = [[UIView alloc] init];
  24. _whiteBgView.layer.cornerRadius = 8;
  25. _whiteBgView.backgroundColor = [UIColor whiteColor];
  26. [self addSubview:_whiteBgView];
  27. [_whiteBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  28. make.height.mas_equalTo(260);
  29. make.width.mas_equalTo(300.f);
  30. make.center.mas_equalTo(0.f);
  31. }];
  32. UILabel *titleLab = [[UILabel alloc] init];
  33. titleLab.text = NSLocalizedString(@"player_Secret_key_title",nil);
  34. titleLab.textAlignment = NSTextAlignmentCenter;
  35. titleLab.font = [UIFont boldSystemFontOfSize:18];
  36. titleLab.textColor = [UIColor blackColor];
  37. [_whiteBgView addSubview:titleLab];
  38. [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
  39. make.height.mas_equalTo(20);
  40. make.left.mas_equalTo(0.f);
  41. make.right.mas_equalTo(0.f);
  42. make.top.mas_equalTo(30.f);
  43. }];
  44. UILabel *tipLab = [[UILabel alloc] init];
  45. tipLab.text = NSLocalizedString(@"player_Secret_key_tip",nil);
  46. tipLab.textAlignment = NSTextAlignmentCenter;
  47. tipLab.font = [UIFont systemFontOfSize:14];
  48. tipLab.numberOfLines = 0;
  49. tipLab.textColor = [UIColor hwColor:@"#FF5353" alpha:1.0];
  50. [_whiteBgView addSubview:tipLab];
  51. [tipLab mas_makeConstraints:^(MASConstraintMaker *make) {
  52. make.height.mas_equalTo(35);
  53. make.left.mas_equalTo(10.f);
  54. make.right.mas_equalTo(-0.f);
  55. make.top.mas_equalTo(titleLab.mas_bottom).offset(5.f);
  56. }];
  57. UIView*grayBgView = [[UIView alloc] init];
  58. grayBgView.layer.cornerRadius = 2;
  59. grayBgView.backgroundColor = [UIColor hwColor:@"#F9F9F9" alpha:1.0];
  60. [_whiteBgView addSubview:grayBgView];
  61. [grayBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  62. make.height.mas_equalTo(56);
  63. make.left.mas_equalTo(30.f);
  64. make.right.mas_equalTo(-30.f);
  65. make.top.mas_equalTo(tipLab.mas_bottom).offset(20.f);
  66. }];
  67. [grayBgView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(copyKeyFun)]];
  68. NSString *snStr = ksharedAppDelegate.DeviceThirdIdMod.data.changeSn;
  69. NSString *secretkey = [RSATool sha256_8:snStr];
  70. UILabel *secretKeyLab = [[UILabel alloc] init];
  71. secretKeyLab.text = secretkey;
  72. //secretKeyLab.textAlignment = NSTextAlignmentCenter;
  73. secretKeyLab.font = [UIFont boldSystemFontOfSize:16];
  74. secretKeyLab.textColor = [UIColor hwColor:@"#3B7FFF" alpha:1.0];
  75. [grayBgView addSubview:secretKeyLab];
  76. [secretKeyLab mas_makeConstraints:^(MASConstraintMaker *make) {
  77. make.bottom.mas_equalTo(0.f);
  78. make.left.mas_equalTo(10.f);
  79. make.right.mas_equalTo(0.f);
  80. make.top.mas_equalTo(0.f);
  81. }];
  82. NSString*curStr = NSLocalizedString(@"player_Secret_key_copy",nil);
  83. UILabel *rightLab = [[UILabel alloc] init];
  84. rightLab.text = [[NSString alloc] initWithFormat:@"| %@",curStr];
  85. //@"| 复制密钥";
  86. rightLab.textAlignment = NSTextAlignmentRight;
  87. rightLab.font = [UIFont systemFontOfSize:16];
  88. rightLab.textColor = [UIColor hwColor:@"#666666" alpha:1.0];
  89. [grayBgView addSubview:rightLab];
  90. [rightLab mas_makeConstraints:^(MASConstraintMaker *make) {
  91. make.bottom.mas_equalTo(0.f);
  92. make.left.mas_equalTo(10.f);
  93. make.right.mas_equalTo(-10.f);
  94. make.top.mas_equalTo(0.f);
  95. }];
  96. _closeBut = [[UIButton alloc] init];
  97. NSString *butTitle = [[NSString alloc] initWithFormat:@"%@ %@",NSLocalizedString(@"player_Secret_key_close",nil), @"(10s)"];
  98. /*确认按钮*/
  99. _closeBut = [[UIButton alloc] init];
  100. CGFloat okBtn_W= 240;
  101. // gradient
  102. CAGradientLayer *gl = [CAGradientLayer layer];
  103. gl.frame = CGRectMake(0,0,okBtn_W,40);
  104. gl.startPoint = CGPointMake(0, 0.5);
  105. gl.endPoint = CGPointMake(1, 0.5);
  106. gl.colors = @[(__bridge id)HWFFE10FColor.CGColor, (__bridge id)HWFFE411Color.CGColor];
  107. gl.locations = @[@(0), @(1.0f)];
  108. _closeBut.layer.cornerRadius = 8;
  109. _closeBut.clipsToBounds = YES;
  110. [_closeBut.layer addSublayer:gl];
  111. [_closeBut setTitle:butTitle forState:(UIControlStateNormal)];
  112. [_closeBut setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
  113. [_closeBut addTarget:self action:@selector(closeViewFun) forControlEvents:UIControlEventTouchUpInside];
  114. // NSString* curLanguage = [DDYLanguageTool ddy_AppLanguage];
  115. // if(!curLanguage || curLanguage.length == 0){
  116. // curLanguage = [DDYLanguageTool ddy_SystemLanguage];
  117. // }
  118. //
  119. // // "zh-Hant-HK", "zh-Hans-US",
  120. // if([curLanguage rangeOfString:@"zh-Han"].location != NSNotFound){//中文和繁体
  121. // [okBtn.titleLabel setFont:[UIFont systemFontOfSize:16.f]];
  122. // }
  123. // else{//en-US
  124. // [okBtn.titleLabel setFont:[UIFont systemFontOfSize:14.f]];
  125. // }
  126. [_whiteBgView addSubview:_closeBut];
  127. [_closeBut mas_makeConstraints:^(MASConstraintMaker *make) {
  128. make.bottom.mas_equalTo(-30.f);
  129. make.centerX.mas_equalTo(0.f);
  130. make.width.mas_equalTo(okBtn_W);
  131. make.height.mas_equalTo(40);
  132. }];
  133. [_closeBut setEnabled:NO];
  134. [_closeBut setAlpha:0.5];
  135. [_curTimer invalidate];
  136. _curTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerHandleFun) userInfo:nil repeats:YES];
  137. _coundDownNumber = 10;
  138. }
  139. #pragma mark timer fun
  140. - (void)timerHandleFun
  141. {
  142. _coundDownNumber -- ;
  143. if(_coundDownNumber > 0){
  144. NSString *butTitle = [[NSString alloc] initWithFormat:@"%@ (%lds)",NSLocalizedString(@"player_Secret_key_close",nil), _coundDownNumber];
  145. [_closeBut setTitle:butTitle forState:(UIControlStateNormal)];
  146. }
  147. else{
  148. NSString *butTitle = NSLocalizedString(@"player_Secret_key_close",nil);
  149. [_closeBut setTitle:butTitle forState:(UIControlStateNormal)];
  150. [_closeBut setEnabled:YES];
  151. [_closeBut setAlpha:1];
  152. [_curTimer invalidate];
  153. }
  154. }
  155. #pragma mark 复制
  156. - (void)copyKeyFun
  157. {
  158. NSString *snStr = ksharedAppDelegate.DeviceThirdIdMod.data.changeSn;
  159. NSString *secretkey = [RSATool sha256_8:snStr];
  160. UIPasteboard * Pasteboard = [UIPasteboard generalPasteboard];
  161. Pasteboard.string = secretkey;
  162. NSString *tipStr = NSLocalizedString(@"player_Secret_key_copy_suc",nil);
  163. [[iToast makeText:tipStr] show];
  164. if(_didCopySecretKeyViewTip){
  165. _didCopySecretKeyViewTip();
  166. }
  167. }
  168. #pragma mark 关闭按钮
  169. - (void)closeViewFun
  170. {
  171. [self removeFromSuperview];
  172. if(_didCloseSecretKeyViewTip){
  173. _didCloseSecretKeyViewTip();
  174. }
  175. }
  176. @end