| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431 |
- //
- // 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)routerEvent:(NSString*)event Info:(id)info
- {
- return;
-
- // if([event isEqualToString:@"RA_NOTIFICATION_RELEASE_SCANNER"])
- // {
- // if(self.support_scanner)
- // {
- // int a=0;
- //#ifdef RA_NOTIFICATION
- // UIApplication * app = [UIApplication sharedApplication];
- // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- //
- // if(self.support_scanner)
- // {
- // appDelegate.eventsFeedback = self;
- // }
- //#endif
- // }
- // else
- // [super routerEvent:event Info:info];
- // }
- // else
- // [super routerEvent:event Info:info];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- // [self becomeFirstResponder];
-
- #ifdef RA_NOTIFICATION
- self.support_scanner = false;
- [[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)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
- //{
- //#ifdef RA_NOTIFICATION
- // UIApplication * app = [UIApplication sharedApplication];
- // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- //
- // if(self.support_scanner)
- // {
- // [appDelegate setFeedback:self];
- // // appDelegate.eventsFeedback = self;
- // }
- //#endif
- // return [super touchesBegan:touches withEvent:event];
- //}
- //- (BOOL)becomeFirstResponder
- //{
- //#ifdef RA_NOTIFICATION
- // UIApplication * app = [UIApplication sharedApplication];
- // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- //
- // if(self.support_scanner)
- // {
- // [appDelegate setFeedback:self];
- // // appDelegate.eventsFeedback = self;
- // }
- //#endif
- // return [super becomeFirstResponder];
- //}
- -(void)viewDidAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- #ifdef RA_NOTIFICATION
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-
- if(self.support_scanner)
- {
- [appDelegate pushFeedback:self];
- // appDelegate.eventsFeedback = self;
- }
- #endif
- }
- -(void)viewDidDisappear:(BOOL)animated
- {
- #ifdef RA_NOTIFICATION
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- if(self.support_scanner)
- {
- [appDelegate popFeedback:self];
- // appDelegate.eventsFeedback = self;
- }
- [super routerEvent:RA_NOTIFICATION_RELEASE_SCANNER Info:nil];
- #endif
- [super viewDidDisappear:animated];
- }
- - (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];
- self.notification_refreshLevel = NotificationRefreshLevelNone;
-
- }
- break;
- case NotificationRefreshLevelData:
- if([self respondsToSelector:@selector(reload_data)])
- {
- [self reload_data];
- self.notification_refreshLevel = NotificationRefreshLevelNone;
- }
- 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];
- #ifndef RA_NOTIFICATION
- if(self==appDelegate.active_controller)
- {
- [self reload_container_getdata:true];
- }
- else
- self.refresh_type = REFRESH_DATA;
- #endif
- }
- -(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_refreshLevel<NotificationRefreshLevelView)
- {
- if([self isVisible])
- {
- [self refresh_price];
- self.notification_refreshLevel = NotificationRefreshLevelNone;
- }
- else
- {
- self.notification_refreshLevel = NotificationRefreshLevelView;
- }
- }
-
- }
- - (void)OnRefreshUI: (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_ui)])
- return;
-
- if(self.notification_refreshLevel<NotificationRefreshLevelView)
- {
- if([self isVisible])
- {
- [self refresh_ui];
- self.notification_refreshLevel = NotificationRefreshLevelNone;
- }
- else
- {
- self.notification_refreshLevel = NotificationRefreshLevelView;
- }
- }
- }
- - (void)OnReloadData: (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(reload_data)])
- return;
- if(self.notification_refreshLevel<NotificationRefreshLevelData)
- {
- if([self isVisible])
- {
- [self reload_data];
- self.notification_refreshLevel = NotificationRefreshLevelNone;
- }
- else
- {
- self.notification_refreshLevel = NotificationRefreshLevelData;
- }
- }
-
- }
- - (void)OnClearData: (NSNotification *)notification
- {
- if(![self respondsToSelector:@selector(clear_data)])
- return;
- if([self isVisible])
- {
- if([self respondsToSelector:@selector(clear_data)])
- {
- [self clear_data];
- if([self respondsToSelector:@selector(refresh_ui)])
- {
- [self refresh_ui];
- self.notification_refreshLevel = NotificationRefreshLevelNone;
- }
- }
- }
- else
- {
- if([self respondsToSelector:@selector(clear_data)])
- {
- [self clear_data];
- self.notification_refreshLevel = NotificationRefreshLevelView;
- }
- }
-
- }
- #pragma mark - utils
- -(BOOL)isVisible
- {
- return (self.isViewLoaded && self.view.window);
- }
- - (NSString *)class_name {
- const char *class_name_ch = object_getClassName([self class]);
- return [NSString stringWithUTF8String:class_name_ch];
- }
- +(void) Notify:(NSString*) receiver Message:(NSString*)notification_msg
- {
- //NSArray* arr1 =[RAConvertor string2arr:@"abcde" separator:nil];
- // NSArray* arr2 =[RAConvertor string2arr:nil separator:nil];
- NSArray* arr_receiver = [RAConvertor string2arr:receiver separator:@","];
- NSMutableDictionary* dict = [NSMutableDictionary new];
- dict[@"receiver"]=arr_receiver;
- NSString* notificationname = nil;
- notificationname = notification_msg;
- NSNotification *notification =[NSNotification notificationWithName:notificationname object:nil userInfo:dict];
-
- //通过通知中心发送通知
-
- [[NSNotificationCenter defaultCenter] postNotification:notification];
- return;
-
- }
- @end
|