PageRenderTime 25ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/WHAMBUSH/wbLoginRegisterViewController.m

https://gitlab.com/urbanjunglestudio/whambush-ios
Objective C | 505 lines | 402 code | 79 blank | 24 comment | 55 complexity | 11c13e81eb158f20974a7befe3fe0e50 MD5 | raw file
  1. //
  2. // wbLoginRegisterViewController.m
  3. // WHAMBUSH
  4. //
  5. // Created by Jari Kalinainen on 09/10/14.
  6. // Copyright (c) 2014 Jari Kalinainen. All rights reserved.
  7. //
  8. #import "wbLoginRegisterViewController.h"
  9. @interface wbLoginRegisterViewController ()
  10. @end
  11. @implementation wbLoginRegisterViewController
  12. @synthesize selectedCountry;
  13. @synthesize showSettings;
  14. -(id) init
  15. {
  16. DPRINTCLASS;
  17. self = [super init];
  18. if (self) {
  19. //
  20. //selectedCountry = @"";
  21. pickCountry = [[wbCountryPickerView alloc] initWithFrame:[[wbAPI sharedAPI] portraitFrame]];
  22. [pickCountry setSelectedCountry:[[wbAPI sharedAPI] currentCountry]];
  23. [pickCountry setDelegate:self];
  24. showSettings = NO;
  25. }
  26. return self;
  27. }
  28. + (id)sharedLRVC
  29. {
  30. static dispatch_once_t pred = 0;
  31. __strong static id _sharedObject = nil;
  32. dispatch_once(&pred, ^{
  33. _sharedObject = [[self alloc] init];
  34. });
  35. return _sharedObject;
  36. }
  37. -(NSString*)description
  38. {
  39. return [super description];
  40. }
  41. -(void)showAskToLoginRegisterOnView:(id)view
  42. {
  43. [kROOTVC performSelector:@selector(hideSettings)];
  44. NSString *settingsTxt;
  45. if (showSettings) {
  46. settingsTxt = NSLocalizedString(@"USER_SETTINGS", @"");
  47. }
  48. IBActionSheet *actionSheet = [[IBActionSheet alloc] initWithTitle:NSLocalizedString(@"GENERAL_GUEST_USER_LOGIN_REGISTER",@"") delegate:self cancelButtonTitle:NSLocalizedString(@"GENERAL_CANCEL", @"") destructiveButtonTitle:nil otherButtonTitles:NSLocalizedString(@"GENERAL_LOGIN",@""),NSLocalizedString(@"REGISTER_REGISTER_BUTTON",@""),settingsTxt, nil];
  49. [actionSheet setTitleBackgroundColor:kTOPUICOLOR];
  50. [actionSheet setTitleTextColor:kLIGHTGRAYUICOLOR];
  51. [actionSheet setButtonTextColor:kLIGHTGRAYUICOLOR];
  52. [actionSheet setButtonBackgroundColor:kTOPUICOLOR forButtonAtIndex:0];
  53. [actionSheet setButtonBackgroundColor:kTOPUICOLOR forButtonAtIndex:1];
  54. if (showSettings) {
  55. [actionSheet setButtonBackgroundColor:kBOTTOMUICOLOR forButtonAtIndex:2];
  56. [actionSheet setButtonBackgroundColor:kREDUICOLOR forButtonAtIndex:3];
  57. } else {
  58. [actionSheet setButtonBackgroundColor:kREDUICOLOR forButtonAtIndex:2];
  59. }
  60. [actionSheet setAlpha:1];
  61. [actionSheet showInView:[[[UIApplication sharedApplication] delegate] window]];
  62. }
  63. -(void)closeAlert
  64. {
  65. [currentAlertView close];
  66. }
  67. -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
  68. {
  69. DNSLog(@"%ld",(long)buttonIndex);
  70. if (buttonIndex == 2 && showSettings) {
  71. [kROOTVC performSelector:@selector(startSettings:) withObject:self];
  72. } else if (buttonIndex == 0) {
  73. [self showLoginScreen];
  74. } else if (buttonIndex == 1) {
  75. [self showRegisterScreen];
  76. }
  77. showSettings = NO;
  78. }
  79. -(void)showLoginScreen
  80. {
  81. emailField = nil;
  82. userField = nil;
  83. passField = nil;
  84. passCheckField = nil;
  85. activeField = nil;
  86. CustomIOS7AlertView *alertView = [[CustomIOS7AlertView alloc] init];
  87. [alertView setButtonTitles:[NSMutableArray arrayWithObjects:NSLocalizedString(@"GENERAL_CANCEL", @""), NSLocalizedString(@"GENERAL_LOGIN", @""), nil]];
  88. [alertView setDelegate:self];
  89. [alertView setContainerView:[self loginView]];
  90. [alertView setTag:0];
  91. [alertView setButtonTextColor:kLIGHTGRAYUICOLOR];
  92. [alertView show];
  93. }
  94. -(void)showRegisterScreen
  95. {
  96. emailField = nil;
  97. userField = nil;
  98. passField = nil;
  99. passCheckField = nil;
  100. activeField = nil;
  101. CustomIOS7AlertView *alertView = [[CustomIOS7AlertView alloc] init];
  102. [alertView setButtonTitles:[NSMutableArray arrayWithObjects:NSLocalizedString(@"GENERAL_CANCEL", @""), NSLocalizedString(@"REGISTER_REGISTER_BUTTON", @""), nil]];
  103. [alertView setDelegate:self];
  104. [alertView setContainerView:[self registerView]];
  105. [alertView setTag:1];
  106. [alertView setButtonTextColor:kWHITEUICOLOR];
  107. [alertView show];
  108. [[[[UIApplication sharedApplication] delegate] window] addSubview:pickCountry];
  109. }
  110. -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  111. {
  112. DNSLog(@"%ld, %ld",(long)buttonIndex,(long)alertView.tag);
  113. if ([alertView tag] == 0 && buttonIndex == 1) {
  114. DNSLog(@"%@",[alertView textFieldAtIndex:0] );
  115. DNSLog(@"%@",[alertView textFieldAtIndex:1]);
  116. NSBlockOperation *op = [NSBlockOperation blockOperationWithBlock:^(void){
  117. [[wbWaitView sharedWait] performSelectorOnMainThread:@selector(show) withObject:NULL waitUntilDone:YES];
  118. }];
  119. [op setCompletionBlock:^(void){
  120. dispatch_sync(dispatch_get_main_queue(), ^{
  121. NSString *guest_id = [[wbAPI sharedAPI] getSettingWithKey:@"guest_id"];
  122. [[wbAPI sharedAPI] authenticate:[[alertView textFieldAtIndex:0] text] password:[[alertView textFieldAtIndex:1] text] guest_id:guest_id];
  123. });
  124. }];
  125. [op start];
  126. } else {
  127. kHIDEWAIT;
  128. }
  129. }
  130. - (void)customIOS7dialogButtonTouchUpInside:(id)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
  131. {
  132. currentAlertView = alertView;
  133. DNSLog(@"%ld, %@",(long)buttonIndex,(CustomIOS7AlertView*)alertView);
  134. if ([(CustomIOS7AlertView*)alertView tag] == 0) {
  135. if (buttonIndex == 1) {
  136. [self doLogin];
  137. } else {
  138. kHIDEWAIT;
  139. [alertView close];
  140. [activeField resignFirstResponder];
  141. }
  142. } else {
  143. if (buttonIndex == 1) {
  144. [self checkRegister];
  145. } else {
  146. kHIDEWAIT;
  147. [alertView close];
  148. [activeField resignFirstResponder];
  149. }
  150. }
  151. }
  152. -(void)doLogin
  153. {
  154. NSBlockOperation *op = [NSBlockOperation blockOperationWithBlock:^(void){
  155. [[wbWaitView sharedWait] performSelectorOnMainThread:@selector(show) withObject:NULL waitUntilDone:YES];
  156. }];
  157. [op setCompletionBlock:^(void){
  158. dispatch_sync(dispatch_get_main_queue(), ^{
  159. NSString *guest_id = [[wbAPI sharedAPI] getSettingWithKey:@"guest_id"];
  160. [[wbAPI sharedAPI] authenticate:userField.text password:passCheckField.text guest_id:guest_id];
  161. });
  162. }];
  163. [op start];
  164. }
  165. -(void)checkRegister
  166. {
  167. NSBlockOperation *op = [NSBlockOperation blockOperationWithBlock:^(void){
  168. [[wbWaitView sharedWait] performSelectorOnMainThread:@selector(show) withObject:NULL waitUntilDone:YES];
  169. }];
  170. [op setCompletionBlock:^(void){
  171. dispatch_sync(dispatch_get_main_queue(), ^{
  172. if ([self checkForRegisterErrors]) {
  173. NSDictionary *userArray = [NSDictionary dictionaryWithObjectsAndKeys:
  174. [NSString stringWithFormat:@"%@",emailField.text],@"email",
  175. [NSString stringWithFormat:@"%@",userField.text],@"username",
  176. [NSString stringWithFormat:@"%@",passField.text],@"password1",
  177. [NSString stringWithFormat:@"%@",passField.text],@"password2",
  178. [selectedCountry objectForKey:@"country"],@"country",
  179. nil];
  180. [[wbAPI sharedAPI] createUser:userArray];
  181. //kHIDEWAIT
  182. } else {
  183. kHIDEWAIT;
  184. }
  185. });
  186. }];
  187. [op start];
  188. }
  189. -(BOOL)checkForRegisterErrors
  190. {
  191. if (emailField.text.length < 1 | userField.text.length < 1) {
  192. [[wbAPI sharedAPI] showErrorWithTxt:NSLocalizedString(@"REGISTER_ERROR_EMPTY_FIELDS",@"")];
  193. return NO;
  194. }
  195. else if (![passField.text isEqualToString:passCheckField.text]){
  196. [[wbAPI sharedAPI] showErrorWithTxt:NSLocalizedString(@"REGISTER_ERROR_PASSWORD_MISMATCH",@"")];
  197. return NO;
  198. }
  199. else if (![[wbAPI sharedAPI] validateEmailWithString:emailField.text]) {
  200. [[wbAPI sharedAPI] showErrorWithTxt:NSLocalizedString(@"REGISTER_ERROR_BROKEN_EMAIL",@"")];
  201. return NO;
  202. }
  203. else if (passField.text.length < 4 ) {
  204. [[wbAPI sharedAPI] showErrorWithTxt:NSLocalizedString(@"REGISTER_ERROR_PASSWORD_TOO_SHORT",@"")];
  205. return NO;
  206. }
  207. else if (selectedCountry == nil) {
  208. [[wbAPI sharedAPI] showErrorWithTxt:NSLocalizedString(@"REGISTER_ERROR_EMPTY_COUNTRY",@"")];
  209. return NO;
  210. }
  211. return YES;
  212. }
  213. //- (BOOL)validateEmailWithString:(NSString*)email
  214. //{
  215. // NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
  216. // NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
  217. // return [emailTest evaluateWithObject:email];
  218. //}
  219. -(UIView*)loginView
  220. {
  221. UIView *rv = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 150)];
  222. UIButton *closekb = [UIButton buttonWithType:UIButtonTypeSystem];
  223. [closekb setFrame:rv.frame];
  224. [closekb setBackgroundColor:kTRANSPARENTUICOLOR];
  225. [closekb addTarget:activeField action:@selector(resignFirstResponder) forControlEvents:UIControlEventTouchUpInside];
  226. [rv addSubview:closekb];
  227. wbLabel *regLabel = [[wbLabel alloc] init];
  228. [regLabel setText:[NSLocalizedString(@"GENERAL_LOGIN", @"") uppercaseString]];
  229. [regLabel setTextColor:kGREENUICOLOR];
  230. [regLabel setFont:kFONT(30)];
  231. [regLabel sizeToFit];
  232. [regLabel setCenter:CGPointMake(CGRectGetMidX(rv.frame), 26)];
  233. //Textfields
  234. #define firstX (rv.frame.size.width/2-(kTXTBOXW/2))
  235. CGRect usernameRect = CGRectMake(firstX,CGRectGetMaxY(regLabel.frame)+12,
  236. (kTXTBOXW),
  237. kTXTBOXH);
  238. CGRect passwordCheckRect = CGRectMake(firstX,CGRectGetMaxY(usernameRect)+1,
  239. kTXTBOXW,
  240. kTXTBOXH);
  241. if (userField == nil) {
  242. userField = [self giveTxtFieldWithRect:usernameRect placeholder:NSLocalizedString(@"GENERAL_USERNAME",@"") secure:NO tag:0];
  243. }
  244. CAShapeLayer *passwordMaskLayerT = [[CAShapeLayer alloc] init];
  245. UIBezierPath *passwordMaskPathWithRadiusTop = [UIBezierPath bezierPathWithRoundedRect:userField.bounds byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight) cornerRadii:CGSizeMake(10.0, 10.0)];
  246. passwordMaskLayerT.frame = userField.bounds;
  247. passwordMaskLayerT.path = passwordMaskPathWithRadiusTop.CGPath;
  248. passwordMaskLayerT.fillColor = [UIColor whiteColor].CGColor;
  249. [userField.layer setMask:passwordMaskLayerT];
  250. [userField setDelegate:self];
  251. if (passCheckField == nil) {
  252. passCheckField = [self giveTxtFieldWithRect:passwordCheckRect placeholder:NSLocalizedString(@"GENERAL_PASSWORD",@"") secure:YES tag:1];
  253. }
  254. CAShapeLayer *passwordMaskLayerB = [[CAShapeLayer alloc] init];
  255. UIBezierPath *passwordMaskPathWithRadiusBottom = [UIBezierPath bezierPathWithRoundedRect:passCheckField.bounds byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight) cornerRadii:CGSizeMake(10.0, 10.0)];
  256. passwordMaskLayerB.frame = passCheckField.bounds;
  257. passwordMaskLayerB.path = passwordMaskPathWithRadiusBottom.CGPath;
  258. passwordMaskLayerB.fillColor = kBOTTOMUICOLOR.CGColor;//[UIColor whiteColor].CGColor;
  259. [passCheckField.layer setMask:passwordMaskLayerB];
  260. [passCheckField setDelegate:self];
  261. [rv addSubview:userField];
  262. [rv addSubview:passCheckField];
  263. [rv addSubview:regLabel];
  264. return rv;
  265. }
  266. -(UIView*)registerView
  267. {
  268. UIView *rv = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 265+kTXTBOXH)];
  269. UIButton *closekb = [UIButton buttonWithType:UIButtonTypeSystem];
  270. [closekb setFrame:rv.frame];
  271. [closekb setBackgroundColor:kTRANSPARENTUICOLOR];
  272. [closekb addTarget:activeField action:@selector(resignFirstResponder) forControlEvents:UIControlEventTouchUpInside];
  273. [rv addSubview:closekb];
  274. wbLabel *regLabel = [[wbLabel alloc] init];
  275. [regLabel setText:[NSLocalizedString(@"REGISTER_REGISTER_BUTTON", @"") uppercaseString]];
  276. [regLabel setTextColor:kGREENUICOLOR];
  277. [regLabel setFont:kFONT(30)];
  278. [regLabel sizeToFit];
  279. [regLabel setCenter:CGPointMake(CGRectGetMidX(rv.frame), 30)];
  280. //Textfields
  281. #define firstX (rv.frame.size.width/2-(kTXTBOXW/2))
  282. CGRect usernameRect = CGRectMake(firstX,CGRectGetMaxY(regLabel.frame)+12,
  283. (kTXTBOXW),
  284. kTXTBOXH);
  285. CGRect emailRect = CGRectMake(firstX,CGRectGetMaxY(usernameRect)+1,
  286. kTXTBOXW,
  287. kTXTBOXH);
  288. CGRect countryRect = CGRectMake(firstX,CGRectGetMaxY(emailRect)+1,
  289. kTXTBOXW,
  290. kTXTBOXH);
  291. CGRect passwordRect = CGRectMake(firstX,CGRectGetMaxY(countryRect)+1,
  292. kTXTBOXW,
  293. kTXTBOXH);
  294. CGRect passwordCheckRect = CGRectMake(firstX,CGRectGetMaxY(passwordRect)+1,
  295. kTXTBOXW,
  296. kTXTBOXH);
  297. if (userField == nil) {
  298. userField = [self giveTxtFieldWithRect:usernameRect placeholder:NSLocalizedString(@"GENERAL_USERNAME",@"") secure:NO tag:0];
  299. }
  300. CAShapeLayer *passwordMaskLayerT = [[CAShapeLayer alloc] init];
  301. UIBezierPath *passwordMaskPathWithRadiusTop = [UIBezierPath bezierPathWithRoundedRect:userField.bounds byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight) cornerRadii:CGSizeMake(10.0, 10.0)];
  302. passwordMaskLayerT.frame = userField.bounds;
  303. passwordMaskLayerT.path = passwordMaskPathWithRadiusTop.CGPath;
  304. passwordMaskLayerT.fillColor = [UIColor whiteColor].CGColor;
  305. [userField.layer setMask:passwordMaskLayerT];
  306. [userField setDelegate:self];
  307. if (emailField == nil) {
  308. emailField = [self giveTxtFieldWithRect:emailRect placeholder:NSLocalizedString(@"GENERAL_EMAIL",@"") secure:NO tag:1];
  309. }
  310. [emailField setDelegate:self];
  311. if (passField == nil) {
  312. passField = [self giveTxtFieldWithRect:passwordRect placeholder:NSLocalizedString(@"GENERAL_PASSWORD",@"") secure:YES tag:2];
  313. }
  314. //country
  315. if (countryButton == nil) {
  316. countryButton = [UIButton buttonWithType:UIButtonTypeSystem];
  317. }
  318. [countryButton setBackgroundColor:kBOTTOMUICOLOR];
  319. [countryButton setFrame:countryRect];
  320. [countryButton setTitle:NSLocalizedString(@"GENERAL_COUNTRY", @"") forState:UIControlStateNormal];
  321. [countryButton setTitleColor:kWHITEUICOLOR forState:UIControlStateNormal];
  322. [countryButton setTitleColor:kWHITEUICOLOR forState:UIControlStateSelected];
  323. [[countryButton titleLabel] setFont:kFONTHelvetica(18)];
  324. [countryButton addTarget:self action:@selector(countryAction) forControlEvents:UIControlEventTouchUpInside];
  325. [countryButton setTintColor:kTRANSPARENTUICOLOR];
  326. [self setSelectedCountry:[[wbAPI sharedAPI] currentCountry]];
  327. UIImage *arrowImg = [[wbAPI sharedAPI] changeColorForImage:[UIImage ch_imageNamed:@"feed_arrow.png"] toColor:kBKGUICOLOR];
  328. UIImageView *downArrowImgView = [[UIImageView alloc] initWithImage:arrowImg];
  329. [downArrowImgView setFrame:CGRectMake(countryButton.frame.size.width-25, 0, arrowImg.size.width/2, arrowImg.size.height/2)];
  330. [downArrowImgView setCenter:CGPointMake(downArrowImgView.center.x, countryButton.frame.size.height/2)];
  331. [downArrowImgView setUserInteractionEnabled:NO];
  332. [passField setDelegate:self];
  333. if (passCheckField == nil) {
  334. passCheckField = [self giveTxtFieldWithRect:passwordCheckRect placeholder:NSLocalizedString(@"REGISTER_CONFIRM_PASSWORD",@"") secure:YES tag:3];
  335. }
  336. CAShapeLayer *passwordMaskLayerB = [[CAShapeLayer alloc] init];
  337. UIBezierPath *passwordMaskPathWithRadiusBottom = [UIBezierPath bezierPathWithRoundedRect:passCheckField.bounds byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight) cornerRadii:CGSizeMake(10.0, 10.0)];
  338. passwordMaskLayerB.frame = passCheckField.bounds;
  339. passwordMaskLayerB.path = passwordMaskPathWithRadiusBottom.CGPath;
  340. passwordMaskLayerB.fillColor = kBOTTOMUICOLOR.CGColor;//[UIColor whiteColor].CGColor;
  341. [passCheckField.layer setMask:passwordMaskLayerB];
  342. [passCheckField setDelegate:self];
  343. //terms&cond
  344. NSMutableAttributedString *firstLine = [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"REGISTER_TERMS_CONDITIONS", @"")];
  345. NSMutableAttributedString *rowStr = [[NSMutableAttributedString alloc] initWithAttributedString:firstLine];
  346. [rowStr addAttribute:NSForegroundColorAttributeName value:kNOTSOLIGHTGRAYUICOLOR range:(NSRange){0,[rowStr length]}];
  347. UIButton *termButton = [UIButton buttonWithType:UIButtonTypeCustom];
  348. [termButton setAttributedTitle:rowStr forState:UIControlStateNormal];
  349. [termButton.titleLabel setFont:kFONTHelvetica(12)];
  350. [termButton.titleLabel setNumberOfLines:0];
  351. [termButton setFrame:CGRectMake(0, CGRectGetMaxY(passCheckField.frame)+10,rv.frame.size.width, 40)];
  352. [termButton addTarget:self action:@selector(openTermsUrl) forControlEvents:UIControlEventTouchUpInside];
  353. [termButton.titleLabel setTextAlignment:NSTextAlignmentCenter];
  354. [termButton setBackgroundColor:kTRANSPARENTUICOLOR];
  355. [rv addSubview:userField];
  356. [rv addSubview:emailField];
  357. [rv addSubview:countryButton];
  358. [countryButton addSubview:downArrowImgView];
  359. [rv addSubview:passField];
  360. [rv addSubview:passCheckField];
  361. [rv addSubview:regLabel];
  362. [rv addSubview:termButton];
  363. return rv;
  364. }
  365. //text field
  366. -(UITextField *)giveTxtFieldWithRect:(CGRect)tfRect placeholder:(NSString*)placeholder secure:(BOOL)secure tag:(NSInteger)tag
  367. {
  368. UITextField *tmp = [self giveTxtFieldWithRect:tfRect placeholder:placeholder secure:secure];
  369. [tmp setTag:tag];
  370. return tmp;
  371. }
  372. -(UITextField *)giveTxtFieldWithRect:(CGRect)tfRect placeholder:(NSString*)placeholder secure:(BOOL)secure
  373. {
  374. UITextField *txtField = [[UITextField alloc]initWithFrame:tfRect];
  375. [txtField setTextColor:kWHITEUICOLOR];
  376. [txtField setAutocapitalizationType:UITextAutocapitalizationTypeNone];
  377. [txtField setBackgroundColor:/*UIColorFromHexRGB(0x434947)*/kBOTTOMUICOLOR];
  378. [txtField setBorderStyle:UITextBorderStyleNone];
  379. [txtField setFont:kFONTHelvetica(18)];
  380. [txtField setUserInteractionEnabled:YES];
  381. [txtField setSecureTextEntry:secure];
  382. [txtField setKeyboardAppearance:UIKeyboardAppearanceDark];
  383. [txtField setKeyboardType:UIKeyboardTypeEmailAddress];
  384. [txtField setAutocorrectionType:UITextAutocorrectionTypeNo];
  385. [txtField setTintColor:kWHITEUICOLOR];
  386. [txtField setAutoresizesSubviews:YES];
  387. [txtField setReturnKeyType:UIReturnKeyNext];
  388. [txtField setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
  389. [txtField setTextAlignment:NSTextAlignmentCenter];
  390. [txtField setAttributedPlaceholder:[[NSAttributedString alloc] initWithString:placeholder attributes:@{NSForegroundColorAttributeName:kLIGHTGRAYUICOLOR}]];
  391. return txtField;
  392. }
  393. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  394. NSInteger nextTag = textField.tag + 1;
  395. // Try to find next responder
  396. UIResponder* nextResponder = [textField.superview viewWithTag:nextTag];
  397. if (nextResponder) {
  398. // Found next responder, so set it.
  399. [nextResponder becomeFirstResponder];
  400. } else {
  401. // Not found, so remove keyboard.
  402. [textField resignFirstResponder];
  403. }
  404. return NO;
  405. }
  406. - (void)textFieldDidBeginEditing:(UITextField *)textField
  407. {
  408. activeField = textField;
  409. }
  410. -(void)openTermsUrl
  411. {
  412. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:NSLocalizedString(kTERMSCONDLINK, @"")]];
  413. }
  414. -(void)countryAction
  415. {
  416. DCMSG(@"countryAction");
  417. [activeField resignFirstResponder];
  418. [pickCountry show];
  419. }
  420. -(void)setSelectedCountry:(NSDictionary *)_selectedCountry
  421. {
  422. selectedCountry = _selectedCountry;
  423. [countryButton setTitle:[selectedCountry objectForKey:@"name"] forState:UIControlStateSelected];
  424. [countryButton setSelected:YES];
  425. }
  426. @end