// // ActiveViewController.m // RedAnt ERP Mobile // // Created by Ray on 12/15/15. // Copyright © 2015 United Software Applications, Inc. All rights reserved. // #import "ActiveViewController.h" #import "config.h" #import "AppDelegate.h" #import "RAConvertor.h" //#import "NotificationNameCenter.h" @interface ActiveViewController () @end @implementation ActiveViewController - (void)viewDidLoad { [super viewDidLoad]; #ifdef RA_NOTIFICATION [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(OnRefreshUI:) name:RA_NOTIFICATION_REFRESH_UI object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(OnReloadData:) name:RA_NOTIFICATION_RELOAD_DATA object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(OnClearData:) name:RA_NOTIFICATION_CLEAR_DATA object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(OnUpdatePrice:) name:RA_NOTIFICATION_UPDATE_PRICE object:nil]; self.notification_refreshLevel = NotificationRefreshLevelData; #else self.refresh_type = REFRESH_DATA; #endif // Do any additional setup after loading the view. } - (void)dealloc { [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; #ifdef RA_NOTIFICATION switch (self.notification_refreshLevel) { case NotificationRefreshLevelView: if([self respondsToSelector:@selector(refresh_ui)]) [self refresh_ui]; break; case NotificationRefreshLevelData: if([self respondsToSelector:@selector(reload_data)]) [self reload_data]; break; default: break; } #else UIApplication * app = [UIApplication sharedApplication]; AppDelegate *appDelegate = (AppDelegate *)[app delegate]; appDelegate.active_controller = self; switch (self.refresh_type) { case REFRESH_VIEW: [self reload_container_getdata:false]; break; case REFRESH_DATA: { [self reRefreshView]; [self reload_container_getdata:true]; } break; } #endif // [[self navigationController] setNavigationBarHidden:YES animated:NO]; } -(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { // UIApplication * app = [UIApplication sharedApplication]; // AppDelegate *appDelegate = (AppDelegate *)[app delegate]; // [appDelegate didRotated]; // UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation]; // if (UIInterfaceOrientationIsLandscape(orientation)|| UIInterfaceOrientationIsPortrait(orientation)) // { // self.orientation = orientation; // [self.collectionview.collectionViewLayout invalidateLayout]; // DebugLog(@"routed"); // } } - (void)reRefreshView { } -(void) logout { self.refresh_type=REFRESH_NONE; } -(void) showHidePrice { // [self reload_container_getdata:false]; } -(void) refresh_on_login { UIApplication * app = [UIApplication sharedApplication]; AppDelegate *appDelegate = (AppDelegate *)[app delegate]; if(self==appDelegate.active_controller) { [self reload_container_getdata:true]; } else self.refresh_type = REFRESH_DATA; } -(void) reload_container_getdata:(bool) update_data { self.refresh_type=REFRESH_NONE; } -(void)refresh_btn_click:(UILongPressGestureRecognizer*)gestureRecognizer { [self reload_container_getdata:true]; } /* #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. } */ #pragma mark - Support scanner -(void) OnUpdateDevicesList { } -(void) onDecodedData:(NSString*) value { } -(void) onErrorInfo:(NSString*) errorInfo { } -(void) onStatusChanged:(NSString*) status { } -(void) onLogUpdate { } #pragma mark - Notification - (void)OnUpdatePrice: (NSNotification *)notification { if(self.disable_refresh) return; NSDictionary* dict = [notification userInfo]; NSArray* arr= dict[@"receiver"]; //如果当前对象不在不是指定接收者,也不是广播通信,就返回。 if([arr indexOfObject:[self class_name]]==NSNotFound&& arr.count>0) return; //如果当前对象本身不支持此动作,则返回 if(![self respondsToSelector:@selector(refresh_price)]) return; //如果当前已有的处理层级更高(reload),则不处理,交给reload 处理。 if(self.notification_refreshLevel0) return; if(![self respondsToSelector:@selector(refresh_ui)]) return; if(self.notification_refreshLevel0) return; if(![self respondsToSelector:@selector(reload_data)]) return; if(self.notification_refreshLevel