TZAssetModel.m 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //
  2. // TZAssetModel.m
  3. // TZImagePickerController
  4. //
  5. // Created by 谭真 on 15/12/24.
  6. // Copyright © 2015年 谭真. All rights reserved.
  7. //
  8. #import "TZAssetModel.h"
  9. #import "TZImageManager.h"
  10. @implementation TZAssetModel
  11. + (instancetype)modelWithAsset:(PHAsset *)asset type:(TZAssetModelMediaType)type{
  12. TZAssetModel *model = [[TZAssetModel alloc] init];
  13. model.asset = asset;
  14. model.isSelected = NO;
  15. model.isChecked = NO;
  16. model.type = type;
  17. return model;
  18. }
  19. + (instancetype)modelWithAsset:(PHAsset *)asset type:(TZAssetModelMediaType)type timeLength:(NSString *)timeLength {
  20. TZAssetModel *model = [self modelWithAsset:asset type:type];
  21. model.timeLength = timeLength;
  22. return model;
  23. }
  24. @end
  25. @implementation TZAlbumModel
  26. - (void)setResult:(PHFetchResult *)result needFetchAssets:(BOOL)needFetchAssets {
  27. _result = result;
  28. if (needFetchAssets) {
  29. [[TZImageManager manager] getAssetsFromFetchResult:result completion:^(NSArray<TZAssetModel *> *models) {
  30. self->_models = models;
  31. if (self->_selectedModels) {
  32. [self checkSelectedModels];
  33. }
  34. }];
  35. }
  36. }
  37. - (void)setSelectedModels:(NSArray *)selectedModels {
  38. _selectedModels = selectedModels;
  39. if (_models) {
  40. [self checkSelectedModels];
  41. }
  42. }
  43. - (void)checkSelectedModels {
  44. self.selectedCount = 0;
  45. NSMutableArray *selectedAssets = [NSMutableArray array];
  46. for (TZAssetModel *model in _selectedModels) {
  47. [selectedAssets addObject:model.asset];
  48. }
  49. for (TZAssetModel *model in _models) {
  50. if ([selectedAssets containsObject:model.asset]) {
  51. self.selectedCount ++;
  52. }
  53. }
  54. }
  55. - (NSString *)name {
  56. if (_name) {
  57. return _name;
  58. }
  59. return @"";
  60. }
  61. @end