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