ActiveViewController.m 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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 "RAConvertor.h"
  12. //#import "NotificationNameCenter.h"
  13. @interface ActiveViewController ()
  14. @end
  15. @implementation ActiveViewController
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  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. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(OnUpdatePrice:) name:RA_NOTIFICATION_UPDATE_PRICE object:nil];
  23. self.notification_refreshLevel = NotificationRefreshLevelData;
  24. #else
  25. self.refresh_type = REFRESH_DATA;
  26. #endif
  27. // Do any additional setup after loading the view.
  28. }
  29. - (void)dealloc
  30. {
  31. [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
  32. [[NSNotificationCenter defaultCenter] removeObserver:self];
  33. }
  34. - (void)didReceiveMemoryWarning {
  35. [super didReceiveMemoryWarning];
  36. // Dispose of any resources that can be recreated.
  37. }
  38. - (void)viewWillAppear:(BOOL)animated
  39. {
  40. [super viewWillAppear:animated];
  41. #ifdef RA_NOTIFICATION
  42. switch (self.notification_refreshLevel)
  43. {
  44. case NotificationRefreshLevelView:
  45. if([self respondsToSelector:@selector(refresh_ui)])
  46. [self refresh_ui];
  47. break;
  48. case NotificationRefreshLevelData:
  49. if([self respondsToSelector:@selector(reload_data)])
  50. [self reload_data];
  51. break;
  52. default:
  53. break;
  54. }
  55. #else
  56. UIApplication * app = [UIApplication sharedApplication];
  57. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  58. appDelegate.active_controller = self;
  59. switch (self.refresh_type)
  60. {
  61. case REFRESH_VIEW:
  62. [self reload_container_getdata:false];
  63. break;
  64. case REFRESH_DATA: {
  65. [self reRefreshView];
  66. [self reload_container_getdata:true];
  67. }
  68. break;
  69. }
  70. #endif
  71. // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  72. }
  73. -(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
  74. {
  75. // UIApplication * app = [UIApplication sharedApplication];
  76. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  77. // [appDelegate didRotated];
  78. // UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
  79. // if (UIInterfaceOrientationIsLandscape(orientation)|| UIInterfaceOrientationIsPortrait(orientation))
  80. // {
  81. // self.orientation = orientation;
  82. // [self.collectionview.collectionViewLayout invalidateLayout];
  83. // DebugLog(@"routed");
  84. // }
  85. }
  86. - (void)reRefreshView {
  87. }
  88. -(void) logout
  89. {
  90. self.refresh_type=REFRESH_NONE;
  91. }
  92. -(void) showHidePrice
  93. {
  94. // [self reload_container_getdata:false];
  95. }
  96. -(void) refresh_on_login
  97. {
  98. UIApplication * app = [UIApplication sharedApplication];
  99. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  100. if(self==appDelegate.active_controller)
  101. {
  102. [self reload_container_getdata:true];
  103. }
  104. else
  105. self.refresh_type = REFRESH_DATA;
  106. }
  107. -(void) reload_container_getdata:(bool) update_data
  108. {
  109. self.refresh_type=REFRESH_NONE;
  110. }
  111. -(void)refresh_btn_click:(UILongPressGestureRecognizer*)gestureRecognizer
  112. {
  113. [self reload_container_getdata:true];
  114. }
  115. /*
  116. #pragma mark - Navigation
  117. // In a storyboard-based application, you will often want to do a little preparation before navigation
  118. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  119. // Get the new view controller using [segue destinationViewController].
  120. // Pass the selected object to the new view controller.
  121. }
  122. */
  123. #pragma mark - Support scanner
  124. -(void) OnUpdateDevicesList
  125. {
  126. }
  127. -(void) onDecodedData:(NSString*) value
  128. {
  129. }
  130. -(void) onErrorInfo:(NSString*) errorInfo
  131. {
  132. }
  133. -(void) onStatusChanged:(NSString*) status
  134. {
  135. }
  136. -(void) onLogUpdate
  137. {
  138. }
  139. #pragma mark - Notification
  140. - (void)OnUpdatePrice: (NSNotification *)notification
  141. {
  142. if(self.disable_refresh)
  143. return;
  144. NSDictionary* dict = [notification userInfo];
  145. NSArray* arr= dict[@"receiver"];
  146. //如果当前对象不在不是指定接收者,也不是广播通信,就返回。
  147. if([arr indexOfObject:[self class_name]]==NSNotFound&& arr.count>0)
  148. return;
  149. //如果当前对象本身不支持此动作,则返回
  150. if(![self respondsToSelector:@selector(refresh_price)])
  151. return;
  152. //如果当前已有的处理层级更高(reload),则不处理,交给reload 处理。
  153. if(self.notification_refreshLevel<NotificationRefreshLevelView)
  154. {
  155. if([self isVisible])
  156. {
  157. [self refresh_price];
  158. }
  159. else
  160. {
  161. self.notification_refreshLevel = NotificationRefreshLevelView;
  162. }
  163. }
  164. }
  165. - (void)OnRefreshUI: (NSNotification *)notification
  166. {
  167. if(self.disable_refresh)
  168. return;
  169. NSDictionary* dict = [notification userInfo];
  170. NSArray* arr= dict[@"receiver"];
  171. if([arr indexOfObject:[self class_name]]==NSNotFound&& arr.count>0)
  172. return;
  173. if(![self respondsToSelector:@selector(refresh_ui)])
  174. return;
  175. if(self.notification_refreshLevel<NotificationRefreshLevelView)
  176. {
  177. if([self isVisible])
  178. {
  179. [self refresh_ui];
  180. }
  181. else
  182. {
  183. self.notification_refreshLevel = NotificationRefreshLevelView;
  184. }
  185. }
  186. }
  187. - (void)OnReloadData: (NSNotification *)notification
  188. {
  189. if(self.disable_refresh)
  190. return;
  191. NSDictionary* dict = [notification userInfo];
  192. NSArray* arr= dict[@"receiver"];
  193. if([arr indexOfObject:[self class_name]]==NSNotFound&& arr.count>0)
  194. return;
  195. if(![self respondsToSelector:@selector(reload_data)])
  196. return;
  197. if(self.notification_refreshLevel<NotificationRefreshLevelData)
  198. {
  199. if([self isVisible])
  200. {
  201. [self reload_data];
  202. }
  203. else
  204. {
  205. self.notification_refreshLevel = NotificationRefreshLevelData;
  206. }
  207. }
  208. }
  209. - (void)OnClearData: (NSNotification *)notification
  210. {
  211. if(![self respondsToSelector:@selector(clear_data)])
  212. return;
  213. if([self isVisible])
  214. {
  215. {
  216. [self clear_data];
  217. if([self respondsToSelector:@selector(refresh_ui)])
  218. [self refresh_ui];
  219. }
  220. }
  221. else
  222. {
  223. if([self respondsToSelector:@selector(clear_data)])
  224. {
  225. [self clear_data];
  226. self.notification_refreshLevel = NotificationRefreshLevelView;
  227. }
  228. }
  229. }
  230. #pragma mark - utils
  231. -(BOOL)isVisible
  232. {
  233. return (self.isViewLoaded && self.view.window);
  234. }
  235. - (NSString *)class_name {
  236. const char *class_name_ch = object_getClassName([self class]);
  237. return [NSString stringWithUTF8String:class_name_ch];
  238. }
  239. +(void) Notify:(NSString*) receiver Message:(NSString*)notification_msg
  240. {
  241. //NSArray* arr1 =[RAConvertor string2arr:@"abcde" separator:nil];
  242. // NSArray* arr2 =[RAConvertor string2arr:nil separator:nil];
  243. NSArray* arr_receiver = [RAConvertor string2arr:receiver separator:@","];
  244. NSMutableDictionary* dict = [NSMutableDictionary new];
  245. dict[@"receiver"]=arr_receiver;
  246. NSString* notificationname = nil;
  247. notificationname = notification_msg;
  248. NSNotification *notification =[NSNotification notificationWithName:notificationname object:nil userInfo:dict];
  249. //通过通知中心发送通知
  250. [[NSNotificationCenter defaultCenter] postNotification:notification];
  251. return;
  252. }
  253. @end