CustomerInfoViewController.m 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. //
  2. // CustomerInfoViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 9/10/15.
  6. // Copyright (c) 2015 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "CustomerInfoViewController.h"
  9. #import "RANetwork.h"
  10. #import "CustomerEditViewController.h"
  11. #import "MainViewController.h"
  12. #import "JKTimerManager.h"
  13. @interface CustomerInfoViewController ()
  14. @end
  15. @implementation CustomerInfoViewController
  16. - (void)onEditClick:(id)sender {
  17. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  18. [params setValue:self.contactId forKey:@"contact_id"];
  19. CustomerEditViewController * cuseditVC = [[CustomerEditViewController alloc]initWithNibName:@"CommonEditor.iPad" bundle:nil];
  20. cuseditVC.bnewcustomer=false;
  21. cuseditVC.url_type = URL_REMOTE;
  22. cuseditVC.request_url=URL_EDIT_CUSTOMER;
  23. cuseditVC.params = params;
  24. cuseditVC.delegate=self;
  25. [[self navigationController] setNavigationBarHidden:NO animated:NO];
  26. [self.navigationController pushViewController:cuseditVC animated:false];
  27. }
  28. - (void)onAssignClick:(id)sender {
  29. [self.lastedit endEditing:true];
  30. [self.lasttextview endEditing:true];
  31. // [self.navigationController popViewControllerAnimated:(false)];
  32. int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  33. // NSMutableDictionary* data = [[self.data_init objectForKey:@"customerInfo"] mutableCopy];
  34. for(int i=0;i<section_count;i++)
  35. {
  36. NSDictionary * sectionjson= [self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i]] ;
  37. int count = [[sectionjson valueForKey:@"count"] intValue];
  38. for(int j=0;j<count;j++)
  39. {
  40. NSDictionary * itemjson=[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j]];
  41. //NSObject* obj=[itemjson valueForKey:@"name"];
  42. NSString* name = itemjson[@"name"];//[[ valueForKey:@"name"] stringValue];
  43. // DebugLog(@"%@",name.class);
  44. // DebugLog(@"%@",self.data_init.class);
  45. // DebugLog(@"%@",NSDictionary.class);
  46. NSString* value = itemjson[@"value"];//[[itemjson valueForKey:@""] stringValue];
  47. //[self.data_init setValue:value forKey:name];
  48. self.data_init[name]=value;
  49. }
  50. }
  51. //---------------- construct customer_contact----------------------
  52. NSString* customer_first_name = [self.data_init valueForKey:@"customer_first_name"];
  53. if(customer_first_name==nil)
  54. customer_first_name=@"";
  55. NSString* customer_last_name= [self.data_init valueForKey:@"customer_last_name"];
  56. if(customer_last_name==nil)
  57. customer_last_name=@"";
  58. NSString* customer_contact = [NSString stringWithFormat:@"%@ %@",customer_first_name,customer_last_name];
  59. customer_contact=[customer_contact stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  60. [self.data_init setValue:customer_contact forKey:@"customer_contact"];
  61. //---------------- finish construct customer_contact----------------------
  62. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  63. if(self.update_order && appDelegate.order_code!=nil)
  64. {
  65. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  66. NSDictionary* editor_json = [RANetwork update_OrderCustomer:appDelegate.order_code customerinfo:self.data_init];
  67. dispatch_async(dispatch_get_main_queue(), ^{
  68. if([[editor_json valueForKey:@"result"] intValue]==2)
  69. {
  70. [self.navigationController popViewControllerAnimated:false];
  71. if(self.returnValue)
  72. {
  73. self.returnValue(self.data_init);
  74. }
  75. }
  76. else
  77. {
  78. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Update Order Customer Infomation" controller:self] ;
  79. }
  80. });
  81. });
  82. }
  83. else
  84. {
  85. [self.navigationController popViewControllerAnimated:false];
  86. if(self.returnValue)
  87. {
  88. self.returnValue(self.data_init);
  89. }
  90. }
  91. }
  92. - (void)onResetClick:(id)sender {
  93. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  94. if(appDelegate.order_code.length>0)
  95. {
  96. //当前已打开订单则关闭订单。
  97. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure to release order and reset contact?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  98. //block代码块取代了delegate
  99. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  100. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Release Order"];
  101. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  102. NSDictionary* order_json = [RANetwork release_Order:appDelegate.order_code withScreen:ScreenCodeCustomerInfo];
  103. dispatch_async(dispatch_get_main_queue(), ^{
  104. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  105. if([[order_json valueForKey:@"result"] intValue]==2)
  106. {
  107. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  108. // appDelegate.order_code = nil;
  109. [appDelegate closeOrder];
  110. #ifdef RA_NOTIFICATION
  111. [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  112. [ActiveViewController Notify:@"ContactListViewController" Message:RA_NOTIFICATION_REFRESH_UI];
  113. #else
  114. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  115. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  116. [((MainViewController*)appDelegate.main_vc) reloadContact:false immediately:false];
  117. #endif
  118. [self.navigationController popToRootViewControllerAnimated:false];
  119. }
  120. else
  121. {
  122. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Release Order" controller:self] ;
  123. }
  124. });
  125. });
  126. }];
  127. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  128. DebugLog(@"Cancel");
  129. }];
  130. [alertControl addAction:actionOne];
  131. [alertControl addAction:alertthree];
  132. [self presentViewController:alertControl animated:YES completion:nil];
  133. }
  134. else
  135. {
  136. //询问并清空当前的全局contact_id、customer
  137. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure to reset contact?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  138. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  139. if(appDelegate.user_type!=USER_ROLE_CUSTOMER)
  140. {
  141. appDelegate.contact_id=nil;
  142. appDelegate.customerInfo = nil;
  143. }
  144. [self.navigationController popViewControllerAnimated:(false)];
  145. }];
  146. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  147. DebugLog(@"Cancel");
  148. }];
  149. [alertControl addAction:actionOne];
  150. [alertControl addAction:alertthree];
  151. [self presentViewController:alertControl animated:YES completion:nil];
  152. }
  153. }
  154. - (void)viewDidLoad {
  155. [super viewDidLoad];
  156. [[self navigationController] setNavigationBarHidden:NO animated:NO];
  157. if(self.rightbtn_title!=nil)
  158. [ self.right_btn setTitle:self.rightbtn_title];
  159. // UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Back", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onBackClick:)];
  160. // // closeButton.title = @"Close";
  161. UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  162. style:UIBarButtonItemStylePlain
  163. target:self
  164. action:@selector( onBackClick:)];
  165. self.navigationItem.leftBarButtonItem = backButton;
  166. NSMutableArray * items = [[NSMutableArray alloc]init];
  167. self.btn_edit = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"edit"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  168. style:UIBarButtonItemStylePlain
  169. target:self
  170. action:@selector(onEditClick:)];//[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Download", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onDownloadOrderClick:)];
  171. // self.btn_edit.tintColor = UIColorFromRGB(0x996633);
  172. self.btn_assign = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"assign"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  173. style:UIBarButtonItemStylePlain
  174. target:self
  175. action:@selector(onAssignClick:)];//[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Download", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onDownloadOrderClick:)];
  176. // self.btn_assign.tintColor = UIColorFromRGB(0x996633);
  177. self.btn_reset = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"reset"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  178. style:UIBarButtonItemStylePlain
  179. target:self
  180. action:@selector(onResetClick:)];//[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Download", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onDownloadOrderClick:)];
  181. // self.btn_reset.tintColor = UIColorFromRGB(0x996633);
  182. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  183. if(self.edit_icon)
  184. [items addObject:self.btn_edit];
  185. if ((appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) && appDelegate.order_code.length > 0 && ![Singleton sharedInstance].currentOrderIsMerged) {
  186. // shop order 隐藏assign
  187. } else {
  188. if(self.assig_icon)
  189. [items addObject:self.btn_assign];
  190. }
  191. if(self.reset_icon)
  192. [items addObject:self.btn_reset];
  193. self.navigationItem.rightBarButtonItems=items;
  194. if (self.data_init==nil) {
  195. [self request_fill];
  196. }
  197. else
  198. {
  199. [self fillData];
  200. }
  201. // Do any additional setup after loading the view.
  202. }
  203. - (void)onBackClick:(UIButton *)sender {
  204. [self.lastedit endEditing:true];
  205. [self.lasttextview endEditing:true];
  206. NSMutableDictionary* back_data = [self.data_init mutableCopy];
  207. // [self.navigationController popViewControllerAnimated:(false)];
  208. int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  209. // NSMutableDictionary* data = [[self.data_init objectForKey:@"customerInfo"] mutableCopy];
  210. for(int i=0;i<section_count;i++)
  211. {
  212. NSDictionary * sectionjson= [self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i]] ;
  213. int count = [[sectionjson valueForKey:@"count"] intValue];
  214. for(int j=0;j<count;j++)
  215. {
  216. NSDictionary * itemjson=[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j]];
  217. NSString* name = [itemjson valueForKey:@"name"];
  218. NSString* value = [itemjson valueForKey:@"value"];
  219. [back_data setValue:value forKey:name];
  220. }
  221. }
  222. //---------------- construct customer_contact----------------------
  223. NSString* customer_first_name = [back_data valueForKey:@"customer_first_name"];
  224. if(customer_first_name==nil)
  225. customer_first_name=@"";
  226. NSString* customer_last_name= [back_data valueForKey:@"customer_last_name"];
  227. if(customer_last_name==nil)
  228. customer_last_name=@"";
  229. NSString* customer_contact = [NSString stringWithFormat:@"%@ %@",customer_first_name,customer_last_name];
  230. customer_contact=[customer_contact stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  231. [back_data setValue:customer_contact forKey:@"customer_contact"];
  232. if(self.onClose)
  233. {
  234. self.onClose(back_data);
  235. }
  236. [self.navigationController popViewControllerAnimated:(false)];
  237. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  238. // ;
  239. // }];
  240. }
  241. -(void) request_fill
  242. {
  243. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Loading Contact information"];
  244. [RANetwork request_contactinfo:self.contactId completionHandler:^(NSMutableDictionary *result) {
  245. NSMutableDictionary* editor_json = result;
  246. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  247. if([[editor_json valueForKey:@"result"] intValue]==2)
  248. {
  249. self.data_init = [[editor_json objectForKey:@"customerInfo" ] mutableCopy];
  250. [self fillData];
  251. self.btn_assign.enabled=true;
  252. }
  253. else
  254. {
  255. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Loading Contact Information" controller:self] ;
  256. self.btn_assign.enabled=false;
  257. }
  258. }];
  259. return;
  260. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  261. //
  262. // NSDictionary* editor_json = [RANetwork request_CustomerInfo:self.contactId];
  263. //
  264. // dispatch_async(dispatch_get_main_queue(), ^{
  265. //
  266. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  267. //
  268. // if([[editor_json valueForKey:@"result"] intValue]==2)
  269. // {
  270. // self.data_init = [[editor_json objectForKey:@"customerInfo" ] mutableCopy];
  271. //
  272. // [self fillData];
  273. // self.btn_assign.enabled=true;
  274. //
  275. // }
  276. // else
  277. // {
  278. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Loading Contact Information" controller:self] ;
  279. // self.btn_assign.enabled=false;
  280. // }
  281. //
  282. //
  283. // });
  284. // });
  285. }
  286. - (void) fillData
  287. {
  288. int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  289. // NSDictionary* data = [self.data_init objectForKey:@"customerInfo"];
  290. for(int i=0;i<section_count;i++)
  291. {
  292. NSMutableDictionary * sectionjson= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i]] mutableCopy];
  293. int count = [[sectionjson valueForKey:@"count"] intValue];
  294. for(int j=0;j<count;j++)
  295. {
  296. NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  297. NSString* control=[itemjson valueForKey:@"control"];
  298. NSString* name = [itemjson valueForKey:@"name"];
  299. NSString* value = [self.data_init valueForKey:name];
  300. [itemjson setValue:value forKey:@"value"];
  301. if([control isEqualToString:@"img"])
  302. {
  303. {
  304. NSString* img_url = [itemjson valueForKey:@"img_url_0"];
  305. NSString* url_value = [self.data_init valueForKey:img_url];
  306. [itemjson setValue:url_value forKey:@"img_url_0"];
  307. }
  308. {
  309. NSString* img_url = [itemjson valueForKey:@"img_url_1"];
  310. NSString* url_value = [self.data_init valueForKey:img_url];
  311. [itemjson setValue:url_value forKey:@"img_url_1"];
  312. }
  313. {
  314. NSString* img_url = [itemjson valueForKey:@"img_url_2"];
  315. NSString* url_value = [self.data_init valueForKey:img_url];
  316. [itemjson setValue:url_value forKey:@"img_url_2"];
  317. }
  318. }
  319. [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j]];
  320. }
  321. [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i]];
  322. }
  323. self.content_data_control=[self translate_json:self.content_data_download changed:self.changed_data];
  324. // self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ;
  325. [self.editorTable reloadData];
  326. }
  327. #pragma mark- img changed
  328. // image 改变时执行
  329. - (void) imgIsChanged:(NSString *)url_down url_up:(NSString *)url_up indexPath: (NSIndexPath *) indexPath{
  330. // int aaa = 0;
  331. // NSDictionary* aaa = self.content_data_download;
  332. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Create Order"];
  333. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  334. NSString* cid=[self getValue:@"customer_cid"];
  335. NSDictionary* return_json = [RANetwork update_customer_img:cid img_url:url_up];
  336. dispatch_async(dispatch_get_main_queue(), ^{
  337. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  338. if([[return_json valueForKey:@"result"] intValue]==2)
  339. {
  340. int result=[[return_json valueForKey:@"result"] intValue];
  341. if(result==2)
  342. {
  343. UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Upload successful." message:nil delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  344. [alert show];
  345. }
  346. }
  347. else
  348. {
  349. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  350. }
  351. });
  352. });
  353. // // DebugLog(@"Sender is = %@", url);
  354. //
  355. //
  356. //
  357. //
  358. // NSMutableDictionary* section_json=nil;
  359. //
  360. //
  361. // // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
  362. // NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  363. //
  364. // int refresh = [[item_json valueForKey:@"refresh"] intValue];
  365. //
  366. // NSString* subid=[item_json valueForKey:@"subid"];
  367. //
  368. // item_json[@"img_url"]=url_down;
  369. // item_json[@"avalue"]=url_up;
  370. //
  371. // if(subid==nil)
  372. // {
  373. // section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  374. // int count=0;
  375. //
  376. // count=[[section_json valueForKey:@"count"] intValue];
  377. //
  378. // for(int i=0;i<count;i++)
  379. // {
  380. // NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
  381. // if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
  382. // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
  383. //
  384. //
  385. // }
  386. //
  387. // }
  388. // else
  389. // {
  390. // NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  391. // int section = [(NSString*)idarr[0] intValue];
  392. // int item=[(NSString*)idarr[1] intValue];
  393. //
  394. //
  395. // section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  396. // NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
  397. // item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  398. // [item_json setValue:@"true" forKey:@"dirty"];
  399. // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
  400. // }
  401. //
  402. //
  403. //
  404. // [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  405. //
  406. // self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
  407. //
  408. // NSRange range = NSMakeRange(indexPath.section, 1);
  409. // NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
  410. // // [self.editorTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  411. //
  412. //
  413. // if(refresh==1)
  414. // {
  415. // [self refresh];
  416. // }
  417. }
  418. - (void)didReceiveMemoryWarning {
  419. [super didReceiveMemoryWarning];
  420. // Dispose of any resources that can be recreated.
  421. }
  422. /*
  423. #pragma mark - Navigation
  424. // In a storyboard-based application, you will often want to do a little preparation before navigation
  425. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  426. // Get the new view controller using [segue destinationViewController].
  427. // Pass the selected object to the new view controller.
  428. }
  429. */
  430. #pragma mark - Urgency
  431. - (void)viewWillAppear:(BOOL)animated {
  432. [super viewWillAppear:animated];
  433. [self start_urgency_timer];
  434. }
  435. -(void) viewWillDisappear:(BOOL)animated
  436. {
  437. [super viewWillDisappear:animated];
  438. [self cancel_urgency_timer];
  439. }
  440. - (void)dealloc {
  441. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  442. [appDelegate.urgencyDic removeObjectForKey:[NSString stringWithFormat:@"level_%d",self.level]];
  443. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:self.level] forKey:@"count"];
  444. }
  445. - (void)start_urgency_timer {
  446. if (!self.editable) {
  447. return;
  448. }
  449. __weak typeof(self) weakSelf = self;
  450. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  451. [appDelegate.urgencyDic setValue:appDelegate.user forKey:@"user"];
  452. #ifdef OFFLINE_MODE
  453. [appDelegate.urgencyDic setValue:[NSNumber numberWithBool:appDelegate.offline_mode] forKey:@"offline_mode"];
  454. #endif
  455. [[JKTimerManager sharedTimerManager] scheduledDispatchTimerWithName:self.urgency_timer_name timeInterval:1 queue:nil repeats:YES action:^{
  456. NSMutableDictionary *urgencyDic = [NSMutableDictionary dictionary];
  457. // DebugLog(@"timer start....");
  458. [urgencyDic setValue:weakSelf.content_data_download forKey:[NSString stringWithFormat:@"%@_restored_data",self.class_name]];
  459. [urgencyDic setValue:weakSelf.class_name forKey:@"class_name"];
  460. [appDelegate.urgencyDic setValue:urgencyDic forKey:[NSString stringWithFormat:@"level_%d",weakSelf.level]];
  461. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:weakSelf.level + 1] forKey:@"count"];
  462. }];
  463. }
  464. - (void)cancel_urgency_timer {
  465. [[JKTimerManager sharedTimerManager] cancelTimerWithName:self.urgency_timer_name];
  466. }
  467. @end