| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142 |
- //
- // RAHomeViewController.m
- // Apex And Drivers
- //
- // Created by Jack on 2018/6/1.
- // Copyright © 2018年 USAI. All rights reserved.
- //
- #import "RAHomeViewController.h"
- //#import "RAOrderDetailViewController.h"
- #import "RAProgressHUD.h"
- //#import "ApexDriverUploadListVC.h"
- //#import "RAHomeMoreViewController.h"
- #import <UserNotifications/UserNotifications.h>
- //#import "UIScrollView+Empty.h"
- #import "RAEmptyView.h"
- #import "RAHomeHeaderView.h"
- //#import "RAMessageViewController.h"
- //#import "RASettingViewController.h"
- #import <CoreLocation/CoreLocation.h>
- //#import "RABadgeButton.h"
- #import "const.h"
- #import "RADataProvider.h"
- #import "RASingleton.h"
- //#import "ResultISFCell.h"
- #import "ResultCustomerCell.h"
- //#import "ResultACICell.h"
- //#import "ResultACEM1Cell.h"
- //#import "ResultBaseModel.h"
- //#import "ResultACIModel.h"
- //#import "ResulteManifestCell.h"
- //#import "ResulteManifestModel.h"
- //#import "ResultACEM1Model.h"
- //#import "ResultISFModel.h"
- #import "ResultCustomerModel.h"
- #import "ResultViewController.h"
- #import "HomeDashEmptyCell.h"
- #import "FunctionSettingViewController.h"
- #import "HomeDashISFCellP.h"
- #import "HomeDashISFModelP.h"
- #import "HomeDashACEM1CellP.h"
- #import "HomeDashACEM1ModelP.h"
- #import "HomeDashACICellP.h"
- #import "HomeDashACIModelP.h"
- #import "HomeDasheManifestCellP.h"
- #import "HomeDasheManifestModelP.h"
- #import "HomeDashISFCellE.h"
- #import "HomeDashISFModelE.h"
- #import "HomeDashACEM1CellE.h"
- #import "HomeDashACEM1ModelE.h"
- #import "HomeDashACICellE.h"
- #import "HomeDashACIModelE.h"
- #import "HomeDasheManifestCellE.h"
- #import "HomeDasheManifestModelE.h"
- #import "RAUtils.h"
- #import "TFNavigationController.h"
- @implementation RAHomeSectionModel
- - (instancetype)init {
- if (self = [super init]) {
-
- }
- return self;
- }
- - (void)setValue:(id)value forUndefinedKey:(NSString *)key {
-
- }
- - (void)setOrders:(NSArray *)orders {
-
- NSMutableArray *orderArr = [NSMutableArray array];
- for (int i = 0; i < orders.count; i++)
- {
- NSDictionary *item = [orders objectAtIndex:i];
-
-
- switch (self.type) {
- case DashResultTypeEmpty:
- {
-
- ResultBaseModel *model = [ResultBaseModel new];
- [model setValuesForKeysWithDictionary:item];
- model.type=self.type;
- [orderArr addObject:model];
- }
- break;
- case DashResultTypeACIPending:
- {
- HomeDashACIModelP *model = [HomeDashACIModelP new];
- [model setValuesForKeysWithDictionary:item];
- model.type=self.type;
- [orderArr addObject:model];
- }
- break;
- case DashResultTypeeManifestPending:
- {
- HomeDasheManifestModelP *model = [HomeDasheManifestModelP new];
- [model setValuesForKeysWithDictionary:item];
- model.type=self.type;
- [orderArr addObject:model];
- }
- break;
- case DashResultTypeISFPending:
- {
-
- HomeDashISFModelP *model = [HomeDashISFModelP new];
- [model setValuesForKeysWithDictionary:item];
- model.type=self.type;
- [orderArr addObject:model];
- // ResultISFModel *model = [ResultISFModel new];
- // [model setValuesForKeysWithDictionary:item];
- // [orderArr addObject:model];
- }
- break;
- case DashResultTypeACEM1Pending:
- {
- HomeDashACEM1ModelP *model = [HomeDashACEM1ModelP new];
- [model setValuesForKeysWithDictionary:item];
- model.type=self.type;
- [orderArr addObject:model];
- }
- break;
- case DashResultTypeACIError:
- {
- HomeDashACIModelE *model = [HomeDashACIModelE new];
- [model setValuesForKeysWithDictionary:item];
- model.type=self.type;
- [orderArr addObject:model];
- }
- break;
- case DashResultTypeeManifestError:
- {
- HomeDasheManifestModelE *model = [HomeDasheManifestModelE new];
- [model setValuesForKeysWithDictionary:item];
- model.type=self.type;
- [orderArr addObject:model];
- }
- break;
- case DashResultTypeISFError:
- {
-
- HomeDashISFModelE *model = [HomeDashISFModelE new];
- [model setValuesForKeysWithDictionary:item];
- model.type=self.type;
- [orderArr addObject:model];
- // ResultISFModel *model = [ResultISFModel new];
- // [model setValuesForKeysWithDictionary:item];
- // [orderArr addObject:model];
- }
- break;
- case DashResultTypeACEM1Error:
- {
- HomeDashACEM1ModelE *model = [HomeDashACEM1ModelE new];
- [model setValuesForKeysWithDictionary:item];
- model.type=self.type;
- [orderArr addObject:model];
- }
- break;
- // case ResultTypeCustomer:
- // {
- // ResultCustomerModel *model = [ResultCustomerModel new];
- // [model setValuesForKeysWithDictionary:item];
- // [orderArr addObject:model];
- // }
- // break;
- // case ApexResultTypeAirBooking: {
- // ApexResultAirBookingModel *model = [ApexResultAirBookingModel new];
- // [model setValuesForKeysWithDictionary:item];
- // [modelsArr addObject:model];
- // }
- // break;
- // case ApexResultTypeBLInfo: {
- // ApexResultBLInfoModel *model = [ApexResultBLInfoModel new];
- // [model setValuesForKeysWithDictionary:item];
- // [modelsArr addObject:model];
- // }
- // break;
- //// case ApexResultTypeAirAwbInfo: {
- //// ApexResultAirAwbInfoModel *model = [ApexResultAirAwbInfoModel new];
- //// [model setValuesForKeysWithDictionary:item];
- //// [modelsArr addObject:model];
- //// }
- //// break;
- // case ApexResultTypeContainer: {
- // ApexResultContainerModel *model = [ApexResultContainerModel new];
- // [model setValuesForKeysWithDictionary:item];
- // [modelsArr addObject:model];
- // }
- // break;
- // case ApexResultTypeDocument: {
- // ApexResultDocumentModel *model = [ApexResultDocumentModel new];
- // [model setValuesForKeysWithDictionary:item];
- // [modelsArr addObject:model];
- // }
- // break;
- default:
- break;
- }
-
- }
- if (orders.count==0)
- {
- // NSDictionary *order = [orders objectAtIndex:i];
- ResultBaseModel *dashModel = [ResultBaseModel new];
- // [dashModel setValuesForKeysWithDictionary:order];
- [orderArr addObject:dashModel];
- }
- // {
- //
- //
- //
- //
- // NSDictionary *order = [orders objectAtIndex:i];
- // ResultBaseModel *dashModel = [ResultBaseModel new];
- // [dashModel setValuesForKeysWithDictionary:order];
- // [orderArr addObject:dashModel];
- // }
- _orders = orderArr;
- }
- //- (void)setBackendFlagCount:(NSInteger)backendFlagCount {
- // _backendFlagCount = backendFlagCount;
- //
- // if (self.delegate && [self.delegate respondsToSelector:@selector(refreshUI)]) {
- // [self.delegate refreshUI];
- // }
- //}
- - (ResultBaseModel *)dashModelForIndex:(NSInteger)index {
- return [self.orders objectAtIndex:index];
- }
- - (NSInteger)ordersCount {
- return self.orders.count;
- }
- - (NSInteger)orderModelIndexForID:(NSString *)orderID {
-
- __block NSInteger curIndex = -1;;
- // [self.orders enumerateObjectsUsingBlock:^(DashboardModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- // if ([obj.orderID isEqualToString:orderID]) {
- // curIndex = idx;
- // return ;
- // }
- // }];
- return curIndex;
- }
- - (BOOL)hasMoreOrder {
- return self.totalCount > 0;
- }
- - (ResultBaseModel *)modelForOrder:(NSString *)orderId {
- if (!orderId) {
- return nil;
- }
- __block ResultBaseModel *model = nil;
- // [self.orders enumerateObjectsUsingBlock:^(DashboardModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- // if ([obj.orderID isEqualToString:orderId]) {
- // model = obj;
- // }
- // }];
- return model;
- }
- @end
- #pragma mark - View Controller
- @interface RAHomeViewController () <RAHomeHeaderDelegate>
- @property (nonatomic,strong) NSMutableArray <RAHomeSectionModel *> *sectionArray;
- @property (nonatomic,strong) NSIndexPath *currentIndexPath;
- @property (nonatomic,strong) UIRefreshControl *refreshControl;
- @property (nonatomic,assign) NSUInteger messageCount;///<未读消息数量
- @end
- @implementation RAHomeViewController
- + (instancetype)viewControllerFromStoryboard {
- RAHomeViewController *homeVC = [[UIStoryboard storyboardWithName:@"Home" bundle:nil] instantiateViewControllerWithIdentifier:[self storyboardID]];
- return homeVC;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.label_cache.text = NSLocalizedString(@"cache content", nil);
- [self.label_cache sizeToFit];
- self.label_cache.layer.borderColor=SecondaryColor.CGColor;
- self.label_cache.layer.borderWidth = 1.0f;
- self.label_cache.layer.cornerRadius = 5.0f;
- self.label_cache.layer.masksToBounds = YES;
-
-
- // [self checkActivation];
- [self checkPermission];
- [self clearNavigationbar];
- [self configureNavigationBar];
- [self configureTable];
- [self registNotification];
- // [self loadData];
- self.reloadFlag=true;
- [self checkActivation];
- }
- - (void) checkActivation
- {
- if(!RASingleton.sharedInstance.active)
- {
- NSString * msg=@"Our customer service will contact you to assist you complete the user activation.";
- // [RAUtils message_alert:msg title:@"Message" controller:self];
-
-
- [RAUtils message_box:@"Message" message:msg completion:^{
- }];
- }
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
-
- [self.headerView reloadUI];
-
- [self clearNavigationbar];
- [self configureNavigationBar];
- }
- - (void)viewDidAppear:(BOOL)animated {
- [super viewDidAppear:animated];
-
- if (self.reloadFlag) {
- [self loadData];
- self.reloadFlag = !self.reloadFlag;
- }
- }
- - (void)dealloc {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- #pragma mark - Configure
- - (void)configureTable {
-
- if (@available(iOS 11, *)) {
- self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- }
- // else {
- // self.automaticallyAdjustsScrollViewInsets = NO;
- // }
- self.tableView.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1];
- self.tableView.tableFooterView = [UIView new];
- self.tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
-
- UIRefreshControl *refresh = [[UIRefreshControl alloc] init];
- [refresh addTarget:self action:@selector(refreshControlValueChanged:) forControlEvents:UIControlEventValueChanged];
- [self.tableView addSubview:refresh];
- self.refreshControl = refresh;
-
- // self.homeOrderTableView.emptyDataViewManualsize = true;
- // empty
- // self.homeOrderTableView setempty
- // __weak typeof(self) weakSelf = self;
- // self.homeOrderTableView.emptyView = [RAEmptyView emptyViewWithTapBlk:^(id sender) {
- // [weakSelf loadData];
- // }];
-
- // Header
- self.headerView = [RAHomeHeaderView homeHeader];
- // self.headerView.onSetFunctions=^(void)
- // {
- // [self.tableView reloadData];
- // };
-
- __block typeof(self) blockself = self;
- self.headerView.onSetCompany=^(void)
- {
- [blockself loadData];
- };
- self.headerView.delegate = self;
- self.tableView.tableHeaderView = self.headerView;
-
-
- // self.emptyReloadview =[[UIView alloc] initWithFrame:CGRectMake(200, 200, 300, 300)];
- //// self.emptyReloadview.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
- //// [self.homeOrderTableView addSubview:self.emptyContentview];
- // [self.homeOrderTableView insertSubview:self.emptyReloadview atIndex:0];
- //
- // self.emptyReloadview.backgroundColor = [UIColor redColor];
- // self.emptyReloadview.hidden = NO;
- // [self.homeOrderTableView bringSubviewToFront:self.emptyReloadview];
- __weak typeof(self) weakSelf = self;
- RAEmptyView* ev = [RAEmptyView emptyViewWithTapBlk:^(id sender) {
- [weakSelf loadData];
-
- }];
- self.Reloadview = ev;
- [self.tableView addSubview:ev];
- // CGRect tvrect = self.homeOrderTableView.frame;
- // CGRect hvrect = self.homeOrderTableView.tableHeaderView.frame;
- ev.hidden = YES;
- // ev.translatesAutoresizingMaskIntoConstraints = false;
- // NSLayoutConstraint *centerYConstraint =
- // [NSLayoutConstraint constraintWithItem:ev
- // attribute:NSLayoutAttributeCenterY
- // relatedBy:NSLayoutRelationEqual
- // toItem:self.homeOrderTableView
- // attribute:NSLayoutAttributeCenterY
- // multiplier:1.0
- // constant:0.0];
- // [self.homeOrderTableView addConstraint:centerYConstraint];
- //
- ev.center = self.tableView.center;
-
-
- [self.tableView registerNib:[UINib nibWithNibName:@"HomeDashACICellP" bundle:nil] forCellReuseIdentifier:HomeDashACICellP.identifier];
-
- [self.tableView registerNib:[UINib nibWithNibName:@"HomeDashEmptyCell" bundle:nil] forCellReuseIdentifier:HomeDashEmptyCell.identifier];
- [self.tableView registerNib:[UINib nibWithNibName:@"HomeDasheManifestCellP" bundle:nil] forCellReuseIdentifier:HomeDasheManifestCellP.identifier];
- [self.tableView registerNib:[UINib nibWithNibName:@"HomeDashACEM1CellP" bundle:nil] forCellReuseIdentifier:HomeDashACEM1CellP.identifier];
- // [self.tableView registerNib:[UINib nibWithNibName:@"ResultCustomerCell" bundle:nil] forCellReuseIdentifier:ResultCustomerCell.identifier];
- // [self.tableView registerNib:[UINib nibWithNibName:@"ResultISFCell" bundle:nil] forCellReuseIdentifier:ResultISFCell.identifier];
- [self.tableView registerNib:[UINib nibWithNibName:@"HomeDashISFCellP" bundle:nil] forCellReuseIdentifier:HomeDashISFCellP.identifier];
-
- [self.tableView registerNib:[UINib nibWithNibName:@"HomeDashISFCellE" bundle:nil] forCellReuseIdentifier:HomeDashISFCellE.identifier];
- [self.tableView registerNib:[UINib nibWithNibName:@"HomeDashACICellE" bundle:nil] forCellReuseIdentifier:HomeDashACICellE.identifier];
- [self.tableView registerNib:[UINib nibWithNibName:@"HomeDasheManifestCellE" bundle:nil] forCellReuseIdentifier:HomeDasheManifestCellE.identifier];
- [self.tableView registerNib:[UINib nibWithNibName:@"HomeDashACEM1CellE" bundle:nil] forCellReuseIdentifier:HomeDashACEM1CellE.identifier];
-
-
- }
- - (void)updateViewConstraints
- {
- [super updateViewConstraints];
-
- //
- // //约束条件
- // //redview在垂直方向上距离边界为50
- // UIView* dv= self.emptyReloadview;
- // dv.translatesAutoresizingMaskIntoConstraints=NO;
- // NSLayoutConstraint *constraint1 = [NSLayoutConstraint constraintWithItem:dv attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.homeOrderTableView attribute:NSLayoutAttributeTop multiplier:1 constant:0];
- // NSLayoutConstraint *constraint2 = [NSLayoutConstraint constraintWithItem:dv attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.homeOrderTableView attribute:NSLayoutAttributeBottom multiplier:1 constant:0];
- //
- // NSLayoutConstraint *constraint3 = [NSLayoutConstraint constraintWithItem:dv attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.homeOrderTableView attribute:NSLayoutAttributeLeft multiplier:1 constant:0];
- //
- // NSLayoutConstraint *constraint4 = [NSLayoutConstraint constraintWithItem:dv attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.homeOrderTableView attribute:NSLayoutAttributeRight multiplier:1 constant:0];
- //
- // [self.homeOrderTableView addConstraint:constraint1];
- // [self.homeOrderTableView addConstraint:constraint2];
- // [self.homeOrderTableView addConstraint:constraint3];
- // [self.homeOrderTableView addConstraint:constraint4];
-
- }
- - (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 {
-
-
- // self.tabBarController.navigationItem.title = @"navigatiion title";
- UIImage *logo = [[UIImage imageNamed:@"navigate_logo"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
- // UIImage *logo = [[UIImage imageNamed:@"apexlogo-2"] imageWithRenderingMode:UIImageRenderingModeAutomatic];
- UIBarButtonItem *logoItem = [[UIBarButtonItem alloc] initWithImage:logo landscapeImagePhone:logo style:UIBarButtonItemStylePlain target:nil action:nil];
- // logoItem.enabled = NO;
- self.tabBarController.navigationItem.leftBarButtonItem = logoItem;
-
- // UIBarButtonItem *welcomeItem =[[UIBarButtonItem alloc] initWithTitle:[NSString stringWithFormat:@"Welcome: %@",RASingleton.sharedInstance.firstName] menu:nil];
-
- UIBarButtonItem *functionSettingItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"ic_setting"] style:UIBarButtonItemStylePlain target:self action:@selector(settingClick:)];
-
- // welcomeItem.enabled = NO;
- self.tabBarController.navigationItem.rightBarButtonItem =functionSettingItem;
-
-
- TFNavigationController* ranav= (TFNavigationController*)self.navigationController;
-
- [ranav setupColor];
- //
- // UIBarButtonItem *uploadListItem =[[UIBarButtonItem alloc] initWithTitle:[NSString stringWithFormat:@"Welcome: %@",RASingleton.sharedInstance.firstName] menu:nil];
- ////
- // self.tabBarController.navigationItem.rightBarButtonItem =uploadListItem;
-
- // uploadListItem= [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"action_setting"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
- // style:UIBarButtonItemStylePlain
- // target:self
- // action:@selector(uploadListItemClick:)];
- //
- // self.navigationItem.rightBarButtonItems = @[uploadListItem];
- // [[NSNotificationCenter defaultCenter] postNotificationName:RANotificationRequestUploadCount object:nil];
- //
- // self.title = [NSString stringWithFormat:@"Welcome: %@",RASingleton.sharedInstance.firstName];
- }
- - (void)settingClick:(id)sender {
- // self.presenter.dirty = YES;
- // NSString *module_name = [self.params objectForKey:@"module_name"];
- FunctionSettingViewController *ViewController = [[UIStoryboard storyboardWithName:@"Home" bundle:nil]
- instantiateViewControllerWithIdentifier:@"FunctionSettingViewController"];
- // ViewController.function_name = module_name;
- // ViewController.behavior = BEHAVIOR_RESULT;
- // ViewController.forNewResult = YES;
- // ViewController.maxDisplayCount = ResultMaxDispalyAdditionCount;
- // self.parent
- ViewController.onSave = ^(NSArray* functions){
- [self.headerView set_FunctionButtons:[functions mutableCopy]];
- // self.functionButtons =[functions mutableCopy];
- // [self.functionButtons addObject:@{@"name": @"...",@"icon": @"ic_more",@"type": @"panel_setting"}];
- [self.tableView reloadData];
- //+0.5);
-
- };
- [self.navigationController pushViewController:ViewController animated:YES];
- }
- - (void)registNotification {
-
-
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:RA_NOTIFICATION_LOGOUT object:nil];
- // [RASingleton.sharedInstance writeLog:[NSString stringWithFormat:@"%s",__func__]];
- // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveNewOrderNotification:) name:RANotificationHandleOrder object:nil];
- // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveReloadNotification:) name:RANotificationReloadHome object:nil];
- // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveCheckDetailNofitication:) name:RANotificationCheckDetail object:nil];
- // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveUploadFinishNotification:) name:RANotificationChangeUpload object:nil];
- }
- - (void)handleNotification:(NSNotification *)notification {
-
-
- // NSAssert(true, @"setup does not implement");
-
- // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
- if ([notification.name isEqualToString:RA_NOTIFICATION_LOGOUT]) {
-
- // [appDelegate Logout];
- // [(LoginViewController *)self.logoutbar.firstObject clear];
- self.reloadFlag = true;
-
-
- // [self.navigationController.navigationBar setHidden:true];
- //
- }
- }
- - (void)checkPermission {
-
- CLAuthorizationStatus locationAuthoriztionAstatus = [CLLocationManager authorizationStatus];
- [[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
-
- UNAuthorizationStatus notificationAuthorizationStatus = settings.authorizationStatus;
-
- BOOL enableLocation = locationAuthoriztionAstatus != kCLAuthorizationStatusRestricted && locationAuthoriztionAstatus != kCLAuthorizationStatusDenied;
- BOOL enableRemoteNotification = notificationAuthorizationStatus != UNAuthorizationStatusDenied;
-
- if (!enableLocation | !enableRemoteNotification) {
-
- NSMutableString *msg = [NSMutableString stringWithString:NSLocalizedString(@"you should open", nil)];
-
- if (!enableLocation) {
- [msg appendString:NSLocalizedString(@" location permissions", nil)];
- }
-
- if (!enableRemoteNotification) {
-
- if (!enableLocation) {
- [msg appendString:NSLocalizedString(@" and notification permissions", nil)];
- } else {
- [msg appendString:NSLocalizedString(@" notification permissions", nil)];
- }
- }
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
- UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Warning", nil) message:msg preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Ok", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-
- NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
- if ([[UIApplication sharedApplication] canOpenURL:url]) {
- // [[UIApplication sharedApplication] openURL:url];
-
- [[UIApplication sharedApplication] openURL:url options:@{UIApplicationOpenURLOptionUniversalLinksOnly : @NO} completionHandler:nil];
- }
- }];
-
- [alertVC addAction:okAction];
-
- [self presentViewController:alertVC animated:YES completion:nil];
-
- });
- }
- }];
-
- }
- #pragma mark - Private
- //- (void)_checkOrder:(NSString *)orderId {
- // if (orderId) {
- //
- // for (RAHomeSectionModel *section in self.sectionArray) {
- //
- // ResultBaseModel *model = [section modelForOrder:orderId];
- // dispatch_async(dispatch_get_main_queue(), ^{
- //
- //// if (model && model.backendFlag) {
- //// if (section.backendFlagCount > 0) {
- //// section.backendFlagCount = section.backendFlagCount - 1;
- //// }
- //// model.backendFlag = NO;
- //// self.messageCount = self.messageCount - 1;
- //// }
- // });
- // }
- //
- // }
- //}
- - (void)_updateUploadItem:(UIBarButtonItem *)item withUploadCount:(NSUInteger)count {
- item.tintColor = WhiteColor;
- // if (item) {
- //
- // if (count > 0) {
- // item.tintColor = UIColorFromRGB(0x299D4D);
- // } else {
- // item.tintColor = ApexDriverWhiteColor;
- // }
- // }
- }
- #pragma mark - Action
- - (void)uploadListItemClick:(UIBarButtonItem *)sender {
-
- // ApexDriverUploadListVC *vc = [ApexDriverUploadListVC viewControllerFromStoryboard];
- // [self.navigationController pushViewController:vc animated:YES];
- }
- - (void)logoutItemClick:(UIBarButtonItem *)sender {
-
- // // show progress
- // RAProgressHUD *hud = [RAProgressHUD showHUDOnView:self.view];
- //
- // dispatch_async(dispatch_get_global_queue(0, 0), ^{
- //
- // [RADataProvider logout];
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- //
- // // dismiss progress
- // [hud dismiss];
- //
- // [RASingleton.sharedInstance logout];
- // [[NSNotificationCenter defaultCenter] postNotificationName:RANotificationLogout object:nil];
- //
- // });
- //
- // });
- }
- - (void)refreshControlValueChanged:(UIRefreshControl *)refresh {
- self.currentIndexPath = nil;
- [self loadData];
- }
- #pragma mark - Setter
- - (void)setHeaderView:(RAHomeHeaderView *)headerView {
- _headerView = headerView;
- }
- - (void)setMessageCount:(NSUInteger)messageCount {
- _messageCount = messageCount;
- dispatch_async(dispatch_get_main_queue(), ^{
- self.headerView.existNewMessage = messageCount > 0;
- });
- }
- #pragma mark - Getter
- - (NSMutableArray *)sectionArray {
- if (!_sectionArray) {
- _sectionArray = [NSMutableArray array];
- }
- return _sectionArray;
- }
- - (RAHomeSectionModel *)modelForSection:(NSInteger)section {
- RAHomeSectionModel *sectionModel = [self.sectionArray objectAtIndex:section];
- return sectionModel;
- }
- - (NSUInteger)orderSectionCount {
-
- return self.sectionArray.count;
- }
- - (NSUInteger)orderCountForSection:(NSInteger)section {
- RAHomeSectionModel *sectionModel = [self.sectionArray objectAtIndex:section];
- return [sectionModel ordersCount];
- }
- - ( ResultBaseModel*)dashModelForIndexPath:(NSIndexPath *)indexPath {
- RAHomeSectionModel *sectionModel = [self.sectionArray objectAtIndex:indexPath.section];
- return [sectionModel dashModelForIndex:indexPath.row];
- }
- - (NSString *)titleForSection:(NSInteger)section {
- RAHomeSectionModel *sectionModel = [self.sectionArray objectAtIndex:section];
- return sectionModel.title;
- }
- - (BOOL)hasMoreOrderForSection:(NSInteger)section {
- RAHomeSectionModel *sectionModel = [self.sectionArray objectAtIndex:section];
- return [sectionModel hasMoreOrder];
- }
- //- (NSInteger)backendCountForSection:(NSInteger)section {
- // RAHomeSectionModel *sectionModel = [self.sectionArray objectAtIndex:section];
- // return sectionModel.backendFlagCount;
- //}
- #pragma mark - Set/Update
- //
- //- (void)setBackendFlagCount:(NSInteger)count forSection:(NSInteger)section {
- // RAHomeSectionModel *sectionModel = [self.sectionArray objectAtIndex:section];
- // sectionModel.backendFlagCount = count;
- //}
- //
- //- (void)decreaseBackendFlagCountForSection:(NSInteger)section {
- // RAHomeSectionModel *sectionModel = [self.sectionArray objectAtIndex:section];
- // NSInteger count = sectionModel.backendFlagCount;
- // sectionModel.backendFlagCount = --count;
- //}
- - (void)setHeaderDelegate:(id<RAHomeSectionModelDelegate>)delegate forSection:(NSInteger)section {
- RAHomeSectionModel *sectionModel = [self.sectionArray objectAtIndex:section];
- sectionModel.delegate = delegate;
- }
- #pragma mark - Data
- - (void)loadData {
- self.label_cache.hidden=true;
- if (self.loading) {
- return;
- }
- self.loading = YES;
-
- // [self.homeOrderTableView hideEmpty];
- self.Reloadview.hidden = true;
-
- // show progress
- RAProgressHUD *hud = [RAProgressHUD showHUDOnView:self.view];
-
-
- __weak typeof(self) weakSelf = self;
- [RADataProvider LoadHome:^(NSMutableDictionary *result) {
- NSDictionary *json = result;
- // DebugLog(result);
- // dismiss progress
- [hud dismiss];
- if (weakSelf.refreshControl.isRefreshing) {
- [weakSelf.refreshControl endRefreshing];
- }
-
- if (weakSelf) {
- __strong typeof(weakSelf) strongSelf = weakSelf;
-
- // header
- // BOOL driverAvailable = [[json objectForKey:@"driver_available"] boolValue];
- //// strongSelf.headerView.availabel = driverAvailable;
- // NSInteger newCount = [[json objectForKey:@"new_count"] integerValue];
- // NSInteger processingCount = [[json objectForKey:@"processing_count"] integerValue];
- // NSInteger finishCount = [[json objectForKey:@"finish_count"] integerValue];
- // NSInteger messageCount = [[json objectForKey:@"message_count"] integerValue];
-
- // strongSelf.headerView.NewOrderCount = newCount;
- // strongSelf.headerView.ProcessingOrderCount = processingCount;
- // strongSelf.headerView.FinishOrderCount = finishCount;
- // strongSelf.messageCount = messageCount;
-
- int result = [[json objectForKey:@"result"] intValue];
- if (result == RESULT_TRUE) {
-
- // int badge = [json[@"badge"] intValue];
- // [UIApplication sharedApplication].applicationIconBadgeNumber=badge;
-
- NSMutableDictionary* totaljson=json[@"total"];
-
- NSString* headertext = @"<center><font size=5 color=white><b>In 30 Days</b>";
- // NSString * htmlString = headertext;
- //
- // NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
- //
- //// UILabel * myLabel = [[UILabel alloc] initWithFrame:self.view.bounds]; myLabel.attributedText = attrStr;
- //
- // CGRect rect0=[attrStr boundingRectWithSize:self.headerView.labelTotal.frame.size options:nil context:nil];
- // CGRect rect1 = CGRectZero;
- // CGRect rect2 = CGRectZero;
- // CGRect rect3 = CGRectZero;
- // CGRect rect4 = CGRectZero;
- // CGRect rect5 = CGRectZero;
- if(totaljson[@"acem1"] !=nil)
- {
-
- NSString* acem1=[NSString stringWithFormat:@" ACE-M1: <font color=yellow>%d</font>",[totaljson[@"acem1"] intValue]];
- headertext=[headertext stringByAppendingString:acem1];
- // NSString * htmlString = acem1;
- //
- // NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
- //
- // // UILabel * myLabel = [[UILabel alloc] initWithFrame:self.view.bounds]; myLabel.attributedText = attrStr;
- //
- // rect1=[attrStr boundingRectWithSize:self.headerView.labelTotal.frame.size options:nil context:nil];
- }
- //
- if(totaljson[@"isf"]!=nil)
- {
-
- NSString* isf=[NSString stringWithFormat:@" ISF: <font color=yellow>%d</font>",[totaljson[@"isf"] intValue]];
- headertext=[headertext stringByAppendingString:isf];
- // NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
- //
- // // UILabel * myLabel = [[UILabel alloc] initWithFrame:self.view.bounds]; myLabel.attributedText = attrStr;
- //
- // rect2=[attrStr boundingRectWithSize:self.headerView.labelTotal.frame.size options:nil context:nil];
- }
- //
- if(totaljson[@"aci"]!=nil)
- {
-
- NSString* aci=[NSString stringWithFormat:@" ACI: <font color=yellow>%d</font>",[totaljson[@"aci"] intValue]];
-
- headertext=[headertext stringByAppendingString:aci];
- // NSString * htmlString = acem1;
- //
- // NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
- //
- // // UILabel * myLabel = [[UILabel alloc] initWithFrame:self.view.bounds]; myLabel.attributedText = attrStr;
- //
- // rect3=[attrStr boundingRectWithSize:self.headerView.labelTotal.frame.size options:nil context:nil];
- }
- //
-
-
- if(totaljson[@"emanifest"] !=nil)
- {
-
- NSString* eman=[NSString stringWithFormat:@" eManifest: <font color=yellow>%d</font>",[totaljson[@"emanifest"] intValue]];
- headertext=[headertext stringByAppendingString:eman];
- // NSString * htmlString = acem1;
- //
- // NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
- //
- // // UILabel * myLabel = [[UILabel alloc] initWithFrame:self.view.bounds]; myLabel.attributedText = attrStr;
- //
- // rect4=[attrStr boundingRectWithSize:self.headerView.labelTotal.frame.size options:nil context:nil];
- }
-
-
- headertext=[headertext stringByAppendingString:@"</font></center>"];
-
- // self.logLabel.text = [log stringByAppendingString:@"\n"];
- //
- // CGSize bestsize=[self.logLabel sizeThatFits:self.logLabel.frame.size];
-
-
- // NSString * htmlString1= [NSString stringWithFormat:@"<center><font size=5 color=white><b>This Month</b> ACE-M1: <font color=yellow>%d</font> ISF: <font color=yellow>%d</font> ACI: <font color=yellow>%d</font> eManifest: <font color=yellow>%d</font></font></center>",[totaljson[@"acem1"] intValue],[totaljson[@"isf"] intValue],[totaljson[@"aci"] intValue],[totaljson[@"emanifest"] intValue]];
- NSAttributedString * attrStr1 = [[NSAttributedString alloc]
- initWithData:[headertext dataUsingEncoding:NSUnicodeStringEncoding]
- options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType }
- documentAttributes:nil
- error:nil];
- self.headerView.labelTotal.attributedText=attrStr1;
-
- BOOL requiredLocation = [[json objectForKey:@"requiredLocation"] boolValue];
- [RASingleton sharedInstance].requiredBackgroundLocation = requiredLocation;
-
- NSArray *sectionArray = [json objectForKey:@"sections"];
-
- NSMutableArray *tmpSectionArr = [NSMutableArray array];
- strongSelf.currentIndexPath = nil;
-
- for (int i = 0; i < sectionArray.count; i++) {
- NSDictionary *section = [sectionArray objectAtIndex:i];
- RAHomeSectionModel *sectionModel = [RAHomeSectionModel new];
- sectionModel.section = i;
- sectionModel.type = [section[@"type"] intValue];
- [sectionModel setValuesForKeysWithDictionary:section];
- [tmpSectionArr addObject:sectionModel];
- if (strongSelf.currentOrderID.length > 0) {
- NSInteger idx = [sectionModel orderModelIndexForID:self.currentOrderID];
- if (idx > -1) {
- strongSelf.currentIndexPath = [NSIndexPath indexPathForRow:idx inSection:i];
- }
- }
- }
- strongSelf.sectionArray = tmpSectionArr;
- [strongSelf.tableView reloadData];
- if (strongSelf.currentIndexPath) {
- // [strongSelf.homeOrderTableView scrollToRowAtIndexPath:self.currentIndexPath atScrollPosition:UITableViewScrollPositionMiddle animated:NO];
- [strongSelf.tableView selectRowAtIndexPath:strongSelf.currentIndexPath animated:NO scrollPosition:UITableViewScrollPositionMiddle];
- } else {
-
- }
-
- if([json[@"iscache"] boolValue]==true)
- {
- self.label_cache.hidden=false;
- }
-
- } else {
-
- [strongSelf.sectionArray removeAllObjects];
- strongSelf.tableView.contentOffset = CGPointZero;
- [strongSelf.tableView reloadData];
-
- // process error
- NSString *msg = [json objectForKey:@"err_msg"];
- // [strongSelf showAlert:msg];
- [strongSelf showAlertTilte:NSLocalizedString(@"Warning", nil) message:msg];
- }
- }
-
- weakSelf.loading = NO;
-
- if (weakSelf.orderSectionCount == 0) {
- // [weakSelf.homeOrderTableView showEmpty];
- self.Reloadview.hidden = false;
- } else {
- // [weakSelf.homeOrderTableView hideEmpty];
- self.Reloadview.hidden = true;
- }
- }];
-
- }
- //
- //- (void)updateDriverAvailable:(BOOL)available {
- //
- // // show progress
- // RAProgressHUD *hud = [RAProgressHUD showHUDOnView:self.view];
- //
- // __weak typeof(self) weakSelf = self;
- // dispatch_async(dispatch_get_global_queue(0, 0), ^{
- //
- // NSDictionary *json = [RADataProvider updateDriverAvailable:available];
- // dispatch_async(dispatch_get_main_queue(), ^{
- //
- // [hud dismiss];
- //
- // int result = [[json objectForKey:@"result"] intValue];
- // if (result == RESULT_TRUE) {
- //
- // weakSelf.headerView.availabel = available;
- //
- // } else {
- //
- // NSString *msg = [json objectForKey:@"err_msg"];
- // [weakSelf showAlertTilte:NSLocalizedString(@"Warning", nil) message:msg];
- // }
- // });
- //
- // });
- //
- //}
- #pragma mark - Controller Action
- - (void)pushDetailViewControllerForModel:(ResultBaseModel *)model {
-
- // [self pushDetailViewControllerForOrderID:model.orderID type:model.status type2:model.order_type2 statusNo:model.status_no];
- }
- //- (void)pushDetailViewControllerForOrderID:(NSString *)orderID type:(NSInteger)type type2:(NSString *)type2 statusNo:(NSString *)statusNo {
- //
- // if (!orderID) {
- // return;
- // }
- // RAOrderDetailViewController *detailVC = [RAOrderDetailViewController viewControllerFromStoryboard];
- // detailVC.orderID = orderID;
- // detailVC.orderType = type;
- // detailVC.orderType2 = type2;
- // detailVC.status_no = statusNo;
- // [self.navigationController pushViewController:detailVC animated:YES];
- //}
- //- (void)showMoreControllerWithTitle:(NSString *)title Type:(RAOrderStatus)type {
- //
- //// RAHomeMoreViewController *homeMoreVC = [RAHomeMoreViewController viewControllerFromStoryboard];
- //// homeMoreVC.title = title;
- //// homeMoreVC.type = type;
- ////
- //// __weak typeof(self) weakSelf = self;
- //// homeMoreVC.backendFlagOrderClickBlk = ^{
- //// weakSelf.reloadFlag = YES;
- //// };
- ////
- //// [self.navigationController pushViewController:homeMoreVC animated:YES];
- //}
- - (void)showMoreOrderForSection:(NSInteger)section {
-
- RAHomeSectionModel *sectionModel = [self.sectionArray objectAtIndex:section];
-
- if(sectionModel.more ==nil)
- return;
-
- NSMutableDictionary* params = [[sectionModel.more valueForKey:@"param"] mutableCopy];
- [params setValue:[sectionModel.more valueForKey:@"sub_type"] forKey:@"sub_type"];
-
- // resultViewController.params =params;
- // [self.navigationController pushViewController:resultViewController animated:YES];
-
-
- // AMResultViewController *resultVC = [[AMResultViewController alloc] initWithNibName:@"Result" bundle:nil];
- // resultVC.params = params;
- // [self.navigationController pushViewController:resultVC animated:YES];
-
- ResultViewController *vc = [ResultViewController resultViewController:params];
- [self.navigationController pushViewController:vc animated:YES];
-
-
- // [self showMoreControllerWithTitle:sectionModel.title Type:sectionModel.type];
- }
- #pragma mark - Nofitication Selector
- //
- //- (void)receiveNewOrderNotification:(NSNotification *)notification {
- // [self loadData];
- //}
- //
- //- (void)receiveReloadNotification:(NSNotification *)notification {
- // [self loadData];
- //}
- //
- //- (void)receiveCheckDetailNofitication:(NSNotification *)notification {
- ////
- //// NSDictionary *userInfo = [notification userInfo];
- //// if (userInfo) {
- //// NSString *orderId = [userInfo objectForKey:@"order_id"];
- //// if (orderId) {
- //// [self _checkOrder:orderId];
- //// }
- //// }
- ////
- //}
- - (void)receiveUploadFinishNotification:(NSNotification *)notification {
-
- NSUInteger count = [notification.userInfo[@"upload_count"] integerValue];
- UIBarButtonItem *item = self.navigationItem.rightBarButtonItem;
- [self _updateUploadItem:item withUploadCount:count];
- }
- #pragma mark - Header Delegate
- - (void)signoutClick:(UIButton *)sender {
- [self logoutItemClick:nil];
- }
- //
- //- (void)settingClick:(UIButton *)sender {
- //// dispatch_async(dispatch_get_main_queue(), ^{
- //// RASettingViewController *settingVC = [RASettingViewController viewControllerFromStoryboard];
- //// [self.navigationController pushViewController:settingVC animated:YES];
- //// });
- //}
- //
- //- (void)availableClick:(UIButton *)sender {
- //
- // NSString *msg = [NSString localizedStringWithFormat:NSLocalizedString(@"are you sure to change status to %@", nil),self.headerView.availabel ? NSLocalizedString(@"Unavailable", nil) : NSLocalizedString(@"Available", nil)];
- // UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Warning", nil) message:msg preferredStyle:UIAlertControllerStyleAlert];
- //
- // UIAlertAction *yesAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"YES", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- // [self updateDriverAvailable:!self.headerView.availabel];
- // }];
- //
- // UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- //
- // }];
- //
- //
- // [alertVC addAction:cancelAction];
- // [alertVC addAction:yesAction];
- //
- // [self presentViewController:alertVC animated:YES completion:nil];
- //}
- //- (void)messageClick:(UIButton *)sender {
- // RAMessageViewController *messageVC = [RAMessageViewController viewControllerFromStoryboard];
- // [self.navigationController pushViewController:messageVC animated:YES];
- //}
- //- (void)newOrderClick:(id)sender {
- //
- //// [self showMoreControllerWithTitle:NSLocalizedString(@"New Order", nil) Type:RAOrderStatusNew];
- //}
- //
- //- (void)processingOrderClick:(id)sender {
- //
- //// [self showMoreControllerWithTitle:NSLocalizedString(@"Processing Order", nil) Type:RAOrderStatusProcessing];
- //}
- //
- //- (void)finishedOrderClick:(id)sender {
- //
- //// [self showMoreControllerWithTitle:NSLocalizedString(@"Finished Order", nil) Type:RAOrderStatusFinish];
- //}
- @end
|