playerShowSecretkeyView.m 7.2 KB

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