PageRenderTime 73ms CodeModel.GetById 44ms RepoModel.GetById 0ms app.codeStats 0ms

/Classes/ResultViewController.m

https://github.com/simplypavi/domainr-alpha
Objective C | 189 lines | 165 code | 24 blank | 0 comment | 74 complexity | b76c2f9b0404f7e072b20bb00d1e2780 MD5 | raw file
  1. #import "ResultViewController.h"
  2. #import "Result.h"
  3. @implementation ResultViewController
  4. @synthesize result;
  5. - (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation; {
  6. return interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown;
  7. }
  8. - (void)dealloc {
  9. Release(result);
  10. [super dealloc];
  11. }
  12. - (id)initWithResult:(Result *)newResult; {
  13. self = [super initWithStyle:UITableViewStyleGrouped];
  14. self.result = newResult;
  15. self.title = [newResult domainName];
  16. return self;
  17. }
  18. - (void)viewWillAppear:(BOOL)animated; {
  19. isGoingBack = YES;
  20. [self.navigationController setNavigationBarHidden:NO animated:YES];
  21. [super viewWillAppear:animated];
  22. }
  23. - (void)viewWillDisappear:(BOOL)animated; {
  24. if(isGoingBack) [self.navigationController setNavigationBarHidden:YES animated:YES];
  25. [super viewWillDisappear:animated];
  26. }
  27. - (void)viewDidLoad; {
  28. tldInfoOpen = toolsOpen = NO;
  29. [super viewDidLoad];
  30. }
  31. - (void)viewDidUnload; {
  32. }
  33. #pragma mark UITableView methods
  34. enum kSections {
  35. kRegisterSection = 0,
  36. kMailSection,
  37. kTLDSection,
  38. kToolSection
  39. };
  40. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; {
  41. return 4;
  42. }
  43. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section; {
  44. if(section == kRegisterSection) {
  45. return 1;
  46. }
  47. else if(section == kMailSection) {
  48. return 1;
  49. }
  50. else if(section == kTLDSection) {
  51. return 1;
  52. }
  53. else if(section == kToolSection) {
  54. if(toolsOpen) {
  55. if([result isResolvable]) {
  56. return 3;
  57. }
  58. return 2;
  59. }
  60. return 1;
  61. }
  62. return 0;
  63. }
  64. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; {
  65. id cell = nil;
  66. if(indexPath.section == kRegisterSection) {
  67. cell = (UITableViewCell *)[tableView cellForClass:[UITableViewCell class]];
  68. [cell setAccessoryType:UITableViewCellAccessoryDetailDisclosureButton];
  69. [[cell textLabel] setText:NSLocalizedString([result isResolvable] ? @"Is it for sale?" : @"Register",nil)];
  70. }
  71. else if(indexPath.section == kMailSection) {
  72. cell = (UITableViewCell *)[tableView cellForClass:[UITableViewCell class]];
  73. if(indexPath.row == 0) {
  74. [[cell textLabel] setText:NSLocalizedString(@"Save as Email",nil)];
  75. }
  76. }
  77. else if(indexPath.section == kTLDSection) {
  78. cell = (UITableViewCell *)[tableView cellForClass:[UITableViewCell class]];
  79. if(indexPath.row == 0) {
  80. [[cell textLabel] setText:NSLocalizedString(@"TLD Info",nil)];
  81. [cell setAccessoryType:UITableViewCellAccessoryNone];
  82. }
  83. if (tldInfoOpen) {
  84. if(indexPath.row == 1) {
  85. }
  86. }
  87. }
  88. else if(indexPath.section == kToolSection) {
  89. cell = (UITableViewCell *)[tableView cellForClass:[UITableViewCell class]];
  90. if(indexPath.row == 0) {
  91. [[cell textLabel] setText:NSLocalizedString(@"Tools",nil)];
  92. [cell setAccessoryType:UITableViewCellAccessoryNone];
  93. [cell setAccessoryView:[[[UIImageView alloc] initWithImage:toolsOpen ? [SDImage imageNamed:@"RevealDisclosureIndicatorUp.png"] : [SDImage imageNamed:@"RevealDisclosureIndicatorDown.png"]] autorelease]];
  94. [[cell textLabel] setTextColor:toolsOpen ? [UIColor grayColor] : [UIColor blackColor]];
  95. return cell;
  96. }
  97. else if([result isResolvable] && indexPath.row == 1) {
  98. [[cell textLabel] setText:NSLocalizedString(@"Visit Site (www)",nil)];
  99. [[cell textLabel] setTextColor:[UIColor blackColor]];
  100. [cell setAccessoryView:nil];
  101. [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
  102. }
  103. else if((![result isResolvable] && indexPath.row == 1) || indexPath.row == 2) {
  104. [[cell textLabel] setText:NSLocalizedString(@"WHOIS",nil)];
  105. [[cell textLabel] setTextColor:[UIColor blackColor]];
  106. [cell setAccessoryView:nil];
  107. [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
  108. }
  109. }
  110. return cell;
  111. }
  112. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath; {
  113. if(indexPath.section == kRegisterSection) {
  114. isGoingBack = NO;
  115. NSString *apiRegisterURL = [NSString stringWithFormat:@"http://domai.nr/api/register?domain=%@",result.domainName];
  116. WebViewController *webViewController = [[[WebViewController alloc] initWithAddress:apiRegisterURL] autorelease];
  117. [self.navigationController pushViewController:webViewController animated:YES];
  118. }
  119. else if(indexPath.section == kMailSection) {
  120. if(indexPath.row == 0) { //email
  121. [self displayComposerSheet];
  122. }
  123. }
  124. else if(indexPath.section == kTLDSection) { //tld info
  125. tldInfoOpen = !tldInfoOpen;
  126. }
  127. else if(indexPath.section == kToolSection) { //tools
  128. if(indexPath.row == 0) {
  129. toolsOpen = !toolsOpen;
  130. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  131. [tableView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationFade];
  132. }
  133. else if([result isResolvable] && indexPath.row == 1) {
  134. isGoingBack = NO;
  135. WebViewController *webViewController = [[[WebViewController alloc] initWithAddress:[NSString stringWithFormat:@"http://domai.nr/%@/www",result.domainName]] autorelease];
  136. [self.navigationController pushViewController:webViewController animated:YES];
  137. }
  138. else if((![result isResolvable] && indexPath.row == 1) || indexPath.row == 2) {
  139. isGoingBack = NO;
  140. WebViewController *webViewController = [[[WebViewController alloc] initWithAddress:[NSString stringWithFormat:@"http://domai.nr/%@/whois",result.domainName]] autorelease];
  141. [self.navigationController pushViewController:webViewController animated:YES];
  142. }
  143. }
  144. if(!(indexPath.section == kMailSection && indexPath.row == 0)) {
  145. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  146. }
  147. }
  148. #pragma mark -
  149. - (void)displayComposerSheet; {
  150. isGoingBack = NO;
  151. MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
  152. picker.mailComposeDelegate = self;
  153. [picker setToRecipients:nil];
  154. [picker setSubject:[NSString stringWithFormat:NSLocalizedString(@"Domainr saved domain: %@",nil),result.domainName]];
  155. NSString *emailBody = [NSString stringWithFormat:@"%@",@""];
  156. [picker setMessageBody:emailBody isHTML:NO];
  157. [self presentModalViewController:picker animated:YES];
  158. [picker release];
  159. }
  160. - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error; {
  161. [self becomeFirstResponder];
  162. isGoingBack = YES;
  163. [self dismissModalViewControllerAnimated:YES];
  164. }
  165. @end