TabViewController.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. //
  2. // TabViewController.m
  3. // iShop
  4. //
  5. // Created by Rui Zhang on 12/14/23.
  6. //
  7. #import "TabViewController.h"
  8. #import "const.h"
  9. #import "RAConvertor.h"
  10. @interface TabViewController ()
  11. @end
  12. @implementation TabViewController
  13. - (void)viewDidLoad {
  14. [super viewDidLoad];
  15. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(OnRefreshUI:) name:RA_NOTIFICATION_REFRESH_UI object:nil];
  16. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(OnReloadData:) name:RA_NOTIFICATION_RELOAD_DATA object:nil];
  17. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(OnClearData:) name:RA_NOTIFICATION_CLEAR_DATA object:nil];
  18. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(OnUpdatePrice:) name:RA_NOTIFICATION_UPDATE_PRICE object:nil];
  19. self.notification_refreshLevel = NotificationRefreshLevelData;
  20. // Do any additional setup after loading the view.
  21. }
  22. - (void)viewWillAppear:(BOOL)animated
  23. {
  24. [super viewWillAppear:animated];
  25. //
  26. if(self.show_navi)
  27. {
  28. [[self navigationController] setNavigationBarHidden:FALSE animated:NO];
  29. }
  30. else
  31. {
  32. [[self navigationController] setNavigationBarHidden:YES animated:NO];
  33. }
  34. // self.navigationController.navigationBarHidden=true;
  35. switch (self.notification_refreshLevel)
  36. {
  37. case NotificationRefreshLevelView:
  38. if([self respondsToSelector:@selector(refresh_ui)])
  39. {
  40. [self refresh_ui];
  41. self.notification_refreshLevel = NotificationRefreshLevelNone;
  42. }
  43. break;
  44. case NotificationRefreshLevelData:
  45. if([self respondsToSelector:@selector(reload_data)])
  46. {
  47. [self reload_data];
  48. self.notification_refreshLevel = NotificationRefreshLevelNone;
  49. }
  50. break;
  51. default:
  52. break;
  53. }
  54. }
  55. //
  56. //-(void)routerEvent:(NSString*)event Info:(id)info
  57. //{
  58. // return;
  59. //
  60. //// if([event isEqualToString:@"RA_NOTIFICATION_RELEASE_SCANNER"])
  61. //// {
  62. //// if(self.support_scanner)
  63. //// {
  64. //// int a=0;
  65. ////#ifdef RA_NOTIFICATION
  66. //// UIApplication * app = [UIApplication sharedApplication];
  67. //// AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  68. ////
  69. //// if(self.support_scanner)
  70. //// {
  71. //// appDelegate.eventsFeedback = self;
  72. //// }
  73. ////#endif
  74. //// }
  75. //// else
  76. //// [super routerEvent:event Info:info];
  77. //// }
  78. //// else
  79. //// [super routerEvent:event Info:info];
  80. //
  81. //}
  82. - (void)dealloc
  83. {
  84. [[NSNotificationCenter defaultCenter] removeObserver:self];
  85. }
  86. - (void)didReceiveMemoryWarning {
  87. [super didReceiveMemoryWarning];
  88. // Dispose of any resources that can be recreated.
  89. }
  90. -(void)viewDidAppear:(BOOL)animated
  91. {
  92. [super viewDidAppear:animated];
  93. }
  94. -(void)viewDidDisappear:(BOOL)animated
  95. {
  96. [super viewDidDisappear:animated];
  97. }
  98. //-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
  99. //{
  100. //// UIApplication * app = [UIApplication sharedApplication];
  101. //// AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  102. //// [appDelegate didRotated];
  103. //
  104. //// UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
  105. //// if (UIInterfaceOrientationIsLandscape(orientation)|| UIInterfaceOrientationIsPortrait(orientation))
  106. //// {
  107. //// self.orientation = orientation;
  108. //// [self.collectionview.collectionViewLayout invalidateLayout];
  109. //// DebugLog(@"routed");
  110. //// }
  111. //
  112. //
  113. //
  114. //
  115. //}
  116. - (void)reRefreshView {
  117. }
  118. -(void) logout
  119. {
  120. self.refresh_type=REFRESH_NONE;
  121. }
  122. -(void) refresh_on_login
  123. {
  124. }
  125. -(void)refresh_btn_click:(UILongPressGestureRecognizer*)gestureRecognizer
  126. {
  127. if([self respondsToSelector:@selector(reload_data)])
  128. [self reload_data];
  129. // [self reload_container_getdata:true];
  130. }
  131. /*
  132. #pragma mark - Navigation
  133. // In a storyboard-based application, you will often want to do a little preparation before navigation
  134. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  135. // Get the new view controller using [segue destinationViewController].
  136. // Pass the selected object to the new view controller.
  137. }
  138. */
  139. #pragma mark - Support scanner
  140. -(void) OnUpdateDevicesList
  141. {
  142. }
  143. -(void) onDecodedData:(NSString*) value
  144. {
  145. }
  146. -(void) onErrorInfo:(NSString*) errorInfo
  147. {
  148. }
  149. -(void) onStatusChanged:(NSString*) status
  150. {
  151. }
  152. -(void) onLogUpdate
  153. {
  154. }
  155. #pragma mark - Notification
  156. //-(void)OnReleaseScanner:(NSNotification *)notification
  157. //{
  158. // if(!self.support_scanner)
  159. // return;
  160. // else
  161. // {
  162. // int a=0;
  163. //
  164. // UIApplication * app = [UIApplication sharedApplication];
  165. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  166. //
  167. // if(self.support_scanner)
  168. // {
  169. // appDelegate.eventsFeedback = self;
  170. // }
  171. //
  172. // }
  173. // NSLog(@"release scanner !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  174. //}
  175. - (void)OnUpdatePrice: (NSNotification *)notification
  176. {
  177. if(self.disable_refresh)
  178. return;
  179. NSDictionary* dict = [notification userInfo];
  180. NSArray* arr= dict[@"receiver"];
  181. //如果当前对象不在不是指定接收者,也不是广播通信,就返回。
  182. if([arr indexOfObject:[self class_name]]==NSNotFound&& arr.count>0)
  183. return;
  184. //如果当前对象本身不支持此动作,则返回
  185. if(![self respondsToSelector:@selector(refresh_price)])
  186. return;
  187. //如果当前已有的处理层级更高(reload),则不处理,交给reload 处理。
  188. if(self.notification_refreshLevel<NotificationRefreshLevelView)
  189. {
  190. if([self isVisible])
  191. {
  192. [self refresh_price];
  193. self.notification_refreshLevel = NotificationRefreshLevelNone;
  194. }
  195. else
  196. {
  197. self.notification_refreshLevel = NotificationRefreshLevelView;
  198. }
  199. }
  200. }
  201. - (void)OnRefreshUI: (NSNotification *)notification
  202. {
  203. if(self.disable_refresh)
  204. return;
  205. NSDictionary* dict = [notification userInfo];
  206. NSArray* arr= dict[@"receiver"];
  207. if([arr indexOfObject:[self class_name]]==NSNotFound&& arr.count>0)
  208. return;
  209. if(![self respondsToSelector:@selector(refresh_ui)])
  210. return;
  211. if(self.notification_refreshLevel<NotificationRefreshLevelView)
  212. {
  213. if([self isVisible])
  214. {
  215. [self refresh_ui];
  216. self.notification_refreshLevel = NotificationRefreshLevelNone;
  217. }
  218. else
  219. {
  220. self.notification_refreshLevel = NotificationRefreshLevelView;
  221. }
  222. }
  223. }
  224. - (void)OnReloadData: (NSNotification *)notification
  225. {
  226. if(self.disable_refresh)
  227. return;
  228. NSDictionary* dict = [notification userInfo];
  229. NSArray* arr= dict[@"receiver"];
  230. if([arr indexOfObject:[self class_name]]==NSNotFound&& arr.count>0)
  231. return;
  232. if(![self respondsToSelector:@selector(reload_data)])
  233. return;
  234. if(self.notification_refreshLevel<NotificationRefreshLevelData)
  235. {
  236. if([self isVisible])
  237. {
  238. [self reload_data];
  239. self.notification_refreshLevel = NotificationRefreshLevelNone;
  240. }
  241. else
  242. {
  243. self.notification_refreshLevel = NotificationRefreshLevelData;
  244. }
  245. }
  246. }
  247. - (void)OnClearData: (NSNotification *)notification
  248. {
  249. NSDictionary* dict = [notification userInfo];
  250. NSArray* arr= dict[@"receiver"];
  251. if([arr indexOfObject:[self class_name]]==NSNotFound&& arr.count>0)
  252. return;
  253. if(![self respondsToSelector:@selector(clear_data)])
  254. return;
  255. if([self isVisible])
  256. {
  257. if([self respondsToSelector:@selector(clear_data)])
  258. {
  259. [self clear_data];
  260. if([self respondsToSelector:@selector(refresh_ui)])
  261. {
  262. [self refresh_ui];
  263. self.notification_refreshLevel = NotificationRefreshLevelNone;
  264. }
  265. }
  266. }
  267. else
  268. {
  269. if([self respondsToSelector:@selector(clear_data)])
  270. {
  271. [self clear_data];
  272. self.notification_refreshLevel = NotificationRefreshLevelView;
  273. }
  274. }
  275. }
  276. #pragma mark - utils
  277. -(BOOL)isVisible
  278. {
  279. return (self.isViewLoaded && self.view.window);
  280. }
  281. - (NSString *)class_name {
  282. const char *class_name_ch = object_getClassName([self class]);
  283. return [NSString stringWithUTF8String:class_name_ch];
  284. }
  285. +(void) Notify:(NSString*) receiver Message:(NSString*)notification_msg
  286. {
  287. dispatch_async(dispatch_get_main_queue(), ^{
  288. //NSArray* arr1 =[RAConvertor string2arr:@"abcde" separator:nil];
  289. // NSArray* arr2 =[RAConvertor string2arr:nil separator:nil];
  290. NSArray* arr_receiver = [RAConvertor string2arr:receiver separator:@","];
  291. NSMutableDictionary* dict = [NSMutableDictionary new];
  292. dict[@"receiver"]=arr_receiver;
  293. NSString* notificationname = nil;
  294. notificationname = notification_msg;
  295. NSNotification *notification =[NSNotification notificationWithName:notificationname object:nil userInfo:dict];
  296. //通过通知中心发送通知
  297. [[NSNotificationCenter defaultCenter] postNotification:notification];
  298. return;
  299. });
  300. }
  301. -(void) refresh_ui
  302. {
  303. NSAssert(true, @"subclass %@ refresh_ui does not impl.", [self class_name]);
  304. }
  305. -(void) reload_data
  306. {
  307. NSAssert(true, @"subclass %@ reload_data does not impl.", [self class_name]);
  308. }
  309. -(void) clear_data
  310. {
  311. NSAssert(true, @"subclass %@ clear_data does not impl.", [self class_name]);
  312. }
  313. -(void) refresh_price
  314. {
  315. NSAssert(true, @"subclass %@ refresh_price does not impl.", [self class_name]);
  316. }
  317. /*
  318. #pragma mark - Navigation
  319. // In a storyboard-based application, you will often want to do a little preparation before navigation
  320. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  321. // Get the new view controller using [segue destinationViewController].
  322. // Pass the selected object to the new view controller.
  323. }
  324. */
  325. @end