ModifyPWDSecondViewController.m 14 KB

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