JDProgressHUD.m 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // JDProgressHUD.m
  3. // kneet2
  4. //
  5. // Created by Jason Lee on 10/5/15.
  6. // Copyright © 2015 ntels. All rights reserved.
  7. //
  8. #import "JDObject.h"
  9. #import "JDProgressHUD.h"
  10. @interface JDProgressHUD () {
  11. BOOL useAnimation;
  12. id targetForExecution;
  13. id objectForExecution;
  14. }
  15. @property (copy) JDFacadeCompletionCallBackHandler completionBlock;
  16. @property (assign) BOOL taskInProgress;
  17. @property (atomic, strong) NSTimer *graceTimer;
  18. @property (assign) float graceTime;
  19. @end
  20. @implementation JDProgressHUD
  21. - (void)showLoadingWhileExecutingBlock:(dispatch_block_t)block {
  22. dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
  23. [self showLoadingWhileExecutingBlock:block onQueue:queue completionBlock:NULL];
  24. }
  25. - (void)showLoadingWhileExecutingBlock:(dispatch_block_t)block completionHandler:(JDFacadeCompletionCallBackHandler)handler {
  26. dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
  27. [self showLoadingWhileExecutingBlock:block onQueue:queue completionBlock:handler];
  28. }
  29. - (void)showLoadingWhileExecutingBlock:(dispatch_block_t)block onQueue:(dispatch_queue_t)queue completionBlock:(JDFacadeCompletionCallBackHandler)completion {
  30. self.taskInProgress = YES;
  31. self.completionBlock = completion;
  32. dispatch_async(queue, ^(void) {
  33. block();
  34. dispatch_async(dispatch_get_main_queue(), ^(void) {
  35. [self cleanUp];
  36. });
  37. });
  38. [self showInView:[CommonUtil topView]];
  39. }
  40. - (void)cleanUp {
  41. _taskInProgress = NO;
  42. #if !__has_feature(objc_arc)
  43. [targetForExecution release];
  44. [objectForExecution release];
  45. #else
  46. targetForExecution = nil;
  47. objectForExecution = nil;
  48. #endif
  49. [self dismissAnimated:YES];
  50. if (self.completionBlock) {
  51. self.completionBlock();
  52. self.completionBlock = NULL;
  53. }
  54. }
  55. //
  56. //- (void)dismissAnimated:(BOOL)animated {
  57. // [super dismissAnimated:animated];
  58. //
  59. //
  60. //}
  61. @end