downloadThumbnailManager.m 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // downloadThumbnailManager.m
  3. // 隐私保护
  4. //
  5. // Created by xd h on 2024/1/8.
  6. //
  7. #import "downloadThumbnailManager.h"
  8. @implementation downloadThumbnailManager
  9. static downloadThumbnailManager * cur_downloadFileShareInstance = nil;
  10. +(downloadThumbnailManager *)shareInstance;
  11. {
  12. static dispatch_once_t onceToken;
  13. dispatch_once(&onceToken, ^{
  14. cur_downloadFileShareInstance = [[downloadThumbnailManager alloc] init];
  15. });
  16. return cur_downloadFileShareInstance;
  17. }
  18. - (id)init
  19. {
  20. self = [super init];
  21. if (self) {
  22. //[self initManager];
  23. }
  24. return self;
  25. }
  26. - (void)handlToDownloadThumbnailWith:(NSArray*)Arr
  27. {
  28. KWeakSelf
  29. //dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{
  30. [couldPhoneFileModel bg_findAsync:downloadThumbnail_tableName limit:0 orderBy:nil desc:NO complete:^(NSArray * _Nullable array) {
  31. [weakSelf checkTaskRepeatWithHadTask:array withNewTask:Arr];
  32. }];
  33. //});
  34. }
  35. -(void)checkTaskRepeatWithHadTask:(NSArray*)hadTaskArr withNewTask:(NSArray*)newTaskArr
  36. {
  37. NSMutableArray *curTaskArr = [NSMutableArray arrayWithArray:hadTaskArr];
  38. //for (couldPhoneFileModel *addModel in newTask)
  39. //倒序遍历
  40. [newTaskArr enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  41. //NSLog(@"%ld----",idx);
  42. couldPhoneFileModel *addModel = newTaskArr[idx];
  43. addModel.bg_tableName = downloadThumbnail_tableName;
  44. NSString *newFileName = [addModel getFileNameFun];
  45. BOOL isNeedAdd = YES;
  46. for (couldPhoneFileModel *hadModel in hadTaskArr) {
  47. NSString *hadFileName = [addModel getFileNameFun];
  48. if([newFileName isEqualToString:hadFileName]){
  49. isNeedAdd = NO;
  50. break;
  51. }
  52. }
  53. [curTaskArr addObject:addModel];
  54. }];
  55. KWeakSelf
  56. [couldPhoneFileModel bg_saveOrUpdateArrayAsync:curTaskArr complete:^(BOOL isSuccess) {
  57. [weakSelf planToDownloadThumbnailFun];
  58. }];
  59. }
  60. - (void)planToDownloadThumbnailFun
  61. {
  62. KWeakSelf
  63. [couldPhoneFileModel bg_findAsync:downloadThumbnail_tableName limit:0 orderBy:nil desc:NO complete:^(NSArray * _Nullable array) {
  64. [weakSelf checkCouldPhoneFileModelTaskStateBy:array];
  65. }];
  66. }
  67. - (void)checkCouldPhoneFileModelTaskStateBy:(NSArray*)array
  68. {
  69. NSMutableArray *taskArr = [NSMutableArray new];
  70. for (couldPhoneFileModel*curModel in array) {
  71. if(curModel.curDownloadStateType != downloadStateDone){
  72. [taskArr addObject:curModel];
  73. }
  74. }
  75. _totalTaskArr = taskArr;
  76. }
  77. - (void)beginDownloadThumbnailFun
  78. {
  79. if (_totalTaskArr.count >0) {
  80. _curDownloadFileModel = _totalTaskArr.firstObject;
  81. }
  82. else{
  83. return;
  84. }
  85. [[NSNotificationCenter defaultCenter] postNotificationName:downloadThumbnailBeginNotification object:_curDownloadFileModel];
  86. }
  87. @end