ActiveViewController.m 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. //
  2. // ActiveViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 12/15/15.
  6. // Copyright © 2015 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "ActiveViewController.h"
  9. #import "config.h"
  10. #import "AppDelegate.h"
  11. //#import "NotificationNameCenter.h"
  12. @interface ActiveViewController ()
  13. @end
  14. @implementation ActiveViewController
  15. - (void)viewDidLoad {
  16. [super viewDidLoad];
  17. self.refresh_type = REFRESH_DATA;
  18. #ifdef RA_NOTIFICATION
  19. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(OnRefreshUI:) name:RA_NOTIFICATION_REFRESH_UI object:nil];
  20. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(OnReloadData:) name:RA_NOTIFICATION_RELOAD_DATA object:nil];
  21. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(OnClearData:) name:RA_NOTIFICATION_CLEAR_DATA object:nil];
  22. #endif
  23. // Do any additional setup after loading the view.
  24. }
  25. - (void)didReceiveMemoryWarning {
  26. [super didReceiveMemoryWarning];
  27. // Dispose of any resources that can be recreated.
  28. }
  29. - (void)viewWillAppear:(BOOL)animated
  30. {
  31. [super viewWillAppear:animated];
  32. UIApplication * app = [UIApplication sharedApplication];
  33. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  34. appDelegate.active_controller = self;
  35. switch (self.refresh_type)
  36. {
  37. case REFRESH_VIEW:
  38. [self reload_container_getdata:false];
  39. break;
  40. case REFRESH_DATA: {
  41. [self reRefreshView];
  42. [self reload_container_getdata:true];
  43. }
  44. break;
  45. }
  46. // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  47. }
  48. -(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
  49. {
  50. // UIApplication * app = [UIApplication sharedApplication];
  51. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  52. // [appDelegate didRotated];
  53. // UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
  54. // if (UIInterfaceOrientationIsLandscape(orientation)|| UIInterfaceOrientationIsPortrait(orientation))
  55. // {
  56. // self.orientation = orientation;
  57. // [self.collectionview.collectionViewLayout invalidateLayout];
  58. // DebugLog(@"routed");
  59. // }
  60. }
  61. - (void)reRefreshView {
  62. }
  63. -(void) logout
  64. {
  65. self.refresh_type=REFRESH_NONE;
  66. }
  67. -(void) showHidePrice
  68. {
  69. // [self reload_container_getdata:false];
  70. }
  71. -(void) refresh_on_login
  72. {
  73. UIApplication * app = [UIApplication sharedApplication];
  74. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  75. if(self==appDelegate.active_controller)
  76. {
  77. [self reload_container_getdata:true];
  78. }
  79. else
  80. self.refresh_type = REFRESH_DATA;
  81. }
  82. -(void) reload_container_getdata:(bool) update_data
  83. {
  84. self.refresh_type=REFRESH_NONE;
  85. }
  86. -(void)refresh_btn_click:(UILongPressGestureRecognizer*)gestureRecognizer
  87. {
  88. [self reload_container_getdata:true];
  89. }
  90. /*
  91. #pragma mark - Navigation
  92. // In a storyboard-based application, you will often want to do a little preparation before navigation
  93. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  94. // Get the new view controller using [segue destinationViewController].
  95. // Pass the selected object to the new view controller.
  96. }
  97. */
  98. #pragma mark - Support scanner
  99. -(void) OnUpdateDevicesList
  100. {
  101. }
  102. -(void) onDecodedData:(NSString*) value
  103. {
  104. }
  105. -(void) onErrorInfo:(NSString*) errorInfo
  106. {
  107. }
  108. -(void) onStatusChanged:(NSString*) status
  109. {
  110. }
  111. -(void) onLogUpdate
  112. {
  113. }
  114. #pragma mark - Notification
  115. - (void)OnRefreshUI: (NSNotification *)notification
  116. {
  117. NSDictionary* dict = [notification userInfo];
  118. NSArray* arr= dict[@"receiver"];
  119. if([arr indexOfObject:[self class_name]]==NSNotFound)
  120. return;
  121. // if([self class_name] isEqualToString:@"")
  122. if(self.notification_refreshLevel<NotificationRefreshLevelView)
  123. {
  124. if([self isVisible])
  125. {
  126. if([self respondsToSelector:@selector(refresh_ui)])
  127. [self refresh_ui];
  128. }
  129. else
  130. {
  131. self.notification_refreshLevel = NotificationRefreshLevelView;
  132. }
  133. }
  134. }
  135. - (void)OnReloadData: (NSNotification *)notification
  136. {
  137. NSDictionary* dict = [notification userInfo];
  138. NSArray* arr= dict[@"receiver"];
  139. if([arr indexOfObject:[self class_name]]==NSNotFound)
  140. return;
  141. if(self.notification_refreshLevel<NotificationRefreshLevelData)
  142. {
  143. if([self isVisible])
  144. {
  145. if([self respondsToSelector:@selector(reload_data)])
  146. [self reload_data];
  147. }
  148. else
  149. {
  150. self.notification_refreshLevel = NotificationRefreshLevelData;
  151. }
  152. }
  153. }
  154. - (void)OnClearData: (NSNotification *)notification
  155. {
  156. if([self isVisible])
  157. {
  158. if([self respondsToSelector:@selector(clear_data)])
  159. {
  160. [self clear_data];
  161. if([self respondsToSelector:@selector(refresh_ui)])
  162. [self refresh_ui];
  163. }
  164. }
  165. else
  166. {
  167. if([self respondsToSelector:@selector(clear_data)])
  168. {
  169. [self clear_data];
  170. if(self.notification_refreshLevel<NotificationRefreshLevelView)
  171. self.notification_refreshLevel = NotificationRefreshLevelView;
  172. }
  173. }
  174. }
  175. #pragma mark - utils
  176. -(BOOL)isVisible
  177. {
  178. return (self.isViewLoaded && self.view.window);
  179. }
  180. - (NSString *)class_name {
  181. const char *class_name_ch = object_getClassName([self class]);
  182. return [NSString stringWithUTF8String:class_name_ch];
  183. }
  184. @end