SetPWDSecondViewController.m 13 KB

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