AJPhotoGroupView.m 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. //
  2. // BoPhotoGroupView.m
  3. // PhotoPicker
  4. //
  5. // Created by AlienJunX on 15/11/2.
  6. // Copyright © 2015年 com.alienjun.demo. All rights reserved.
  7. //
  8. #import "AJPhotoGroupView.h"
  9. #import "AJPhotoGroupCell.h"
  10. @interface AJPhotoGroupView()<UITableViewDataSource,UITableViewDelegate>
  11. @end
  12. @implementation AJPhotoGroupView
  13. #pragma mark - init
  14. - (instancetype)init {
  15. self = [super init];
  16. if (self) {
  17. [self initCommon];
  18. }
  19. return self;
  20. }
  21. - (instancetype)initWithCoder:(NSCoder *)coder {
  22. self = [super initWithCoder:coder];
  23. if (self) {
  24. [self initCommon];
  25. }
  26. return self;
  27. }
  28. - (id)initWithFrame:(CGRect)frame {
  29. self = [super initWithFrame:frame];
  30. if (self) {
  31. [self initCommon];
  32. }
  33. return self;
  34. }
  35. - (void)initCommon {
  36. self.delegate = self;
  37. self.dataSource = self;
  38. [self registerClass:[AJPhotoGroupCell class] forCellReuseIdentifier:@"cell"];
  39. self.separatorStyle = UITableViewCellSeparatorStyleNone;
  40. self.backgroundColor = [UIColor colorWithRed:235.0/255.0 green:235.0/255.0 blue:235.0/255.0 alpha:1.0];
  41. }
  42. - (void)setupGroup {
  43. [self.albumGroups removeAllObjects];
  44. BOOL canGetVideo = NO;
  45. BOOL canGetPhoto = NO;
  46. if(_isPhotoType){
  47. canGetPhoto = YES;
  48. }
  49. else{
  50. canGetVideo = YES;
  51. }
  52. [[TZImageManager manager] getAllAlbums:canGetVideo allowPickingImage:canGetPhoto needFetchAssets:NO completion:^(NSArray<TZAlbumModel *> *models) {
  53. self->_albumGroups = [[NSMutableArray alloc] initWithArray:models];
  54. [self dataReload];
  55. }];
  56. }
  57. #pragma mark - Reload Data
  58. - (void)dataReload {
  59. if (self.albumGroups.count == 0)
  60. //没有图片
  61. [self showNoAssets];
  62. if (self.albumGroups.count >0 && [_my_delegate respondsToSelector:@selector(didSelectGroup:)]) {
  63. [_my_delegate didSelectGroup:self.albumGroups[0]];
  64. }
  65. [self reloadData];
  66. }
  67. #pragma mark - Not allowed / No assets
  68. - (void)showNotAllowed {
  69. [[NSNotificationCenter defaultCenter] postNotificationName:@"NotAllowedPhoto" object:nil];
  70. if ([_my_delegate respondsToSelector:@selector(didSelectGroup:)]) {
  71. [_my_delegate didSelectGroup:nil];
  72. }
  73. }
  74. - (void)showNoAssets {
  75. NSLog(@"%s",__func__);
  76. }
  77. #pragma mark - uitableviewDelegate
  78. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  79. static NSString *cellIdentifer = @"cell";
  80. AJPhotoGroupCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer forIndexPath:indexPath];
  81. if(cell == nil){
  82. cell = [[AJPhotoGroupCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifer];
  83. }
  84. [cell bindModel:[self.albumGroups objectAtIndex:indexPath.row]];
  85. if (indexPath.row == self.selectIndex) {
  86. cell.backgroundColor = [UIColor hwColor:@"#EEFBFF" alpha:1.0];
  87. cell.selectButton.selected = YES;
  88. }
  89. return cell;
  90. }
  91. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  92. //return self.groups.count;
  93. return self.albumGroups.count;
  94. }
  95. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  96. return 60.0;
  97. }
  98. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  99. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  100. self.selectIndex = indexPath.row;
  101. [self reloadData];
  102. TZAlbumModel *model = [self.albumGroups objectAtIndex:indexPath.row];
  103. if ([_my_delegate respondsToSelector:@selector(didSelectGroup:)]) {
  104. [_my_delegate didSelectGroup:model];
  105. }
  106. }
  107. #pragma mark - getter/setter
  108. - (NSMutableArray *)albumGroups {
  109. if (!_albumGroups) {
  110. _albumGroups = [[NSMutableArray alloc] init];
  111. }
  112. return _albumGroups;
  113. }
  114. @end