| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- //
- // FavoritesViewController.m
- // Apex Mobile
- //
- // Created by Ray on 14-4-25.
- // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
- //
- #import "SavedDetailViewController.h"
- #import "RAConvertor.h"
- #import "RASingleton.h"
- #import "const.h"
- #import "DetailTabBarController.h"
- @interface SavedDetailViewController ()
- @end
- @implementation SavedDetailViewController
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
- // Custom initialization
- }
- return self;
- }
- - (BOOL)shouldAutorotate
- {
- return YES;
- }
- - (UIInterfaceOrientationMask)supportedInterfaceOrientations
- {
- return UIInterfaceOrientationMaskPortrait;
- }
- - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
- {
- return UIInterfaceOrientationPortrait;
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
-
- NSData* json_user =[NSData dataWithContentsOfFile:[docDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_%@.json",@"saved_detail",RASingleton.sharedInstance.user]]];
-
- NSMutableArray* array;
- if(json_user==nil)
- {
- array = [NSMutableArray new];
-
- }
- else
- {
- array = [[RAConvertor data2arr:json_user] mutableCopy] ;
- }
-
- self.data =array;
- [self.tableview reloadData];
- self.tableview.tableFooterView = [UIView new];
-
- UIBarButtonItem *clearItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"bar_clear"] imageWithRenderingMode:UIImageRenderingModeAutomatic] style:UIBarButtonItemStylePlain target:self action:@selector(clearClick:)];
-
- clearItem.tintColor = UIColor.whiteColor;
- self.navigationItem.rightBarButtonItem = clearItem;
- }
- -(void)viewWillAppear:(BOOL)animated
- {
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (void)clearClick:(id)sender {
-
-
-
-
- UIAlertController *alertVC = [UIAlertController alertControllerWithTitle: @"Warning"
- message: @"Are you sure to clear the list?"
- preferredStyle: UIAlertControllerStyleAlert];
- UIAlertAction *action_ok = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-
- [self.data removeAllObjects];
-
-
-
-
-
-
-
-
-
- NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
-
- NSData* json_user =[RAConvertor arr2data:self.data];
- bool result =[json_user writeToFile:[docDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_%@.json",@"saved_detail",RASingleton.sharedInstance.user]] atomically:true];
-
-
-
-
- [self.tableview reloadData];
-
- }];
- UIAlertAction *action_cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
-
- }];
- [alertVC addAction:action_ok];
- [alertVC addAction:action_cancel];
- [self presentViewController:alertVC animated:YES completion:nil];
-
-
-
- }
- /*
- #pragma mark - Navigation
-
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
- {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
-
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
-
- return self.data.count;
-
-
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- DebugLog(@"cellForRowAtIndexPath");
-
- NSString *CellIdentifier = @"cell_item_history";
- CellItemHistory *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- NSString* name = [self.data[indexPath.row] valueForKey:@"name"];
- NSString* create_time = [self.data[indexPath.row] valueForKey:@"current_date"];
- NSString* company_name = [self.data[indexPath.row] valueForKey:@"company_name"];
- NSString *module_name = [self.data[indexPath.row] valueForKey:@"module"];
- // Cargo Tracking
- NSString* type =@"";
- if ([module_name isEqualToString:@"isf"]) {
- type=@"ISF";
- cell.icon.image = [[UIImage imageNamed:@"flag_us"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
-
- } else if ([module_name isEqualToString:@"acem1"]) {
- type=@"ACE M1";
- cell.icon.image = [[UIImage imageNamed:@"flag_us"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
-
- } else if ([module_name isEqualToString:@"aci"]) {
- type=@"ACI";
- cell.icon.image = [[UIImage imageNamed:@"flag_ca"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
-
- } else if ([module_name isEqualToString:@"emanifest"]) {
- type=@"eManifest";
- cell.icon.image = [[UIImage imageNamed:@"flag_ca"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
-
- }
- else if ([module_name isEqualToString:@"customer"]) {
- type=@"Customer";
- cell.icon.image = [[UIImage imageNamed:@"ic_customer"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
-
- }
-
- cell.name.text = name;
- // [cell.name sizeToFit];
-
- cell.time.text =create_time;
- // [cell.time sizeToFit];
- cell.type.text =type;
- cell.company.text = company_name;
-
- // cell.imageView.image = [UIImage imageNamed:[self.toolsinfo[indexPath.row] valueForKey:@"img"]];
-
- return cell;
-
-
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
- // NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithDictionary:self.params copyItems:true];
-
-
-
- NSMutableDictionary* params = [self.data[indexPath.row] valueForKey:@"param"];
-
-
- NSString * str_actions =[self.data[indexPath.row] valueForKey:@"actions"];
- NSArray* actions = [str_actions componentsSeparatedByString:@","];
-
- NSString* function_name = [self.data[indexPath.row] valueForKey:@"module"];
-
- DetailTabBarController *detailViewController=[[DetailTabBarController alloc] init:function_name actions:actions params:params];
-
- // DetailTabBarController *detailViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"DetailTabBarController"];
- // detailViewController.function_name = self.function_name;
- // detailViewController.actions = self.actions;
- // detailViewController.params =params;
- [self.navigationController pushViewController:detailViewController animated:YES];
- }
- - (UITableViewCellEditingStyle)tableView:(UITableView *)tv editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- return UITableViewCellEditingStyleDelete;
- //不能是UITableViewCellEditingStyleNone
- }
- - (void)tableView:(UITableView *)tableView
- commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
-
-
-
- [self.data removeObjectAtIndex:indexPath.row];
-
-
-
-
-
- NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
-
- NSData* json_user =[RAConvertor arr2data:self.data];
- bool result =[json_user writeToFile:[docDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_%@.json",@"saved_detail",RASingleton.sharedInstance.user]] atomically:true];
-
-
-
- // sqlite3* db = [ApexMobileDB get_db];
- // NSString* sql = [NSString stringWithFormat:@"delete from favorites where _id=%@",[self.data.pagedata[indexPath.row] valueForKey:@"_id"]];
- // [ApexMobileDB execSql:sql db:db];
- // sqlite3_close(db);
- //
- // [self.data.pagedata removeObjectAtIndex:indexPath.row];
- [tableView reloadData];
-
- }
- @end
|