| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757 |
- //
- // HomeViewController.m
- // Apex Mobile
- //
- // Created by Ray on 25/01/2018.
- // Copyright © 2018 United Software Applications, Inc. All rights reserved.
- //
- #import "HomeViewController.h"
- #import "ShipingStatusCell.h"
- #import "ShipSearchController.h"
- #import "ApexMobileDB.h"
- #import "DetailTabBarController.h"
- #import "RAUtils.h"
- #import "KPICell.h"
- #import "KPITableCell.h"
- #import "AMResultViewController.h"
- #import <MapKit/MapKit.h>
- #define SHIP_CELL_IDENTIFIER @"ShippingStatusCell"
- #define KPI_CELL_IDENTIFIER @"KPITableCell"
- typedef enum {
- HomeModeRecent = 0,
- HomeModeKPI = 1
- } HomeMode;
- @interface HomeViewController () <UITableViewDelegate,UITableViewDataSource,UISearchBarDelegate,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,KPIDelegate>
- @property (strong, nonatomic) IBOutlet UISegmentedControl *segmentControl;
- @property (nonatomic,strong) IBOutlet UIView *ShipContainer;
- @property (nonatomic,strong) IBOutlet UIActivityIndicatorView *ShipLoading;
- @property (nonatomic,strong) IBOutlet UIButton *ShipNoDataBtn;
- @property (strong, nonatomic) IBOutlet UITableView *shipTableView;
- @property (strong, nonatomic) IBOutlet UISearchBar *shipSearchBar;
- @property (nonatomic,strong) NSMutableArray *shipArray;
- @property (nonatomic,strong) UIRefreshControl *refreshControl;
- @property (nonatomic,strong) IBOutlet UIView *KPIContainer;
- @property (nonatomic,strong) IBOutlet UIActivityIndicatorView *KPILoading;
- @property (nonatomic,strong) IBOutlet UIButton *KPINoDataBtn;
- @property (nonatomic,strong) IBOutlet UITableView *KPITableView;
- @property (nonatomic,strong) UIRefreshControl *KPIRefresh;
- @property (nonatomic,strong) NSMutableArray *KPIArray;
- @property (nonatomic,strong) NSArray *monthArray;
- @property (nonatomic,assign) HomeMode mode;///<
- @property (nonatomic,assign) NSInteger currentKPI;
- @property (nonatomic,strong) UIAlertController *progressDialog;
- @property (nonatomic,assign) BOOL recentRefresh;
- @property (nonatomic,assign) BOOL kpiRefresh;
- @property (nonatomic,strong) IBOutlet MKMapView *mapView;
- @end
- @implementation HomeViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- if (@available(iOS 11,*)) {
- self.shipTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- } else {
- self.automaticallyAdjustsScrollViewInsets = NO;
- }
- self.currentKPI = 1;
- self.segmentControl.tintColor = APGRAYCOLOR;
- self.recentRefresh = NO;
- self.kpiRefresh = NO;
-
- [self registNotification];
- [self configureTableView];
- self.shipSearchBar.delegate =self;
-
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(logout) name:APLogoutNotification object:nil];
-
- // self.loadIndicator.layer.cornerRadius = 5;
- // self.loadIndicator.layer.masksToBounds = YES;
- // self.loadIndicator.layer.borderColor = [UIColor colorWithRed:169 / 255.0 green:169 / 255.0 blue:169 / 255.0 alpha:1.0].CGColor;
- // self.loadIndicator.layer.borderWidth = 0.3f;
- // self.loadIndicator.color = [UIColor colorWithRed:43 / 255.0 green:43 / 255.0 blue:43 / 255.0 alpha:1.0];
- // self.loadIndicator.backgroundColor = [UIColor colorWithRed:255 / 255.0 green:255 / 255.0 blue:255 / 255.0 alpha:0.9];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
-
- [self clearNavigationbar];
- [self configureNavigationBar];
-
-
- if (self.mode == HomeModeRecent) {
- if (self.shipArray.count == 0 || self.recentRefresh) {
- [self loadData];
- }
- } else if (self.mode == HomeModeKPI) {
- if (self.KPIArray.count == 0 || self.kpiRefresh) {
- [self loadKPIData];
- } else {
- NSString *str = [NSString stringWithFormat:@"%ld / %ld",self.currentKPI,self.KPIArray.count];
- self.parentViewController.title = str;
- }
- }
-
- }
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
-
- self.parentViewController.title = nil;
- }
- - (void)clearNavigationbar {
- self.tabBarController.navigationItem.leftBarButtonItem = nil;
- self.tabBarController.navigationItem.leftBarButtonItems = nil;
- self.tabBarController.navigationItem.titleView = nil;
- self.tabBarController.navigationItem.title = nil;
- self.tabBarController.navigationItem.rightBarButtonItem = nil;
- self.tabBarController.navigationItem.rightBarButtonItems = nil;
- }
- - (void)configureNavigationBar {
-
- if (self.navigationController && !self.navigationController.isNavigationBarHidden) {
-
- UIImage *logo = [[UIImage imageNamed:@"apexlogo-2"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- if (appDelegate.personalmode) {
- logo = [[UIImage imageNamed:@"apexlogo-2p"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
- }
- UIBarButtonItem *logoItem = [[UIBarButtonItem alloc] initWithImage:logo landscapeImagePhone:logo style:UIBarButtonItemStylePlain target:self action:@selector(switchMode:)];
- logoItem.enabled = true;
- self.tabBarController.navigationItem.leftBarButtonItem = logoItem;
-
- UIBarButtonItem *searchItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"bar_search"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(searchItemClick:)];
- self.tabBarController.navigationItem.rightBarButtonItem = searchItem;
- }
- }
- - (void)configureTableView {
-
- CGFloat w = CGRectGetWidth(self.shipTableView.bounds);
- self.shipTableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, w, CGFLOAT_MIN)];
- self.shipTableView.tableFooterView = [UIView new];
-
- [self.shipTableView registerNib:[UINib nibWithNibName:@"ShippingStatusCell" bundle:nil] forCellReuseIdentifier:SHIP_CELL_IDENTIFIER];
- [self.shipTableView registerNib:[UINib nibWithNibName:@"KPITableCell" bundle:nil] forCellReuseIdentifier:KPI_CELL_IDENTIFIER];
-
-
- UIRefreshControl *refresh = [[UIRefreshControl alloc] init];
- refresh.attributedTitle = [[NSAttributedString alloc] initWithString:@"loading data..."];
- [refresh addTarget:self action:@selector(refreshControlValueChanged:) forControlEvents:UIControlEventValueChanged];
- [self.shipTableView addSubview:refresh];
- self.refreshControl = refresh;
-
-
- // KPI
-
- self.KPITableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, w, CGFLOAT_MIN)];
- self.KPITableView.tableFooterView = [UIView new];
-
- [self.KPITableView registerNib:[UINib nibWithNibName:@"KPITableCell" bundle:nil] forCellReuseIdentifier:KPI_CELL_IDENTIFIER];
-
-
- UIRefreshControl *KPIRefresh = [[UIRefreshControl alloc] init];
- KPIRefresh.attributedTitle = [[NSAttributedString alloc] initWithString:@"loading data..."];
- [KPIRefresh addTarget:self action:@selector(KPIRefreshControlValueChanged:) forControlEvents:UIControlEventValueChanged];
- [self.KPITableView addSubview:KPIRefresh];
- self.KPIRefresh = KPIRefresh;
- }
- - (void)registNotification {
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handlePersonModeChangeNotification:) name:APPersonModeChangeNotification object:nil];
- }
- - (void)logout {
- [self.shipArray removeAllObjects];
- [self.shipTableView reloadData];
-
- self.currentKPI = 1;
- self.monthArray = nil;
- [self.KPIArray removeAllObjects];
- [self.KPITableView reloadData];
- }
- - (void)handlePersonModeChangeNotification:(NSNotification *)notification {
- [self reloadContent];
- }
- - (void)postPersonModeChangeNotification {
- [[NSNotificationCenter defaultCenter] postNotificationName:APPersonModeChangeNotification object:nil];
- }
- - (void)dealloc {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- #pragma mark - Private
- - (UIAlertController *)progressDialog {
- if (!_progressDialog) {
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle: nil
- message: @"loading..."
- preferredStyle: UIAlertControllerStyleAlert];
-
-
-
- UIViewController *customVC = [[UIViewController alloc] init];
-
-
- UIActivityIndicatorView* spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
- // spinner.color = [UIColor redColor];
- [spinner startAnimating];
- [customVC.view addSubview:spinner];
-
- [customVC.view addConstraint:[NSLayoutConstraint
- constraintWithItem: spinner
- attribute:NSLayoutAttributeCenterX
- relatedBy:NSLayoutRelationEqual
- toItem:customVC.view
- attribute:NSLayoutAttributeCenterX
- multiplier:1.0f
- constant:0.0f]];
-
- [customVC.view addConstraint:[NSLayoutConstraint
- constraintWithItem: spinner
- attribute:NSLayoutAttributeCenterY
- relatedBy:NSLayoutRelationEqual
- toItem:customVC.view
- attribute:NSLayoutAttributeCenterY
- multiplier:1.0f
- constant:0.0f]];
-
-
- [alertController setValue:customVC forKey:@"contentViewController"];
- _progressDialog = alertController;
- }
- return _progressDialog;
- }
- - (void)showProgressDialog {
- [self presentViewController:self.progressDialog animated:true completion:nil];
- }
- - (void)dismissProgressDialog {
- [self.progressDialog dismissViewControllerAnimated:YES completion:nil];
- }
- #pragma mark - Load Data
- - (NSMutableArray *)shipArray {
- if (!_shipArray) {
- _shipArray = [NSMutableArray array];
- }
- return _shipArray;
- }
- - (NSMutableArray *)KPIArray {
- if (!_KPIArray) {
- _KPIArray = [NSMutableArray array];
- }
- return _KPIArray;
- }
- - (void)reloadContent {
- NSLog(@"Home Person Mode Change");
-
- self.recentRefresh = YES;
- self.kpiRefresh = YES;
- if (((UITabBarController *)self.parentViewController).selectedIndex == 0) {
- if (self.mode == HomeModeRecent) {
- [self loadData];
- } else {
- [self loadKPIData];
- }
- }
-
- }
- - (void)loadData {
- // NSString *path = [[NSBundle mainBundle] pathForResource:@"fake_container_list.json" ofType:nil];
- // NSData *data = [[NSData alloc] initWithContentsOfFile:path];
- //
- // NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
-
- // 避免重复刷新
- if (self.ShipLoading.isAnimating) {
- return;
- }
-
- [self.ShipLoading startAnimating];
-
- [self showProgressDialog];
-
- __weak typeof(self) weakSelf = self;
- dispatch_async(dispatch_get_global_queue(0, 0), ^{
-
- NSDictionary *json = [RANetwork requestHome];
-
- // NSData *data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"fake_home.json" ofType:nil]];
- // NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
- if (self.refreshControl.isRefreshing) {
- [self.refreshControl endRefreshing];
- }
-
- [self.ShipLoading stopAnimating];
-
- [weakSelf dismissProgressDialog];
-
- int result = [[json objectForKey:@"result"] intValue];
- if (result == RESULT_TRUE) {
-
- [self.shipArray removeAllObjects];
- [self.shipArray addObjectsFromArray:[json objectForKey:@"container_list"]];
- [self.shipTableView reloadData];
-
- } else {
- NSString *msg = [json objectForKey:@"err_msg"];
- [RAUtils message_alert:msg title:@"Warning" controller:weakSelf];
- }
- self.ShipNoDataBtn.hidden = self.shipArray.count > 0;
- if (self.shipArray.count) {
- [self.shipTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];
- }
- weakSelf.recentRefresh = NO;
- });
-
- });
- }
- - (void)loadKPIData {
-
- if (self.KPILoading.isAnimating) {
- return;
- }
-
- [self.KPILoading startAnimating];
- [self showProgressDialog];
-
- __weak typeof(self) weakSelf = self;
- dispatch_async(dispatch_get_global_queue(0, 0), ^{
-
- NSDictionary *json = [RANetwork requestKPI];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
- if (weakSelf.KPIRefresh.isRefreshing) {
- [weakSelf.KPIRefresh endRefreshing];
- }
-
- [weakSelf.KPILoading stopAnimating];
-
- [weakSelf dismissProgressDialog];
-
- int result = [[json objectForKey:@"result"] intValue];
- if (result == RESULT_TRUE) {
- // self.currentKPI = 1;
- weakSelf.monthArray = [json objectForKey:@"month"];
-
- [weakSelf.KPIArray removeAllObjects];
- NSArray *kpiArr = [json objectForKey:@"KPI"];
- // [self.KPIArray addObject:[[kpiArr firstObject] mutableCopy]];
- for (int i = 0; i < kpiArr.count; i++) {
- NSMutableDictionary *kpiModel = [[kpiArr objectAtIndex:i] mutableCopy];
- NSMutableArray *itemMutArr = [NSMutableArray array];
- NSArray *itemArr = [kpiModel objectForKey:@"arr_val"];
- for (int j = 0; j < itemArr.count; j++) {
- NSMutableDictionary *item = [[itemArr objectAtIndex:j] mutableCopy];
- [itemMutArr addObject:item];
- }
- [kpiModel setObject:itemMutArr forKey:@"arr_val"];
-
- // [self.KPIArray addObjectsFromArray:kpiArr];
- [weakSelf.KPIArray addObject:kpiModel];
- }
- // [self.KPIArray addObject:[[kpiArr lastObject] mutableCopy]];
-
-
- [weakSelf.KPITableView reloadData];
-
- if (((UITabBarController *)weakSelf.parentViewController).selectedIndex == 0) {
- NSString *str = [NSString stringWithFormat:@"%ld / %ld",self.currentKPI,self.KPIArray.count];
- weakSelf.parentViewController.title = str;
- }
-
- } else {
- NSString *msg = [json objectForKey:@"err_msg"];
- [RAUtils message_alert:msg title:@"Warning" controller:weakSelf];
- }
- weakSelf.KPINoDataBtn.hidden = self.KPIArray.count > 0;
- weakSelf.kpiRefresh = NO;
- });
-
- });
-
- }
- #pragma mark - Actinon
- - (void)refreshControlValueChanged:(UIRefreshControl *)refresh {
- [self loadData];
- }
- - (void)KPIRefreshControlValueChanged:(UIRefreshControl *)refresh {
- [self loadKPIData];
- }
- - (void)searchItemClick:(id)sender {
-
- ShipSearchController *searchVC = [ShipSearchController build];
-
- [self.navigationController pushViewController:searchVC animated:YES];
-
- }
- - (IBAction)modeSegmentClick:(UISegmentedControl *)sender {
-
- if (sender.selectedSegmentIndex == 1) {
- self.mode = HomeModeKPI;
- self.ShipContainer.hidden = YES;
- self.KPIContainer.hidden = NO;
-
- if (self.KPIArray.count == 0 || self.kpiRefresh) {
- [self loadKPIData];
- } else {
- NSString *str = [NSString stringWithFormat:@"%ld / %ld",self.currentKPI,self.KPIArray.count];
- self.parentViewController.title = str;
- }
-
-
- } else {
- self.mode = HomeModeRecent;
- self.KPIContainer.hidden = YES;
- self.ShipContainer.hidden = NO;
- self.parentViewController.title = nil;
- if (self.shipArray.count == 0 || self.recentRefresh) {
- [self loadData];
- }
- }
-
-
- [self.shipTableView reloadData];
- }
- - (void)switchMode:(id)sender {
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- appDelegate.personalmode = ! appDelegate.personalmode;
-
- NSString* msg = @"";
- if(appDelegate.personalmode)
- {
- msg=@"Personal Mode On.";
- self.tabBarController.navigationItem.leftBarButtonItem.image = [[UIImage imageNamed:@"apexlogo-2p"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
- }
- else
- {
- msg=@"Personal Mode Off.";
- self.tabBarController.navigationItem.leftBarButtonItem.image = [[UIImage imageNamed:@"apexlogo-2"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
- }
-
-
- [self postPersonModeChangeNotification];
- // [RAUtils alert_view:msg title:@"Personal Mode"];
- }
- - (IBAction)ShipNoDataBtnClick:(UIButton *)sender {
- [self loadData];
- }
- - (IBAction)KPINoDataBtnClick:(UIButton *)sender {
- [self loadKPIData];
- }
- #pragma mark - TableView DataSource && Delegate
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- if (self.shipTableView == tableView) {
- return self.shipArray.count;
- } else {
- return 1;
- }
-
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return 1;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- if (self.shipTableView == tableView) {
- ShipingStatusCell *cell = [tableView dequeueReusableCellWithIdentifier:SHIP_CELL_IDENTIFIER forIndexPath:indexPath];
-
- NSDictionary *item = [self.shipArray objectAtIndex:indexPath.section];
-
- NSString *title = [item objectForKey:@"title"];
- NSString *icon = [item objectForKey:@"icon"];
- NSString *desc = [item objectForKey:@"description"];
- NSString *detail = [item objectForKey:@"detail"];
- NSString *date = [item objectForKey:@"date"];
- NSString *port = [item objectForKey:@"port"];
- NSInteger stage = [[item objectForKey:@"transport_stage"] integerValue];
-
- [[[[[[[cell setTitle:title] setDescription:desc] setDetail:detail] setPort:port] setTime:date] setIcon:icon] setTransportStage:stage];
-
- return cell;
- } else {
-
- KPITableCell *kpiCell = [tableView dequeueReusableCellWithIdentifier:KPI_CELL_IDENTIFIER forIndexPath:indexPath];
- kpiCell.KPICollectionView.dataSource = self;
- kpiCell.KPICollectionView.delegate = self;
- [kpiCell.KPICollectionView reloadData];
- if (self.KPIArray.count) {
- [kpiCell.KPICollectionView setContentOffset:CGPointMake(self.currentKPI * kpiCell.KPICollectionView.bounds.size.width, 0) animated:NO];
- }
- return kpiCell;
- }
-
- }
- //- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
- // CGFloat w = CGRectGetWidth(tableView.bounds);
- //
- // UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, w, 30)];
- // header.backgroundColor = [UIColor lightGrayColor];
- //
- // UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, w - 10 * 2, 20)];
- // label.textColor = [UIColor whiteColor];
- // label.text = @"Recently";
- //
- // [header addSubview:label];
- // return header;
- //}
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- if (self.shipTableView != tableView) {
- return 0.f;
- }
- return 10;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
- return 0.001;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
- if (self.shipTableView != tableView) {
- return tableView.bounds.size.height;
- }
- return 110;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
-
- if (self.shipTableView != tableView) {
- return;
- }
-
- NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
- // [params setObject:@"dumb" forKey:@"id"];
- NSString* h_field;
- //if(self.radioContainer.selected==true)
- //{
- // [params setObject:@"1" forKey:@"criterion_type"];
- // h_field = @"ctnr";
- //}
- //else
- {
- [params setObject:@"0" forKey:@"criterion_type"];
- h_field = @"h_bol";
- }
-
- NSDictionary *item = [self.shipArray objectAtIndex:indexPath.section];
- NSString * cargo_criterion = item[@"hbol"];
- NSString *serial_no = item[@"serial_no"];
- if(cargo_criterion==nil)
- cargo_criterion=@"";
- [params setObject:cargo_criterion forKey:@"cargo_criterion"];
- if (serial_no != nil) {
- [params setObject:serial_no forKey:@"serial_no"];
- [params setObject:serial_no forKey:@"id"];
- }
- [ApexMobileDB savehistory:h_field value:cargo_criterion];
- DetailTabBarController *detailViewController=[[DetailTabBarController alloc] init:@"Cargo Tracking" actions:[NSArray arrayWithObjects:@"Tracking",nil] params:params];
- [self.navigationController pushViewController:detailViewController animated:YES];
-
- }
- //#pragma mark - SearchBar Delegate
- //
- //- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {
- //
- // ShipSearchController *searchVC = [ShipSearchController build];
- //
- // UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:searchVC];
- //
- // [self presentViewController:nav animated:YES completion:nil];
- //
- // return NO;
- //}
- #pragma mark - CollectionView DataSource & Delegate
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
- return 1;
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- if (self.KPIArray && self.KPIArray.count > 0) {
- return self.KPIArray.count + 2;
- }
- return 0;
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
-
- KPICell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"KPICell" forIndexPath:indexPath];
-
- NSInteger index = indexPath.item;
- if (indexPath.item == 0) {
- index = self.KPIArray.count - 1;
- } else if (indexPath.item == self.KPIArray.count + 1) {
- index = 0;
- } else {
- index = indexPath.item - 1;
- }
-
- NSMutableDictionary *item = [self.KPIArray objectAtIndex:index];
- [item setObject:self.monthArray forKey:@"month"];
- [cell setInfoDic:item];
- cell.delegate = self;
- return cell;
- }
- #pragma mark - KPICell Delegate
- - (void)KPICell:(KPICell *)cell repeatClickLegendAtIndex:(NSInteger)index withItem:(NSDictionary *)item {
- NSLog(@"double clicked %ld",index);
- /**
- s_kpi = true;
- name = kpi name
- sector = sector title
- module_name = module_name
- */
- NSArray * itemsArr = item[@"arr_val"];
- NSMutableDictionary* legend = [itemsArr objectAtIndex:index];
-
- NSString *kpi_name = [item objectForKey:@"name"];
- NSString *sector = [legend objectForKey:@"full_title"];
- NSString *module_name = [item objectForKey:@"module_name"];
- if (kpi_name == nil) {
- kpi_name = @"";
- }
- if (sector == nil) {
- sector = @"";
- }
- if (module_name == nil) {
- module_name = @"";
- }
-
-
- NSMutableDictionary *params = [@{
- @"is_kpi" : @(YES),
- @"name" : kpi_name,
- @"sector": sector,
- @"module_name" : module_name
- } mutableCopy];
-
- AMResultViewController *resultVC = [[AMResultViewController alloc] initWithNibName:@"Result" bundle:nil];
- resultVC.params = params;
- [self.navigationController pushViewController:resultVC animated:YES];
- }
- #pragma mark - FlowLayout Delegate
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
- return collectionView.bounds.size;
- }
- - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
- return 0.0f;
- }
- - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
- return 0.0f;
- }
- #pragma mark - ScrollViewDelegate
- - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
- if (scrollView != self.shipTableView && [scrollView isKindOfClass:[UICollectionView class]]) {
- UICollectionView *collectionView = (UICollectionView *)scrollView;
- CGFloat w = scrollView.bounds.size.width;
- CGFloat offsetX = scrollView.contentOffset.x;
- float f = floorf(offsetX / w);
- NSInteger index = floorf(f + 0.5);
- NSInteger cur = index;
- if (index == 0) {
- cur = self.KPIArray.count;
- [collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:cur inSection:0] atScrollPosition:UICollectionViewScrollPositionNone animated:NO];
- } else if (index == self.KPIArray.count + 1) {
- cur = 1;
- [collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:cur inSection:0] atScrollPosition:UICollectionViewScrollPositionNone animated:NO];
- } else {
- cur = index;
- }
- }
- }
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
- if (scrollView != self.shipTableView && [scrollView isKindOfClass:[UICollectionView class]]) {
- // UICollectionView *collectionView = (UICollectionView *)scrollView;
- CGFloat w = scrollView.bounds.size.width;
- CGFloat offsetX = scrollView.contentOffset.x;
- float f = floorf(offsetX / w);
- NSInteger index = floorf(f + 0.5);
- NSInteger cur = index;
- if (index == 0) {
- cur = self.KPIArray.count;
- } else if (index == self.KPIArray.count + 1) {
- cur = 1;
- } else {
- cur = index;
- }
- self.currentKPI = cur;
- if (self.currentKPI > 0) {
- NSString *str = [NSString stringWithFormat:@"%ld / %ld",self.currentKPI,self.KPIArray.count];
- self.parentViewController.title = str;
- } else {
- self.currentKPI = 1;
- }
- }
- }
- @end
|