WFCUConferenceAudioCollectionViewCell.m 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //
  2. // WFCUConferenceAudioCollectionViewCell.m
  3. // WFChatUIKit
  4. //
  5. // Created by Rain on 2022/10/5.
  6. // Copyright © 2022 Wildfirechat. All rights reserved.
  7. //
  8. #import "WFCUConferenceAudioCollectionViewCell.h"
  9. #import "WFCUConferenceParticipantCollectionViewCell.h"
  10. #if WFCU_SUPPORT_VOIP
  11. #import <WFAVEngineKit/WFAVEngineKit.h>
  12. @interface WFCUConferenceAudioCollectionViewCell () <UICollectionViewDataSource, UICollectionViewDelegate>
  13. @property(nonatomic, strong)UICollectionView *collectionView;
  14. @property(nonatomic, strong)NSMutableArray<WFAVParticipantProfile *> *participants;
  15. @property(nonatomic, assign)NSUInteger pages;
  16. @end
  17. #endif
  18. @implementation WFCUConferenceAudioCollectionViewCell
  19. #if WFCU_SUPPORT_VOIP
  20. - (instancetype)initWithFrame:(CGRect)frame {
  21. self = [super initWithFrame:frame];
  22. if(self) {
  23. [self setupView:frame];
  24. }
  25. return self;
  26. }
  27. - (void)setupView:(CGRect)frame {
  28. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
  29. CGFloat itemWidth = ([UIScreen mainScreen].bounds.size.width - flowLayout.minimumInteritemSpacing*2)/3-5;
  30. flowLayout.itemSize = CGSizeMake(itemWidth, itemWidth);
  31. // flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  32. self.collectionView = [[UICollectionView alloc] initWithFrame:frame collectionViewLayout:flowLayout];
  33. self.collectionView.dataSource = self;
  34. self.collectionView.delegate = self;
  35. self.collectionView.backgroundColor = [UIColor clearColor];
  36. [self.collectionView registerClass:[WFCUConferenceParticipantCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
  37. [self addSubview:self.collectionView];
  38. }
  39. - (void)setProfiles:(NSMutableArray<WFAVParticipantProfile *> *)participants pages:(NSUInteger)pages {
  40. self.participants = participants;
  41. self.pages = pages;
  42. UICollectionViewFlowLayout *flowLayout = (UICollectionViewFlowLayout *)self.collectionView.collectionViewLayout;
  43. CGFloat minimumInteritemSpacing = flowLayout.minimumInteritemSpacing;
  44. CGFloat minimumLineSpacing = flowLayout.minimumLineSpacing;
  45. CGSize parentSize = self.bounds.size;
  46. int itemCount = MIN(12, self.participants.count - self.pages*12);
  47. CGFloat itemWidth = (MIN(parentSize.width, parentSize.height) - flowLayout.minimumInteritemSpacing*2)/3-5;
  48. CGFloat startX, startY, widht, height;
  49. if(parentSize.width > parentSize.height) {
  50. if(itemCount == 1) {
  51. startX = parentSize.width/2 - itemWidth/2;
  52. widht = itemWidth;
  53. } else if(itemCount == 2) {
  54. startX = parentSize.width/2 - itemWidth - minimumInteritemSpacing/2;
  55. widht = itemWidth*2 + minimumInteritemSpacing;
  56. } else if(itemCount == 3){
  57. startX = parentSize.width/2 - itemWidth - itemWidth/2 - minimumInteritemSpacing;
  58. widht = itemWidth*3 + minimumInteritemSpacing*2;
  59. } else /*if(itemCount >= 4)*/ {
  60. startX = parentSize.width/2 - itemWidth*2 - minimumInteritemSpacing - minimumInteritemSpacing/2;
  61. widht = itemWidth*4 + minimumInteritemSpacing*3;
  62. }
  63. if(itemCount <= 4) {
  64. startY = parentSize.height/2 - itemWidth/2 - minimumLineSpacing;
  65. height = itemWidth + minimumLineSpacing * 2;
  66. } else if(itemCount <= 8) {
  67. startY = parentSize.height/2 - itemWidth - minimumLineSpacing - minimumInteritemSpacing/2;
  68. height = itemWidth*2 + minimumLineSpacing*2 + minimumInteritemSpacing;
  69. } else /*if(itemCount <= 12)*/ {
  70. startY = 0;
  71. height = parentSize.height;
  72. }
  73. } else {
  74. if(itemCount == 1) {
  75. startX = parentSize.width/2 - itemWidth/2;
  76. widht = itemWidth;
  77. } else if(itemCount == 2 || itemCount == 4) {
  78. startX = itemWidth/2 - minimumInteritemSpacing/2;
  79. widht = itemWidth*2 + minimumInteritemSpacing;
  80. } else {
  81. startX = 0;
  82. widht = parentSize.width;
  83. }
  84. if(itemCount <= 3) {
  85. startY = parentSize.height/2 - itemWidth/2 - minimumLineSpacing;
  86. height = itemWidth + minimumLineSpacing * 2;
  87. } else if(itemCount <= 6) {
  88. startY = parentSize.height/2 - itemWidth - minimumLineSpacing - minimumInteritemSpacing/2;
  89. height = itemWidth*2 + minimumLineSpacing*2 + minimumInteritemSpacing;
  90. } else if(itemCount <= 9) {
  91. startY = parentSize.height/2 - itemWidth - itemWidth/2 - minimumLineSpacing - minimumInteritemSpacing - minimumInteritemSpacing/2;
  92. height = itemWidth*3 + minimumLineSpacing *2 + minimumInteritemSpacing + minimumInteritemSpacing/2;
  93. } else /*if(itemCount <= 12)*/ {
  94. startY = parentSize.height/2 - itemWidth - itemWidth - minimumLineSpacing - minimumInteritemSpacing*2;
  95. height = itemWidth*4 - minimumLineSpacing*2 - minimumInteritemSpacing*2;
  96. }
  97. }
  98. self.collectionView.frame = CGRectMake(startX, startY, widht, height);
  99. [self.collectionView reloadData];
  100. }
  101. #pragma mark - UICollectionViewDataSource
  102. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  103. return MIN(12, self.participants.count - self.pages*12);
  104. }
  105. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  106. WFCUConferenceParticipantCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
  107. WFAVParticipantProfile *profile = self.participants[self.pages*12 + indexPath.row];
  108. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:profile.userId refresh:NO];
  109. [cell setUserInfo:userInfo callProfile:profile];
  110. cell.backgroundColor = [UIColor clearColor];
  111. return cell;
  112. }
  113. #endif
  114. @end