playerShowSecretkeyView.m 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. //
  2. // playerShowSecretkeyView.m
  3. // 隐私保护
  4. //
  5. // Created by xd h on 2023/11/6.
  6. //
  7. #import "playerShowSecretkeyView.h"
  8. #import "RSATool.h"
  9. #import "connectDeviceManager.h"
  10. @interface playerShowSecretkeyView()
  11. @property(nonatomic,strong)UIView *whiteBgView;
  12. @property(nonatomic,strong)UIButton *closeBut;
  13. @property(nonatomic,strong)NSTimer *curTimer;
  14. @property(nonatomic,assign) NSInteger coundDownNumber;
  15. @end
  16. @implementation playerShowSecretkeyView
  17. - (id)initWithFrame:(CGRect)frame{
  18. self = [super initWithFrame:frame];
  19. self.backgroundColor = [UIColor hwColor:@"000000" alpha:0.6];
  20. [self drawAnyView];
  21. return self;
  22. }
  23. - (void)drawAnyView{
  24. _whiteBgView = [[UIView alloc] init];
  25. _whiteBgView.layer.cornerRadius = 8;
  26. _whiteBgView.backgroundColor = [UIColor whiteColor];
  27. [self addSubview:_whiteBgView];
  28. [_whiteBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  29. make.height.mas_equalTo(260);
  30. make.width.mas_equalTo(300.f);
  31. make.center.mas_equalTo(0.f);
  32. }];
  33. UILabel *titleLab = [[UILabel alloc] init];
  34. titleLab.text = NSLocalizedString(@"player_Secret_key_title",nil);
  35. titleLab.textAlignment = NSTextAlignmentCenter;
  36. titleLab.font = [UIFont boldSystemFontOfSize:18];
  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 = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.sn;
  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)HW0CDEFDColor.CGColor, (__bridge id)HW058DFBColor.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 whiteColor] 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. }
  153. }
  154. #pragma mark 复制
  155. - (void)copyKeyFun
  156. {
  157. NSString *snStr = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.sn;
  158. NSString *secretkey = [RSATool sha256_8:snStr];
  159. UIPasteboard * Pasteboard = [UIPasteboard generalPasteboard];
  160. Pasteboard.string = secretkey;
  161. NSString *tipStr = NSLocalizedString(@"player_Secret_key_copy_suc",nil);
  162. [[iToast makeText:tipStr] show];
  163. }
  164. #pragma mark 关闭按钮
  165. - (void)closeViewFun
  166. {
  167. [self removeFromSuperview];
  168. if(_didCloseSecretKeyViewTip){
  169. _didCloseSecretKeyViewTip();
  170. }
  171. }
  172. @end