// // TabViewController.m // iShop // // Created by Rui Zhang on 12/14/23. // #import "TabViewController.h" #import "const.h" #import "RAConvertor.h" @interface TabViewController () @end @implementation TabViewController - (void)viewDidLoad { [super viewDidLoad]; [[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; // Do any additional setup after loading the view. } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; // if(self.show_navi) { [[self navigationController] setNavigationBarHidden:FALSE animated:NO]; } else { [[self navigationController] setNavigationBarHidden:YES animated:NO]; } // self.navigationController.navigationBarHidden=true; 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; } } // //-(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)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; } -(void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; } //-(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) refresh_on_login { } -(void)refresh_btn_click:(UILongPressGestureRecognizer*)gestureRecognizer { if([self respondsToSelector:@selector(reload_data)]) [self reload_data]; // [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)OnReleaseScanner:(NSNotification *)notification //{ // if(!self.support_scanner) // return; // else // { // int a=0; // // UIApplication * app = [UIApplication sharedApplication]; // AppDelegate *appDelegate = (AppDelegate *)[app delegate]; // // if(self.support_scanner) // { // appDelegate.eventsFeedback = self; // } // // } // NSLog(@"release scanner !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); //} - (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_refreshLevel0) return; 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 { dispatch_async(dispatch_get_main_queue(), ^{ //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; }); } -(void) refresh_ui { NSAssert(true, @"subclass %@ refresh_ui does not impl.", [self class_name]); } -(void) reload_data { NSAssert(true, @"subclass %@ reload_data does not impl.", [self class_name]); } -(void) clear_data { NSAssert(true, @"subclass %@ clear_data does not impl.", [self class_name]); } -(void) refresh_price { NSAssert(true, @"subclass %@ refresh_price does not impl.", [self class_name]); } /* #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. } */ @end