ModifyPWDSecondViewController.m 14 KB

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