downloadThumbnailManager.m 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. NSString *newFileName = [addModel getFileNameFun];
  44. BOOL isNeedAdd = YES;
  45. for (couldPhoneFileModel *hadModel in hadTaskArr) {
  46. NSString *hadFileName = [addModel getFileNameFun];
  47. if([newFileName isEqualToString:hadFileName]){
  48. isNeedAdd = NO;
  49. break;
  50. }
  51. }
  52. [curTaskArr addObject:addModel];
  53. }];
  54. KWeakSelf
  55. [couldPhoneFileModel bg_saveOrUpdateArrayAsync:curTaskArr complete:^(BOOL isSuccess) {
  56. [weakSelf planToDownloadThumbnailFun];
  57. }];
  58. }
  59. - (void)planToDownloadThumbnailFun
  60. {
  61. KWeakSelf
  62. [couldPhoneFileModel bg_findAsync:downloadThumbnail_tableName limit:0 orderBy:nil desc:NO complete:^(NSArray * _Nullable array) {
  63. [weakSelf checkCouldPhoneFileModelTaskStateBy:array];
  64. }];
  65. }
  66. - (void)checkCouldPhoneFileModelTaskStateBy:(NSArray*)array
  67. {
  68. NSMutableArray *taskArr = [NSMutableArray new];
  69. for (couldPhoneFileModel*curModel in array) {
  70. if(curModel.curDownloadStateType != downloadStateDone){
  71. [taskArr addObject:curModel];
  72. }
  73. }
  74. _totalTaskArr = taskArr;
  75. }
  76. - (void)beginDownloadThumbnailFun
  77. {
  78. if (_totalTaskArr.count >0) {
  79. _curDownloadFileModel = _totalTaskArr.firstObject;
  80. }
  81. else{
  82. return;
  83. }
  84. [[NSNotificationCenter defaultCenter] postNotificationName:downloadThumbnailBeginNotification object:_curDownloadFileModel];
  85. }
  86. @end