PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/WHAMBUSH/wbSettingsTableView.m

https://gitlab.com/urbanjunglestudio/whambush-ios
Objective C | 702 lines | 555 code | 125 blank | 22 comment | 96 complexity | d063c352c610ebc8a8be42f9534623a0 MD5 | raw file
  1. //
  2. // wbSettingsTableView.m
  3. // WHAMBUSH
  4. //
  5. // Created by Jari Kalinainen on 12/01/15.
  6. // Copyright (c) 2015 Jari Kalinainen. All rights reserved.
  7. //
  8. #import "wbSettingsTableView.h"
  9. @implementation wbSettingsTableView
  10. @synthesize selectedCountry;
  11. - (id)initWithFrame:(CGRect)frame
  12. {
  13. self = [super initWithFrame:frame];
  14. if (self) {
  15. [self setDelegate:self];
  16. [self setDataSource:self];
  17. [self setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
  18. [self setSeparatorColor:kSEPRATORUICOLOR];
  19. [self setSeparatorInset:UIEdgeInsetsZero];
  20. [self setBackgroundColor:kBKGUICOLOR];
  21. [self setHidden:NO];
  22. UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 2*kFOLLOWLINEH)];
  23. [footer setBackgroundColor:kTRANSPARENTUICOLOR];
  24. [self setTableFooterView:footer];
  25. if (![[wbAPI sharedAPI] is_guest]) {
  26. selectBirthdayView = [[wbBirthdaySelectView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
  27. [selectBirthdayView setBirthday:[[wbUser sharedUser] birthday]];
  28. [selectBirthdayView setDelegate:self];
  29. pickCountry = [[wbCountryPickerView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
  30. [pickCountry setDelegate:self];
  31. [pickCountry setSelectedCountry:[[wbUser sharedUser] countryDictionary]];
  32. insertTxtView = [[wbInsertTextView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
  33. [insertTxtView setDelegate:self];
  34. [insertTxtView setMaxCharCount:90];
  35. [insertTxtView setMaxLinesCount:1];
  36. [insertTxtView setHeaderText:NSLocalizedString(@"SETTINGS_EMAIL",@"")];
  37. [[wbUser sharedUser] updateUserData];
  38. }
  39. }
  40. DPRINTCLASS;
  41. return self;
  42. }
  43. #define kNUMSECTIONS 4
  44. #define kSETTINGS 0
  45. //#define kNOTIFICATIONS 1
  46. #define kSUPPORT 1
  47. #define kSOME 2
  48. #define kALLOWEMAIL
  49. #define kACCOUNTEMAIL 0
  50. #define kACCOUNTBIRTHDAY 1
  51. #define kACCOUNTCOUNTRY 2
  52. #define kACCOUNTPASSWORD 3
  53. // Only override drawRect: if you perform custom drawing.
  54. // An empty implementation adversely affects performance during animation.
  55. - (void)drawRect:(CGRect)rect {
  56. if ([[wbUser sharedUser] userReady] || [[wbAPI sharedAPI] is_guest]) {
  57. // Drawing code
  58. kHIDEWAIT;
  59. if (insertTxtView != nil) {
  60. [insertTxtView setInitialText:[[wbUser sharedUser] email]];
  61. [self addSubview:insertTxtView];
  62. }
  63. if (selectBirthdayView != nil) {
  64. [selectBirthdayView setBirthday:[[wbUser sharedUser] birthday]];
  65. [self addSubview:selectBirthdayView];
  66. [self bringSubviewToFront:selectBirthdayView];
  67. }
  68. if (pickCountry != nil) {
  69. [pickCountry setSelectedCountry:[[wbUser sharedUser] countryDictionary]];
  70. [self addSubview:pickCountry];
  71. [self bringSubviewToFront:pickCountry];
  72. }
  73. [self inactiveEmailPrompt];
  74. [self reloadData];
  75. } else {
  76. kSHOWWAIT;
  77. [self performSelector:@selector(setNeedsDisplay) withObject:nil afterDelay:1];
  78. }
  79. }
  80. -(void)hideKB
  81. {
  82. [insertTxtView hideTextView];
  83. [selectBirthdayView hide];
  84. [pickCountry hide];
  85. }
  86. -(UIView*)accountRow:(NSInteger)row
  87. {
  88. wbLabel *line = [[wbLabel alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width-(kFOLLOWLINEH/2+6), kFOLLOWLINEH)];
  89. [line setBackgroundColor:kTOPUICOLOR];
  90. [line setTextColor:kNOTSOLIGHTGRAYUICOLOR];
  91. [line setFont:kFONTHelvetica(15)];
  92. [line setEdgeInsets:UIEdgeInsetsMake(2, 12, 2, 0)];
  93. NSMutableAttributedString *beginningOfLine;
  94. NSMutableAttributedString *endOfLine;
  95. NSMutableAttributedString *stringLine;
  96. UIImage *lineImg;
  97. switch (row) {
  98. case kACCOUNTEMAIL: //email
  99. beginningOfLine = [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"SETTINGS_EMAIL", @"")];
  100. [beginningOfLine addAttribute:NSForegroundColorAttributeName value:kNOTSOLIGHTGRAYUICOLOR range:(NSRange){0,[beginningOfLine length]}];
  101. endOfLine = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@",[[wbUser sharedUser] email]]];
  102. if ([[[wbUser sharedUser] activation_state] isEqualToString:@"NEW"]) {
  103. [endOfLine addAttribute:NSForegroundColorAttributeName value:kREDUICOLOR range:(NSRange){0,[endOfLine length]}];
  104. } else {
  105. [endOfLine addAttribute:NSForegroundColorAttributeName value:kWHITEUICOLOR range:(NSRange){0,[endOfLine length]}];
  106. }
  107. stringLine = [[NSMutableAttributedString alloc] initWithAttributedString:beginningOfLine];
  108. [stringLine appendAttributedString:endOfLine];
  109. #ifdef kALLOWEMAIL
  110. lineImg = [UIImage ch_imageNamed:@"settings_edit.png"];
  111. #endif
  112. break;
  113. case kACCOUNTBIRTHDAY: //birthday
  114. beginningOfLine = [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"SETTINGS_BIRTHDAY", @"")];
  115. [beginningOfLine addAttribute:NSForegroundColorAttributeName value:kNOTSOLIGHTGRAYUICOLOR range:(NSRange){0,[beginningOfLine length]}];
  116. if ([[[wbUser sharedUser] birthdayString] length] > 0) {
  117. endOfLine = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@",[[wbUser sharedUser] birthdayString]]];
  118. } else {
  119. endOfLine = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@",NSLocalizedString(@"SETTINGS_BIRTHDAY_EMPTY", @"")]];
  120. }
  121. [endOfLine addAttribute:NSForegroundColorAttributeName value:kWHITEUICOLOR range:(NSRange){0,[endOfLine length]}];
  122. stringLine = [[NSMutableAttributedString alloc] initWithAttributedString:beginningOfLine];
  123. [stringLine appendAttributedString:endOfLine];
  124. lineImg = [UIImage ch_imageNamed:@"settings_edit.png"];
  125. break;
  126. case kACCOUNTPASSWORD: // password
  127. beginningOfLine = [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"SETTINGS_PASSWORD_CHANGE", @"")];
  128. stringLine = [[NSMutableAttributedString alloc] initWithAttributedString:beginningOfLine];
  129. lineImg = [UIImage ch_imageNamed:@"settings_link.png"];
  130. break;
  131. case kACCOUNTCOUNTRY:
  132. beginningOfLine = [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"SETTINGS_COUNTRY", @"")];
  133. [beginningOfLine addAttribute:NSForegroundColorAttributeName value:kNOTSOLIGHTGRAYUICOLOR range:(NSRange){0,[beginningOfLine length]}];
  134. endOfLine = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@",NSLocalizedString([[[wbUser sharedUser] countryDictionary] objectForKey:@"name"],@"")]];
  135. [endOfLine addAttribute:NSForegroundColorAttributeName value:kWHITEUICOLOR range:(NSRange){0,[endOfLine length]}];
  136. stringLine = [[NSMutableAttributedString alloc] initWithAttributedString:beginningOfLine];
  137. [stringLine appendAttributedString:endOfLine];
  138. lineImg = [UIImage ch_imageNamed:@"settings_edit.png"];
  139. break;
  140. default:
  141. break;
  142. }
  143. [line addSubview:[self setImage:lineImg]];
  144. [line setAttributedText:stringLine];
  145. return line;
  146. }
  147. -(UIView*)notificationRow:(NSInteger)row
  148. {
  149. return nil;
  150. }
  151. -(UIView*)supportRow:(NSInteger)row
  152. {
  153. wbLabel *line = [[wbLabel alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width-(kFOLLOWLINEH/2+6), kFOLLOWLINEH)];
  154. [line setBackgroundColor:kTRANSPARENTUICOLOR];
  155. [line setTextColor:kNOTSOLIGHTGRAYUICOLOR];
  156. [line setFont:kFONTHelvetica(15)];
  157. [line setEdgeInsets:UIEdgeInsetsMake(2, 12, 2, 0)];
  158. NSMutableAttributedString *beginningOfLine;
  159. NSMutableAttributedString *stringLine;
  160. UIImage *lineImg;
  161. switch (row) {
  162. case 0: //FAQ
  163. beginningOfLine = [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"SETTINGS_SUPPORT_FAQ", @"")];
  164. stringLine = [[NSMutableAttributedString alloc] initWithAttributedString:beginningOfLine];
  165. lineImg = [UIImage ch_imageNamed:@"settings_link.png"];
  166. break;
  167. case 1: //SUPPORT MAIL
  168. beginningOfLine = [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"SETTINGS_SUPPORT_LABEL", @"")];
  169. stringLine = [[NSMutableAttributedString alloc] initWithAttributedString:beginningOfLine];
  170. lineImg = [UIImage ch_imageNamed:@"settings_mail.png"];
  171. break;
  172. default:
  173. break;
  174. }
  175. [line addSubview:[self setImage:lineImg]];
  176. [line setAttributedText:stringLine];
  177. return line;
  178. }
  179. -(UIView*)someRow:(NSInteger)row
  180. {
  181. //FACEBOOK
  182. //INSTAGRAM
  183. //TWITTER
  184. wbLabel *line = [[wbLabel alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width-(kFOLLOWLINEH/2+6), kFOLLOWLINEH)];
  185. [line setBackgroundColor:kTRANSPARENTUICOLOR];
  186. [line setTextColor:kNOTSOLIGHTGRAYUICOLOR];
  187. [line setFont:kFONTHelvetica(15)];
  188. [line setEdgeInsets:UIEdgeInsetsMake(2, 12, 2, 0)];
  189. NSMutableAttributedString *beginningOfLine;
  190. NSMutableAttributedString *stringLine;
  191. UIImage *lineImg;
  192. switch (row) {
  193. case 0: //FACEBOOK
  194. beginningOfLine = [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"SETTINGS_SOME_FACEBOOK", @"")];
  195. stringLine = [[NSMutableAttributedString alloc] initWithAttributedString:beginningOfLine];
  196. lineImg = [UIImage ch_imageNamed:@"settings_link.png"];
  197. break;
  198. case 1: //INSTAGRAM
  199. beginningOfLine = [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"SETTINGS_SOME_INSTAGRAM", @"")];
  200. stringLine = [[NSMutableAttributedString alloc] initWithAttributedString:beginningOfLine];
  201. lineImg = [UIImage ch_imageNamed:@"settings_link.png"];
  202. break;
  203. case 2: //TWITTER
  204. beginningOfLine = [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"SETTINGS_SOME_TWITTER", @"")];
  205. stringLine = [[NSMutableAttributedString alloc] initWithAttributedString:beginningOfLine];
  206. lineImg = [UIImage ch_imageNamed:@"settings_link.png"];
  207. break;
  208. default:
  209. break;
  210. }
  211. [line addSubview:[self setImage:lineImg]];
  212. [line setAttributedText:stringLine];
  213. return line;
  214. }
  215. -(UIView*)logoutRow
  216. {
  217. wbRoundedButton *logoutButton = [wbRoundedButton buttonWithType:UIButtonTypeSystem];
  218. [logoutButton setButtonColor:kREDUICOLOR];
  219. [logoutButton setFilled:NO];
  220. [logoutButton setHelvetica:NO];
  221. [logoutButton setShowsTouchWhenHighlighted:YES];
  222. [logoutButton setTitle:NSLocalizedString(@"GENERAL_LOGOUT",@"") forState:UIControlStateNormal];
  223. [logoutButton sizeToFit];
  224. [logoutButton setCenter:CGPointMake(self.frame.size.width/2, logoutButton.center.y)];
  225. [logoutButton addTarget:self action:@selector(logout:) forControlEvents:UIControlEventTouchUpInside];
  226. return logoutButton;
  227. }
  228. -(UIImageView*)setImage:(UIImage *)_image
  229. {
  230. if (_image != nil) {
  231. float width = kFOLLOWLINEH/2;
  232. float height = kFOLLOWLINEH/2;
  233. if (_image.size.height > _image.size.width) {
  234. if (height > _image.size.height) {
  235. height = _image.size.height;
  236. }
  237. width = (_image.size.width)/(_image.size.height/height);
  238. } else {
  239. if (width > _image.size.width) {
  240. width = _image.size.width;
  241. }
  242. height = (_image.size.height)/(_image.size.width/width);
  243. }
  244. UIImageView *buttonImageView = [[UIImageView alloc] init];
  245. [buttonImageView setImage:_image];
  246. [buttonImageView setFrame:CGRectMake(self.frame.size.width-(width+6), 0, width,height)];
  247. [buttonImageView setCenter:CGPointMake(buttonImageView.center.x, kFOLLOWLINEH/2)];
  248. return buttonImageView;
  249. } else {
  250. return nil;
  251. }
  252. }
  253. /////
  254. -(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  255. {
  256. if ([[wbAPI sharedAPI] is_guest] && section == kSETTINGS) {
  257. return nil;
  258. }
  259. wbLabel *header = [[wbLabel alloc] init];
  260. [header setBackgroundColor:kBKGUICOLOR];
  261. [header setTextColor:kWHITEUICOLOR];
  262. [header setFont:kFONT(24)];
  263. [header setEdgeInsets:UIEdgeInsetsMake(12, 12, 0, 0)];
  264. if (section == kSETTINGS) {
  265. [header setText:[NSLocalizedString(@"SETTINGS_ACCOUNT", @"") uppercaseString]];
  266. // } else if (section == kNOTIFICATIONS) {
  267. // [header setText:@"NOTIFICATIONS"];
  268. } else if (section == kSUPPORT) {
  269. [header setText:[NSLocalizedString(@"SETTINGS_SUPPORT", @"") uppercaseString]];
  270. } else if (section == kSOME) {
  271. [header setText:[NSLocalizedString(@"SETTINGS_SOME", @"") uppercaseString]];
  272. } else {
  273. [header setText:@""];
  274. }
  275. [header sizeToFit];
  276. return header;
  277. }
  278. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  279. {
  280. if (section == kSETTINGS) {
  281. if ([[wbAPI sharedAPI] is_guest]) {
  282. return 0;
  283. } else {
  284. return 4;
  285. }
  286. // } else if (section == kNOTIFICATIONS) {
  287. // return 0;
  288. } else if (section == kSUPPORT) {
  289. return 2;
  290. } else if (section == kSOME) {
  291. return 3;
  292. } else {
  293. if ([[wbAPI sharedAPI] is_guest]) {
  294. return 0;
  295. } else {
  296. return 1;
  297. }
  298. }
  299. }
  300. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  301. {
  302. return kNUMSECTIONS;
  303. }
  304. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  305. {
  306. if ([[wbAPI sharedAPI] is_guest] && section == kSETTINGS) {
  307. return 0;
  308. } else {
  309. return (float)kFOLLOWLINEH+10;
  310. }
  311. }
  312. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  313. if ([[wbAPI sharedAPI] is_guest] && [indexPath section] == kSETTINGS) {
  314. return 0;
  315. } else {
  316. return kFOLLOWLINEH+1;
  317. }
  318. }
  319. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  320. {
  321. NSString *identifier = [NSString stringWithFormat:@"%ld%ld",(long)[indexPath row],(long)[indexPath section]];
  322. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  323. if (cell == nil){
  324. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
  325. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  326. [cell setSeparatorInset:UIEdgeInsetsZero];
  327. [cell setBackgroundColor:kTOPUICOLOR];
  328. [cell setClipsToBounds:NO];
  329. }
  330. if ([indexPath section] == kSETTINGS) {
  331. if (![[wbAPI sharedAPI] is_guest]) {
  332. [cell addSubview:[self accountRow:[indexPath row]]];
  333. }
  334. } else if ([indexPath section] == kSUPPORT) {
  335. [cell addSubview:[self supportRow:[indexPath row]]];
  336. } else if ([indexPath section] == kSOME) {
  337. [cell addSubview:[self someRow:[indexPath row]]];
  338. } else {
  339. [cell addSubview:[self logoutRow]];
  340. [cell setBackgroundColor:kTRANSPARENTUICOLOR];
  341. }
  342. [self bringSubviewToFront:selectBirthdayView];
  343. [self bringSubviewToFront:pickCountry];
  344. [self bringSubviewToFront:insertTxtView];
  345. [self setSeparatorStyle:UITableViewCellSeparatorStyleNone];
  346. [self setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
  347. NSArray *subs = [cell subviews];
  348. DNSLog(@"sc: %lu",(long)[subs count]);
  349. DNSLog(@"%@",subs);
  350. DNSLog(@"%@",cell);
  351. return cell;
  352. }
  353. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  354. {
  355. switch ([indexPath section]) {
  356. case 0:
  357. switch ([indexPath row]) {
  358. case kACCOUNTEMAIL: //email
  359. #ifdef kALLOWEMAIL
  360. [insertTxtView showTextView];
  361. #endif
  362. break;
  363. case kACCOUNTBIRTHDAY: //birthday
  364. [selectBirthdayView show];
  365. break;
  366. case kACCOUNTPASSWORD: //password
  367. [self openLink:NSLocalizedString(@"SETTINGS_PASSWORD_CHANGE_LINK", @"")];
  368. break;
  369. case kACCOUNTCOUNTRY: //country
  370. [pickCountry show];
  371. break;
  372. default:
  373. break;
  374. }
  375. break;
  376. case 1:
  377. switch ([indexPath row]) {
  378. case 0:
  379. [self openLink:NSLocalizedString(@"SETTINGS_SUPPORT_FAQ_LINK", @"")];
  380. break;
  381. case 1:
  382. [self sendSupportMail];
  383. break;
  384. default:
  385. break;
  386. }
  387. break;
  388. case 2:
  389. switch ([indexPath row]) {
  390. case 0:
  391. [self openLink:NSLocalizedString(@"SETTINGS_SOME_FACEBOOK_FI", @"")];
  392. break;
  393. case 1:
  394. [self openLink:NSLocalizedString(@"SETTINGS_SOME_INSTAGRAM_FI", @"")];
  395. break;
  396. case 2:
  397. [self openLink:NSLocalizedString(@"SETTINGS_SOME_TWITTER_FI", @"")];
  398. break;
  399. default:
  400. break;
  401. }
  402. break;
  403. default:
  404. break;
  405. }
  406. }
  407. -(void)openLink:(NSString*)link
  408. {
  409. linkToBeOpen = [NSURL URLWithString:link];
  410. NSString *string = NSLocalizedString(@"GENERAL_WARNING_TITLE", @"");
  411. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:string
  412. message:NSLocalizedString(@"SETTINGS_CONFIRM_BROWSER", @"")
  413. delegate:self
  414. cancelButtonTitle:NSLocalizedString(@"GENERAL_CANCEL",@"")
  415. otherButtonTitles:NSLocalizedString(@"GENERAL_OK",@""),nil];
  416. [alert setTag:0];
  417. [alert show];
  418. }
  419. -(void)changePassword
  420. {
  421. NSString *string = NSLocalizedString(@"GENERAL_WARNING_TITLE", @"");
  422. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:string
  423. message:NSLocalizedString(@"SETTINGS_PASSWORD_CHANGE_CONFIRM", @"")
  424. delegate:self
  425. cancelButtonTitle:NSLocalizedString(@"GENERAL_CANCEL",@"")
  426. otherButtonTitles:NSLocalizedString(@"GENERAL_OK",@""),nil];
  427. [alert setTag:1];
  428. [alert show];
  429. }
  430. -(void)logout:(id)sender
  431. {
  432. NSString *string = NSLocalizedString(@"GENERAL_WARNING_TITLE", @"");
  433. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:string
  434. message:NSLocalizedString(@"SETTINGS_CONFIRM_LOGOUT", @"")
  435. delegate:self
  436. cancelButtonTitle:NSLocalizedString(@"GENERAL_CANCEL",@"")
  437. otherButtonTitles:NSLocalizedString(@"GENERAL_OK",@""),nil];
  438. [alert setTag:2];
  439. [alert show];
  440. }
  441. -(void)inactiveEmailPrompt
  442. {
  443. if ([[[wbUser sharedUser] activation_state] isEqualToString:@"NEW"]) {
  444. NSString *string = NSLocalizedString(@"GENERAL_WARNING_TITLE", @"");
  445. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:string
  446. message:[NSString stringWithFormat:NSLocalizedString(@"SETTINGS_EMAIL_NOT_ACTIVATED", @""),[[wbUser sharedUser] email]]
  447. delegate:self
  448. cancelButtonTitle:NSLocalizedString(@"SETTINGS_EMAIL_RESEND_ACTIVATION",@"")
  449. otherButtonTitles:NSLocalizedString(@"GENERAL_OK",@""),nil];
  450. [alert setTag:3];
  451. [alert show];
  452. }
  453. }
  454. -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  455. {
  456. if ([alertView tag] == 0) {
  457. if (buttonIndex == 1) {
  458. [[UIApplication sharedApplication] openURL:linkToBeOpen];
  459. }
  460. }
  461. if ([alertView tag] == 1) {
  462. }
  463. if ([alertView tag] == 2) {
  464. if (buttonIndex == 1) {
  465. [[wbAPI sharedAPI] logout];
  466. [kROOTVC performSelector:@selector(logout:) withObject:NULL];
  467. }
  468. }
  469. if ([alertView tag] == 3) {
  470. if (buttonIndex == 0) {
  471. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:NSLocalizedString(@"SETTINGS_RESEND_ACTIVATION_LINK", @"")]];
  472. }
  473. }
  474. }
  475. //////////////// mail stuff
  476. -(void)sendSupportMail
  477. {
  478. if ([MFMailComposeViewController canSendMail]) {
  479. mail = [[MFMailComposeViewController alloc] init];
  480. [mail setMailComposeDelegate:self];
  481. [mail setSubject:NSLocalizedString(@"SETTINGS_SUPPORT_MAIL_SUBJECT", @"")];
  482. [mail setMessageBody:[[wbData sharedData] supportMessage] isHTML:NO];
  483. [mail setToRecipients:@[NSLocalizedString(@"SETTINGS_SUPPORT_MAIL", @"")]];
  484. [kROOTVC presentViewController:mail animated:YES completion:NULL];
  485. } else {
  486. [[wbAPI sharedAPI] showErrorWithTxt:NSLocalizedString(@"SETTINGS_SUPPORT_MAIL_FAIL",@"")];
  487. }
  488. }
  489. - (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
  490. {
  491. switch (result) {
  492. case MFMailComposeResultSent:
  493. [[wbAPI sharedAPI] showNoteWithTxt:NSLocalizedString(@"SETTINGS_SUPPORT_MAIL_DONE",@"")];
  494. break;
  495. case MFMailComposeResultSaved:
  496. DNSLog(@"draft saved");
  497. break;
  498. case MFMailComposeResultCancelled:
  499. DNSLog(@"mail cancel");
  500. break;
  501. case MFMailComposeResultFailed:
  502. [[wbAPI sharedAPI] showErrorWithTxt:NSLocalizedString(@"SETTINGS_SUPPORT_MAIL_FAIL",@"")];
  503. break;
  504. default:
  505. [[wbAPI sharedAPI] showErrorWithTxt:NSLocalizedString(@"SETTINGS_SUPPORT_MAIL_FAIL",@"")];
  506. break;
  507. }
  508. [kROOTVC performSelector:@selector(closeCamera:) withObject:mail];
  509. }
  510. -(void)updateBirthday:(NSString*)bday
  511. {
  512. DCMSG(bday);
  513. if (![bday isEqualToString:[[wbUser sharedUser] birthday]]) {
  514. DMSG;
  515. NSDictionary *updateUserDetails = [NSDictionary dictionaryWithObjectsAndKeys:bday,@"birthday", nil];
  516. [[wbAPI sharedAPI] updateUserDetails:updateUserDetails];
  517. //[[wbUser sharedUser] updateUserData];
  518. [[wbUser sharedUser] setNewBirthday:bday];
  519. [selectBirthdayView setBirthday:bday];
  520. DMSG;
  521. [self beginUpdates];
  522. [self reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:1 inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];
  523. [self endUpdates];
  524. // [self reloadData];
  525. }
  526. [selectBirthdayView hide];
  527. kHIDEWAIT
  528. }
  529. -(void)newText:(NSString*)text //delegate method for insetTxtView
  530. {
  531. DCMSG(text);
  532. if (![text isEqualToString:[insertTxtView initialText]]) {
  533. NSBlockOperation *op = [NSBlockOperation blockOperationWithBlock:^(void){
  534. [[wbWaitView sharedWait] performSelectorOnMainThread:@selector(show) withObject:NULL waitUntilDone:YES];
  535. }];
  536. [op setCompletionBlock:^(void){
  537. [self performSelectorOnMainThread:@selector(updateTxt:) withObject:text waitUntilDone:YES];
  538. }];
  539. [op start];
  540. }
  541. }
  542. -(void)updateTxt:(NSString*)text
  543. {
  544. if ([[wbAPI sharedAPI] validateEmailWithString:text]) {
  545. NSDictionary *updateUserDetails = [NSDictionary dictionaryWithObjectsAndKeys:text,@"email", nil];
  546. [[wbAPI sharedAPI] updateUserEmail:updateUserDetails delegate:self];
  547. } else {
  548. [[wbAPI sharedAPI] showErrorWithTxt:NSLocalizedString(@"REGISTER_ERROR_BROKEN_EMAIL",@"")];
  549. [insertTxtView showTextView];
  550. kHIDEWAIT
  551. }
  552. }
  553. -(void)emailSetDone:(id)sender
  554. {
  555. DCMSG(sender);
  556. [insertTxtView setInitialText:[[wbUser sharedUser] email]];
  557. kHIDEWAIT
  558. [[wbAPI sharedAPI] showNoteWithTxt:[NSString stringWithFormat:NSLocalizedString(@"SETTINGS_EMAIL_CHANGE_DONE", @""),[[wbUser sharedUser] email]]];
  559. [self beginUpdates];
  560. [self reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:kACCOUNTEMAIL inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];
  561. [self endUpdates];
  562. }
  563. -(void)setSelectedCountry:(NSDictionary *)_selectedCountry
  564. {
  565. selectedCountry = _selectedCountry;
  566. [[wbUser sharedUser] setCountryDictionary:_selectedCountry];
  567. DCMSG(_selectedCountry);
  568. NSDictionary *updateUserDetails = [NSDictionary dictionaryWithObjectsAndKeys:[selectedCountry objectForKey:@"country"],@"country", nil];
  569. [[wbAPI sharedAPI] updateUserDetails:updateUserDetails];
  570. [[wbAPI sharedAPI] setCurrentCountry:selectedCountry];
  571. [self beginUpdates];
  572. [self reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:kACCOUNTCOUNTRY inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];
  573. [self endUpdates];
  574. [[wbData sharedData] performSelectorInBackground:@selector(getAllMissionFeeds) withObject:nil];
  575. [kROOTVC performSelector:@selector(loginOK)];
  576. }
  577. @end