UserLoginAccountViewController.m 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. //
  2. // UserLoginAccountViewController.m
  3. // XenonSDK
  4. //
  5. // Created by SAGESSE on 2019/5/29.
  6. // Copyright © 2019 SAGESSE. All rights reserved.
  7. //
  8. #import "XenonSDK.h"
  9. #import "UserLoginAccountViewController.h"
  10. #import "UserRegisterAccountViewController.h"
  11. #import "NSBundle+KODLocalizable.h"
  12. #import "KODCommonConst.h"
  13. @interface UserLoginAccountViewController () <UITextFieldDelegate>
  14. @property(nonatomic,strong)UIView *listView;
  15. @end
  16. @implementation UserLoginAccountViewController
  17. -(void)viewDidLoad {
  18. [super viewDidLoad];
  19. self.view.backgroundColor = [UIColor whiteColor];
  20. self.accountTextField.textColor = [UIColor blackColor];
  21. self.passwordTextField.textColor = [UIColor blackColor];
  22. //默认账号填充
  23. XSUser *user = XSUser.history.firstObject;
  24. self.accountTextField.text = user.userName;
  25. }
  26. -(void)viewDidDisappear:(BOOL)animated {
  27. [super viewDidDisappear:animated];
  28. [self.listView removeFromSuperview];
  29. self.listView = nil;
  30. }
  31. - (IBAction)PullAccoutList:(UIButton *)sender {
  32. sender.selected = !sender.selected;
  33. if (sender.selected) {
  34. NSInteger count = XSUser.history.count;
  35. if (count >4) {
  36. count = 4;
  37. }
  38. [self setAccoutListWith:count];
  39. }else{
  40. [self.listView removeFromSuperview];
  41. }
  42. }
  43. -(void)setAccoutListWith:(NSInteger)count {
  44. if (count == 0) {
  45. return;
  46. }
  47. if (self.listView) {
  48. [self.listView removeFromSuperview];
  49. }
  50. self.listView = [[UIView alloc]init];
  51. self.listView.frame = CGRectMake(self.accountInputView.frame.origin.x, self.accountInputView.frame.origin.y +self.accountInputView.frame.size.height*+1+3, self.accountInputView.frame.size.width, self.accountInputView.frame.size.height*count-(count-1)*1);
  52. self.listView.backgroundColor = [UIColor whiteColor];
  53. self.listView.userInteractionEnabled = YES;
  54. [self.view addSubview:self.listView];
  55. for (int i=0; i<count; i++) {
  56. //XSUser *user = [XSUser.history objectAtIndex:i];
  57. XSUser *user = XSUser.history.firstObject;
  58. UIView *v1 = [[UIView alloc]init];
  59. v1.backgroundColor = [UIColor whiteColor];
  60. v1.frame = CGRectMake(0, self.accountInputView.frame.size.height*i-i*1, self.accountInputView.frame.size.width, self.accountInputView.frame.size.height);
  61. v1.userInteractionEnabled = YES;
  62. v1.backgroundColor = [UIColor whiteColor];
  63. v1.layer.borderWidth =1;
  64. v1.layer.borderColor = [[UIColor.lightGrayColor colorWithAlphaComponent:0.8] CGColor];
  65. UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(CGFloatBasedI375(5), CGFloatBasedI375(7), CGFloatBasedI375(26), CGFloatBasedI375(26))];
  66. UIImage* image = [UIImage imageNamed:@"login_pwd_btn_bg" inBundle:XenonSDK.sharedSDK.bundle compatibleWithTraitCollection:nil];
  67. imgView.image = image;
  68. v1.tag = 100+i;
  69. [v1 addSubview:imgView];
  70. UILabel *label = [[UILabel alloc]init];
  71. label.frame = CGRectMake(CGFloatBasedI375(34), 0, v1.frame.size.width-CGFloatBasedI375(34), 40);
  72. label.font = [UIFont systemFontOfSize:14];
  73. label.adjustsFontSizeToFitWidth = YES;
  74. label.textColor = [UIColor blackColor];
  75. label.textAlignment = NSTextAlignmentLeft;
  76. label.text = user.userName;
  77. label.tag = 200+i;
  78. label.userInteractionEnabled = YES;
  79. [v1 addSubview:label];
  80. UITapGestureRecognizer *taper = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hideClickedView:)];
  81. [v1 addGestureRecognizer:taper];
  82. [self.listView addSubview:v1];
  83. }
  84. }
  85. -(void)hideClickedView:(UITapGestureRecognizer *)taper {
  86. [self.listView removeFromSuperview];
  87. UIView *v1 = (UIView *)taper.view;
  88. NSInteger index = v1.tag;
  89. UILabel *label = [v1 viewWithTag:index+100];
  90. self.accountTextField.text = label.text;
  91. }
  92. - (void)loginForPassword:(id)sender {
  93. // Resign editing.
  94. [self.view endEditing:YES];
  95. // Must enter account.
  96. NSString* account = self.accountTextField.text;
  97. if (account.length == 0) {
  98. //请输入帐号
  99. NSString *str = [NSBundle KOD_localizedStringForKey:PleaseEnterAccount];
  100. [XSNetwork showHudFailure:str];
  101. return;
  102. }
  103. // Must enter password.
  104. NSString* password = self.passwordTextField.text;
  105. if (password.length == 0) {
  106. //请输入密码
  107. NSString *str = [NSBundle KOD_localizedStringForKey:PleaseEnterPwd];
  108. [XSNetwork showHudFailure:str];
  109. return;
  110. }
  111. [XSNetwork showHudLoading];
  112. [XSNetwork loginWithAccount:account password:password complete:^(id object, NSError *error) {
  113. if (error != nil) {
  114. [XSNetwork showHudFailure:error];
  115. return;
  116. }
  117. if (XenonSDK.sharedSDK.sdk_loginCallback) {
  118. XenonSDK.sharedSDK.sdk_loginCallback(object);
  119. }
  120. }];
  121. }
  122. - (void)displayModeForPassword:(UIButton*)sender {
  123. // Toggle password display mode.
  124. sender.selected = !sender.selected;
  125. self.passwordTextField.secureTextEntry = sender.selected;
  126. }
  127. //Register user account
  128. - (IBAction)sdk_showViewControllerForUserRegister2:(id)sender {
  129. [self.view endEditing:YES];
  130. [self.navigationController pushViewController:UserRegisterAccountViewController.new animated:YES];
  131. }
  132. // MARK: -
  133. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  134. if (textField.returnKeyType == UIReturnKeyDone) {
  135. [self loginForPassword:textField];
  136. return NO;
  137. }
  138. if (textField == self.accountTextField) {
  139. [self.passwordTextField becomeFirstResponder];
  140. }
  141. return YES;
  142. }
  143. @end