DetailTabBarController.m 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. //
  2. // DetailTabBarController.m
  3. // Apex Mobile
  4. //
  5. // Created by Ray on 14-3-7.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "DetailTabBarController.h"
  9. @interface DetailTabBarController ()
  10. @end
  11. @implementation DetailTabBarController
  12. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  13. {
  14. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  15. if (self) {
  16. }
  17. return self;
  18. }
  19. -(id) init :(NSString*) function_name actions:(NSArray*)actions params:(NSMutableDictionary*)params
  20. {
  21. self = [super init];
  22. if (self) {
  23. DebugLog(@"DetailTabBarController init.................");
  24. // UITabBar *tabBar = self.tabBar;
  25. // [tabBar setTintColor:[UIColor redColor]];
  26. // [tabBar setTintColor:[UIColor colorWithRed:0.0
  27. // green:176.0/255.0
  28. // blue:226.0/255.0
  29. // alpha:1.0]];
  30. // tabBar.selectedImageTintColor = [UIColor clearColor];
  31. // UITabBarItem *item = [tabBar.items objectAtIndex:0];
  32. // NSString *homePath = [[NSBundle mainBundle] pathForResource:@"btn_home_highlight" ofType:@"png"];
  33. // if(item.tag == 1)
  34. // {
  35. // [item setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
  36. // [UIColor lightGrayColor], UITextAttributeTextColor, nil]
  37. // forState:UIControlStateNormal];
  38. // item.selectedImage = [UIImage imageWithContentsOfFile:homePath];
  39. // }
  40. self.actions = actions;
  41. self.function_name = function_name;
  42. self.params = params;
  43. NSString* title=@"";
  44. if([self.function_name isEqualToString:@"Ocean Booking"])
  45. title = @"Booking Detail";
  46. else if([self.function_name isEqualToString:@"Ocean B/L info."])
  47. title = @"B/L info. Detail";
  48. else if([self.function_name isEqualToString:@"Container detail"])
  49. title = @"Container Detail";
  50. else if([self.function_name isEqualToString:@"Download Document"])
  51. title = @"Document Detail";
  52. else if([self.function_name isEqualToString:@"Cargo Tracking"])
  53. title = @"Cargo Detail";
  54. self.navigationItem.title = title;
  55. NSMutableArray* controllers = [[NSMutableArray alloc]init];
  56. if(self.actions.count==1)
  57. self.tabBar.hidden = true;
  58. for(int i=0;i<self.actions.count;i++)
  59. {
  60. NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
  61. [params setValue:@"handset_search" forKey:@"action"];
  62. [params setValue:self.actions[i] forKey:@"action_type"];
  63. [params setValue:self.function_name forKey:@"module_name"];
  64. [params setValue:[self.params valueForKey:@"id"] forKey:@"id"];
  65. [params setValue:[self.params valueForKey:@"sessionid"] forKey:@"sessionid"];
  66. if([self.function_name isEqualToString:@"Cargo Tracking"])
  67. {
  68. if([[self.params valueForKey:@"criterion_type"] isEqualToString:@"0"])
  69. [params setValue:[self.params valueForKey:@"cargo_criterion"] forKey:@"hbol"];
  70. else
  71. [params setValue:[self.params valueForKey:@"cargo_criterion"] forKey:@"container_no"];
  72. }
  73. // testViewController * one = [[testViewController alloc] init];
  74. UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:[NSBundle mainBundle]];
  75. DetailPageViewController *one = [storyboard instantiateViewControllerWithIdentifier:@"DetailPageViewController"];
  76. // DetailPageViewController *one = [[DetailPageViewController alloc]init];
  77. one.function_name = self.function_name;
  78. one.params = params;
  79. [one setTitle:self.actions[i]];
  80. one.tabBarItem = [[UITabBarItem alloc] initWithTitle:self.actions[i] image:nil tag:i];//[[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:0];
  81. [one.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
  82. [UIFont systemFontOfSize:12.0], NSFontAttributeName, nil]
  83. forState:UIControlStateNormal];
  84. // one.tabBarItem set
  85. // [one.tabBarItem setSelectedImage:[UIImage imageNamed:@"tag-3.png"]];
  86. UIOffset offset;
  87. offset.horizontal = 0;
  88. offset.vertical = -15;
  89. [one.tabBarItem setTitlePositionAdjustment:offset];
  90. // one.tabBarItem set
  91. [controllers addObject:one];
  92. }
  93. self.viewControllers = controllers;
  94. UIImage* img = [UIImage imageNamed:@"test1.png"];
  95. UIImage * idimage=[img resizableImageWithCapInsets:UIEdgeInsetsMake(1.0f, 30.0f, 300.0f, 30.0f)];
  96. //tabBarController.tabBar.selectionIndicatorImage = idicImage;
  97. // [self.tabBar setTintColor:[UIColor redColor]];
  98. // [self.tabBar setItemSpacing:0];
  99. // [self.tabBar setBarTintColor:[UIColor greenColor]];
  100. // [self.tabBar setSelectedImageTintColor:[UIColor purpleColor]];
  101. self.tabBar.selectionIndicatorImage =idimage;
  102. // NSMutableArray* controllers = [[NSMutableArray alloc]init];
  103. //
  104. // for(int i=0;i<self.actions.count;i++)
  105. // {
  106. // DetailPageViewController *tab = [[DetailPageViewController alloc]init];
  107. // [tab setTitle:self.actions[i]];
  108. // tab.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:i];
  109. // [controllers addObject:tab];
  110. //
  111. // }
  112. // self.viewControllers = controllers;
  113. //
  114. // UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"asdfsadf" image:[UIImage imageNamed:@"first.png"] tag:1];
  115. // self.tabBarItem = item;
  116. }
  117. return self;
  118. }
  119. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  120. {
  121. if(buttonIndex!=alertView.cancelButtonIndex)
  122. {
  123. UITextField * txt=[alertView textFieldAtIndex:0];
  124. NSString* name = txt.text;
  125. NSString * actions = [self.actions componentsJoinedByString:@","];
  126. // NSString* param = [self.params description];
  127. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:self.params
  128. options:0
  129. error:nil];
  130. NSString* param = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  131. // NSData *myData = [NSKeyedArchiver archivedDataWithRootObject:self.params];
  132. //
  133. // NSString* param = [[NSString alloc] initWithData:myData
  134. // encoding:NSUTF8StringEncoding];
  135. ApexMobileAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
  136. NSString* user = appDelegate.user;
  137. sqlite3 *db =[ApexMobileDB get_db];
  138. [ApexMobileDB execSql: [NSString stringWithFormat: @"insert into favorites(params,name,module_name,user,action) values('%@','%@','%@','%@','%@')",param,name,self.function_name,user,actions] db:db];
  139. sqlite3_close(db);
  140. }
  141. }
  142. -(void)saveDetail:(UIBarButtonItem*)sender
  143. {
  144. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"alert_title_create_tag", nil) message:NSLocalizedString(@"alert_msg_savehint", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"cancel", nil) otherButtonTitles:NSLocalizedString(@"save", nil),nil];
  145. alert.alertViewStyle = UIAlertViewStylePlainTextInput;
  146. UITextField * txt = [[UITextField alloc] init];
  147. txt.backgroundColor = [UIColor yellowColor];
  148. txt.frame = CGRectMake(alert.center.x+65,alert.center.y+48, 150,23);
  149. // [alert addSubview:txt];
  150. [alert show];
  151. }
  152. - (void)viewDidLoad
  153. {
  154. [super viewDidLoad];
  155. UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"save", nil) style:UIBarButtonItemStylePlain target:self action:@selector(saveDetail:)];
  156. // saveButton.title = @"Save";
  157. self.navigationItem.rightBarButtonItem = saveButton;
  158. // self.navigationController.view.frame.size.height;
  159. // NSMutableArray * items = [[NSMutableArray alloc]init];
  160. // UIBarButtonItem *item1 = [[UIBarButtonItem alloc] init];
  161. // item1.title = @"item1";
  162. // item1.image = [UIImage imageNamed:@"rect_setting"];
  163. // UIBarButtonItem *item2 = [[UIBarButtonItem alloc] init];
  164. // item2.image = [UIImage imageNamed:@"rect_about"];
  165. // item2.title = @"item2";
  166. // [items addObject:item1];
  167. // [items addObject:item2];
  168. // self.navigationItem.rightBarButtonItems=items;
  169. // self.navigationItem.backBarButtonItem = backButton;
  170. }
  171. - (void)didReceiveMemoryWarning
  172. {
  173. [super didReceiveMemoryWarning];
  174. // Dispose of any resources that can be recreated.
  175. }
  176. @end