SetPWDSecondViewController.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. //
  2. // SetPWDSecondViewController.m
  3. // 隐私保护
  4. //
  5. // Created by APPLE on 2023/9/19.
  6. //
  7. #import "SetPWDSecondViewController.h"
  8. #import <Masonry.h>
  9. #import "connectDeviceManager.h"
  10. @interface SetPWDSecondViewController (){
  11. NSString *pwd;
  12. UILabel *pointView0;
  13. UILabel *pointView1;
  14. UILabel *pointView2;
  15. UILabel *pointView3;
  16. UILabel *topLabel;
  17. }
  18. @end
  19. @implementation SetPWDSecondViewController
  20. @synthesize oldPWD;
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. // Do any additional setup after loading the view.
  24. pwd = @"";
  25. [self drawAnyView];
  26. }
  27. - (void)drawAnyView{
  28. [self.navigationBar setHidden:YES];
  29. [self.toolBar setHidden:YES];
  30. [self.view setBackgroundColor:HWF5F7FAColor];
  31. /*上一步按钮*/
  32. UIButton *upStepBtn = [[UIButton alloc] init];
  33. [upStepBtn setTitle:NSLocalizedString(@"guide_set_pwd_up_step",nil) forState:(UIControlStateNormal)];
  34. [upStepBtn setTitleColor:HW05BAFBColor forState:(UIControlStateNormal)];
  35. [upStepBtn.titleLabel setFont:[UIFont systemFontOfSize:16]];
  36. [upStepBtn addTarget:self.navigationController
  37. action:@selector(popViewControllerAnimated:)
  38. forControlEvents:(UIControlEventTouchUpInside)];
  39. [self.view addSubview:upStepBtn];
  40. [upStepBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  41. make.left.mas_equalTo(10.f);
  42. make.width.mas_equalTo(58.f);
  43. make.top.mas_equalTo(5.f + H_STATE_BAR);
  44. make.height.mas_equalTo(32.f);
  45. }];
  46. /*设置密码标题*/
  47. topLabel = [[UILabel alloc] init];
  48. [topLabel setFont:[UIFont boldSystemFontOfSize:16.f]];
  49. [topLabel setTextColor:HW333333Color];
  50. [topLabel setTextAlignment:(NSTextAlignmentCenter)];
  51. [topLabel setText:NSLocalizedString(@"guide_set_pwd_makesure_title",nil)];
  52. [self.view addSubview:topLabel];
  53. [topLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.left.mas_equalTo(20);
  55. make.right.mas_equalTo(-20);
  56. make.top.mas_equalTo(99.f + H_STATE_BAR);
  57. }];
  58. CGFloat w_pwd = 24.f;
  59. CGFloat h_pwd = 24.f;
  60. CGFloat pointFont = 20.f;
  61. /*密码视图*/
  62. pointView0 = [[UILabel alloc] init];
  63. [pointView0 setTextColor:HW0A132BColor];
  64. [pointView0 setBackgroundColor:HWE3E8F1Color];
  65. [pointView0 setClipsToBounds:YES];
  66. [pointView0 setTextAlignment:(NSTextAlignmentCenter)];
  67. [pointView0 setFont:[UIFont systemFontOfSize:pointFont]];
  68. [pointView0.layer setCornerRadius:w_pwd/2.f];
  69. [self.view addSubview:pointView0];
  70. [pointView0 mas_makeConstraints:^(MASConstraintMaker *make) {
  71. make.left.equalTo(self.view.mas_centerX).offset((0-2)*(w_pwd+w_pwd) + w_pwd/2.f);
  72. make.height.mas_equalTo(h_pwd);
  73. make.width.mas_equalTo(w_pwd);
  74. make.top.mas_equalTo(151.f + H_STATE_BAR);
  75. }];
  76. pointView1 = [[UILabel alloc] init];
  77. [pointView1 setTextColor:HW0A132BColor];
  78. [pointView1 setBackgroundColor:HWE3E8F1Color];
  79. [pointView1 setClipsToBounds:YES];
  80. [pointView1 setTextAlignment:(NSTextAlignmentCenter)];
  81. [pointView1 setFont:[UIFont systemFontOfSize:pointFont]];
  82. [pointView1.layer setCornerRadius:w_pwd/2.f];
  83. [self.view addSubview:pointView1];
  84. [pointView1 mas_makeConstraints:^(MASConstraintMaker *make) {
  85. make.left.equalTo(self.view.mas_centerX).offset((1-2)*(w_pwd+w_pwd) + w_pwd/2.f);
  86. make.height.mas_equalTo(h_pwd);
  87. make.width.mas_equalTo(w_pwd);
  88. make.top.mas_equalTo(151.f + H_STATE_BAR);
  89. }];
  90. pointView2 = [[UILabel alloc] init];
  91. [pointView2 setTextColor:HW0A132BColor];
  92. [pointView2 setBackgroundColor:HWE3E8F1Color];
  93. [pointView2 setClipsToBounds:YES];
  94. [pointView2 setTextAlignment:(NSTextAlignmentCenter)];
  95. [pointView2 setFont:[UIFont systemFontOfSize:pointFont]];
  96. [pointView2.layer setCornerRadius:w_pwd/2.f];
  97. [self.view addSubview:pointView2];
  98. [pointView2 mas_makeConstraints:^(MASConstraintMaker *make) {
  99. make.left.equalTo(self.view.mas_centerX).offset((2-2)*(w_pwd+w_pwd) + w_pwd/2.f);
  100. make.height.mas_equalTo(h_pwd);
  101. make.width.mas_equalTo(w_pwd);
  102. make.top.mas_equalTo(151.f + H_STATE_BAR);
  103. }];
  104. pointView3 = [[UILabel alloc] init];
  105. [pointView3 setTextColor:HW0A132BColor];
  106. [pointView3 setBackgroundColor:HWE3E8F1Color];
  107. [pointView3 setClipsToBounds:YES];
  108. [pointView3 setTextAlignment:(NSTextAlignmentCenter)];
  109. [pointView3 setFont:[UIFont systemFontOfSize:pointFont]];
  110. [pointView3.layer setCornerRadius:w_pwd/2.f];
  111. [self.view addSubview:pointView3];
  112. [pointView3 mas_makeConstraints:^(MASConstraintMaker *make) {
  113. make.left.equalTo(self.view.mas_centerX).offset((3-2)*(w_pwd+w_pwd) + w_pwd/2.f);
  114. make.height.mas_equalTo(h_pwd);
  115. make.width.mas_equalTo(w_pwd);
  116. make.top.mas_equalTo(151.f + H_STATE_BAR);
  117. }];
  118. /*下方绘制键盘按钮*/
  119. UIView *bgViewForNumberBoard = [[UIView alloc] init];
  120. [bgViewForNumberBoard setBackgroundColor:[UIColor clearColor]];
  121. CGFloat w_bgViewForNumberBoard = SCREEN_W - 2*22.f*AUTOSCALE;
  122. CGFloat h_bgViewForNumberBoard = 330.f;
  123. [self.view addSubview:bgViewForNumberBoard];
  124. [bgViewForNumberBoard mas_makeConstraints:^(MASConstraintMaker *make) {
  125. make.left.mas_equalTo(22.f*AUTOSCALE);
  126. make.height.mas_equalTo(h_bgViewForNumberBoard);
  127. make.width.mas_equalTo(w_bgViewForNumberBoard);
  128. make.bottom.mas_equalTo(-70.f);
  129. }];
  130. CGFloat w_key_btn = w_bgViewForNumberBoard/3.f;
  131. CGFloat h_key_btn = h_bgViewForNumberBoard/4.f;
  132. /*绘制键盘 1~9*/
  133. for (NSInteger nFori = 0; nFori < 9; nFori++) {
  134. CGFloat x_key_btn = (nFori%3)*w_key_btn;
  135. CGFloat y_key_btn = (nFori/3)*h_key_btn;
  136. UIButton *keyBoardBtn = [[UIButton alloc] init];
  137. [keyBoardBtn setBackgroundColor:[UIColor clearColor]];
  138. [keyBoardBtn setTitleColor:HW0A132BColor forState:(UIControlStateNormal)];
  139. [keyBoardBtn.titleLabel setFont:[UIFont boldSystemFontOfSize:40.f]];
  140. [keyBoardBtn setTitle:[NSString stringWithFormat:@"%ld",nFori+1] forState:(UIControlStateNormal)];
  141. [keyBoardBtn addTarget:self action:@selector(keyBoardBtnPressed:) forControlEvents:(UIControlEventTouchUpInside)];
  142. [bgViewForNumberBoard addSubview:keyBoardBtn];
  143. [keyBoardBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  144. make.left.mas_equalTo(x_key_btn);
  145. make.top.mas_equalTo(y_key_btn);
  146. make.width.mas_equalTo(w_key_btn);
  147. make.height.mas_equalTo(h_key_btn);
  148. }];
  149. }
  150. /*删除按钮*/
  151. UIButton *deleteBoardBtn = [[UIButton alloc] init];
  152. [deleteBoardBtn setBackgroundColor:[UIColor clearColor]];
  153. [deleteBoardBtn addTarget:self action:@selector(deleteBoardBtnPressed) forControlEvents:(UIControlEventTouchUpInside)];
  154. [deleteBoardBtn setImage:[UIImage imageNamed:@"key_board_delete"] forState:(UIControlStateNormal)];
  155. [bgViewForNumberBoard addSubview:deleteBoardBtn];
  156. [deleteBoardBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  157. make.left.mas_equalTo(0);
  158. make.bottom.mas_equalTo(0);
  159. make.width.mas_equalTo(w_key_btn);
  160. make.height.mas_equalTo(h_key_btn);
  161. }];
  162. /*0*/
  163. UIButton *keyBoardBtn0 = [[UIButton alloc] init];
  164. [keyBoardBtn0 setBackgroundColor:[UIColor clearColor]];
  165. [keyBoardBtn0 setTitleColor:HW0A132BColor forState:(UIControlStateNormal)];
  166. [keyBoardBtn0.titleLabel setFont:[UIFont boldSystemFontOfSize:40.f]];
  167. [keyBoardBtn0 setTitle:@"0" forState:(UIControlStateNormal)];
  168. [keyBoardBtn0 addTarget:self action:@selector(keyBoardBtnPressed:) forControlEvents:(UIControlEventTouchUpInside)];
  169. [bgViewForNumberBoard addSubview:keyBoardBtn0];
  170. [keyBoardBtn0 mas_makeConstraints:^(MASConstraintMaker *make) {
  171. make.left.mas_equalTo(w_key_btn);
  172. make.bottom.mas_equalTo(0);
  173. make.width.mas_equalTo(w_key_btn);
  174. make.height.mas_equalTo(h_key_btn);
  175. }];
  176. /*OK*/
  177. UIButton *keyBoardBtnOK = [[UIButton alloc] init];
  178. [keyBoardBtnOK setBackgroundColor:[UIColor clearColor]];
  179. [keyBoardBtnOK setTitleColor:HW13B2EBColor forState:(UIControlStateNormal)];
  180. [keyBoardBtnOK.titleLabel setFont:[UIFont boldSystemFontOfSize:30.f]];
  181. [keyBoardBtnOK setTitle:@"OK" forState:(UIControlStateNormal)];
  182. [keyBoardBtnOK addTarget:self action:@selector(keyBoardBtnOKPressed) forControlEvents:(UIControlEventTouchUpInside)];
  183. [bgViewForNumberBoard addSubview:keyBoardBtnOK];
  184. [keyBoardBtnOK mas_makeConstraints:^(MASConstraintMaker *make) {
  185. make.left.mas_equalTo(2*w_key_btn);
  186. make.bottom.mas_equalTo(0);
  187. make.width.mas_equalTo(w_key_btn);
  188. make.height.mas_equalTo(h_key_btn);
  189. }];
  190. }
  191. - (void)deleteBoardBtnPressed{
  192. if (pwd.length > 0){
  193. NSInteger numberLength = pwd.length;
  194. if (numberLength == 1){
  195. [pointView0 setText:@""];
  196. [pointView0 setBackgroundColor:HWE3E8F1Color];
  197. }else if (numberLength == 2){
  198. [pointView1 setText:@""];
  199. [pointView1 setBackgroundColor:HWE3E8F1Color];
  200. }else if (numberLength == 3){
  201. [pointView2 setText:@""];
  202. [pointView2 setBackgroundColor:HWE3E8F1Color];
  203. }else if (numberLength == 4){
  204. [pointView3 setText:@""];
  205. [pointView3 setBackgroundColor:HWE3E8F1Color];
  206. }
  207. pwd = [pwd substringToIndex:numberLength-1];
  208. }
  209. }
  210. - (void)keyBoardBtnOKPressed{
  211. if (pwd.length == 4){
  212. if ([pwd isEqualToString:oldPWD]) {
  213. /*设置密码成功*/
  214. NSDictionary *deviceDict = [HWDataManager getObjectWithKey:Const_Have_Add_Device];
  215. NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithDictionary:deviceDict];
  216. [dict setObject:pwd forKey:Const_Have_Add_Device_PWD];
  217. [HWDataManager setObjectWithKey:Const_Have_Add_Device value:dict];
  218. if (deviceDict && [[deviceDict allKeys] containsObject:Const_Have_Add_Device_SN]){
  219. //有设备了先去做链接准备 // 80bec9c5
  220. NSString *SNStr = deviceDict[@"Const_Have_Add_Device_SN"];
  221. if(SNStr){
  222. KWeakSelf
  223. [[connectDeviceManager shareInstance] updateCardInfoBySN:SNStr withPwdStr:pwd didNetEnd:^(bool didSuc) {
  224. if(didSuc){
  225. [weakSelf getPwdFunBy:SNStr];
  226. }
  227. else{
  228. [[iToast makeText:NSLocalizedString(@"log_login_system_busy",nil)] show];
  229. }
  230. }];
  231. }
  232. }
  233. }else{
  234. /*提示密码不一致*/
  235. [topLabel setText:NSLocalizedString(@"guide_set_pwd_no_same",nil)];
  236. }
  237. }
  238. }
  239. - (void)keyBoardBtnPressed:(id)sender{
  240. UIButton *btn = (UIButton *)sender;
  241. NSString *selectNumberStr = btn.titleLabel.text;
  242. if (pwd.length < 4){
  243. NSInteger numberLength = pwd.length;
  244. if (numberLength == 0){
  245. [pointView0 setText:selectNumberStr];
  246. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  247. [self->pointView0 setBackgroundColor:HW0A132BColor];
  248. });
  249. }else if (numberLength == 1){
  250. [pointView1 setText:selectNumberStr];
  251. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  252. [self->pointView1 setBackgroundColor:HW0A132BColor];
  253. });
  254. }else if (numberLength == 2){
  255. [pointView2 setText:selectNumberStr];
  256. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  257. [self->pointView2 setBackgroundColor:HW0A132BColor];
  258. });
  259. }else if (numberLength == 3){
  260. [pointView3 setText:selectNumberStr];
  261. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  262. [self->pointView3 setBackgroundColor:HW0A132BColor];
  263. });
  264. }
  265. pwd = [pwd stringByAppendingString:selectNumberStr];
  266. }
  267. }
  268. #pragma mark 重新获取密码
  269. -(void)getPwdFunBy:(NSString*)SNStr
  270. {
  271. [[connectDeviceManager shareInstance] getThridMsgBySN:SNStr needReconnect:NO didNetEnd:^(bool didSuc) {
  272. if(didSuc){
  273. [[NSNotificationCenter defaultCenter] postNotificationName:GuideOkNotification object:nil];
  274. }
  275. else{
  276. [[iToast makeText:NSLocalizedString(@"log_login_system_busy",nil)] show];
  277. }
  278. }];
  279. }
  280. /*
  281. #pragma mark - Navigation
  282. // In a storyboard-based application, you will often want to do a little preparation before navigation
  283. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  284. // Get the new view controller using [segue destinationViewController].
  285. // Pass the selected object to the new view controller.
  286. }
  287. */
  288. @end