MOGiftUserView.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. //
  2. // MOGiftUserView.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2024/8/19.
  6. //
  7. #import "MOGiftUserView.h"
  8. #import "MOGiftUserCell.h"
  9. @interface MOGiftUserView ()<UICollectionViewDelegate,UICollectionViewDataSource>
  10. @property (weak, nonatomic) IBOutlet UILabel *tagLab;
  11. @property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
  12. @property (nonatomic, strong) UILabel *tipLab;
  13. @property (weak, nonatomic) IBOutlet BigBtn *allBtn;
  14. @property (nonatomic, strong) NSArray *dataArr;
  15. @property (nonatomic, assign) BOOL isAllChoose;
  16. @property (nonatomic, assign) BOOL oldArrIsChange;
  17. @property (nonatomic, strong) UIView *linkMicsView;
  18. @property (nonatomic, strong) UIImageView *linkMicImageView;
  19. @property (nonatomic, strong) UILabel *linkMicName;
  20. @end
  21. @implementation MOGiftUserView
  22. + (instancetype)moGiftUserView{
  23. return [[[NSBundle mainBundle] loadNibNamed:@"MOGiftUserView" owner:self options:nil] firstObject];
  24. }
  25. - (void)awakeFromNib{
  26. [super awakeFromNib];
  27. self.isAllChoose = NO;
  28. self.tagLab.text = NSLocalString(@"mimo_2_live_send_gift_tag");
  29. self.allBtn.layer.cornerRadius = 8.0;
  30. self.allBtn.layer.masksToBounds = YES;
  31. UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init];
  32. CGFloat width = 50.0;
  33. CGFloat height = 50.0;
  34. flow.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  35. flow.itemSize = CGSizeMake(width, height);
  36. flow.minimumLineSpacing = 0.0;//行间距
  37. flow.minimumInteritemSpacing = 0.0;//列间距
  38. [self.collectionView setCollectionViewLayout:flow];
  39. self.collectionView.delegate = self;
  40. self.collectionView.dataSource = self;
  41. [self.collectionView registerNib:[UINib nibWithNibName:@"MOGiftUserCell" bundle:nil] forCellWithReuseIdentifier:MOGiftUserCell_ID];
  42. [self.allBtn setFont:[MOTextTools poppinsRegularFont:12.0]];
  43. self.tagLab.font = [MOTextTools regularFont:12.0];
  44. self.layer.cornerRadius = 16.0;
  45. self.layer.masksToBounds = YES;
  46. self.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner;
  47. [self addSubview:self.tipLab];
  48. [self.tipLab mas_makeConstraints:^(MASConstraintMaker *make) {
  49. make.edges.equalTo(self.collectionView);
  50. }];
  51. self.tipLab.hidden = YES;
  52. [self addSubview:self.linkMicsView];
  53. [self.linkMicsView mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.left.equalTo(self).offset(80.0);
  55. make.top.bottom.equalTo(self);
  56. make.right.equalTo(self).offset(-0.0);
  57. }];
  58. self.linkMicsView.hidden = YES;
  59. [self.linkMicsView addSubview:self.linkMicImageView];
  60. [self.linkMicImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  61. make.left.equalTo(self.linkMicsView).offset(10.0);
  62. make.centerY.equalTo(self.linkMicsView);
  63. make.width.height.equalTo(@32.0);
  64. }];
  65. [self.linkMicsView addSubview:self.linkMicName];
  66. [self.linkMicName mas_makeConstraints:^(MASConstraintMaker *make) {
  67. make.left.equalTo(self.linkMicImageView.mas_right).offset(6.0);
  68. make.centerY.equalTo(self.linkMicsView);
  69. make.right.equalTo(self.linkMicsView).offset(-10.0);
  70. }];
  71. }
  72. - (IBAction)allBtnClick:(id)sender {
  73. [self.selectUserArr removeAllObjects];
  74. self.isAllChoose = !self.isAllChoose;
  75. if(self.isAllChoose){
  76. for (MOUserProfile *object in self.dataArr) {
  77. object.isSelect = YES;
  78. [self.selectUserArr addObject:object.id];
  79. }
  80. }
  81. else{
  82. for (MOUserProfile *object in self.dataArr) {
  83. object.isSelect = NO;
  84. }
  85. }
  86. self.oldSelectUserArr = [self.selectUserArr copy];
  87. self.oldArrIsChange = YES;
  88. [self.collectionView reloadData];
  89. }
  90. - (void)setIsAllChoose:(BOOL)isAllChoose{
  91. _isAllChoose = isAllChoose;
  92. if(isAllChoose){
  93. NSArray *colorArr = @[[MOTools colorWithHexString:@"#FFFFFF" alpha:0.06],[MOTools colorWithHexString:@"#FFFFFF" alpha:0.06]];
  94. UIImage *image = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, 56.0, 24.0) Colors:colorArr GradientType:0];
  95. [self.allBtn setBackgroundImage:image forState:UIControlStateNormal];
  96. [self.allBtn setTitle:NSLocalString(@"mimo_voice_all_btn_no_choose") forState:UIControlStateNormal];
  97. [self.allBtn setTitleColor:[MOTools colorWithHexString:@"#FFFFFF" alpha:0.5] forState:UIControlStateNormal];
  98. }
  99. else{
  100. NSArray *colorArr = @[kBaseColorLeft,kBaseColorRight];
  101. UIImage *image = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, 56.0, 24.0) Colors:colorArr GradientType:0];
  102. [self.allBtn setBackgroundImage:image forState:UIControlStateNormal];
  103. [self.allBtn setTitle:NSLocalString(@"mimo_voice_all_btn_choose") forState:UIControlStateNormal];
  104. [self.allBtn setTitleColor:[MOTools colorWithHexString:@"#FFFFFF" alpha:1.0] forState:UIControlStateNormal];
  105. }
  106. }
  107. - (void)setLinkMics:(NSArray *)linkMics{
  108. _linkMics = linkMics;
  109. NSMutableArray *tempArr = [NSMutableArray array];
  110. if(self.oldSelectUserArr.count != 0){
  111. BOOL isHaveOne = NO;
  112. if(self.anchorUser){
  113. MOUserProfile *object = [self.anchorUser copy];
  114. if(![object.id isEqualToString:GetUserId]){
  115. if([self.oldSelectUserArr containsObject:object.id]){
  116. isHaveOne = YES;
  117. object.isSelect = YES;
  118. if(![self.selectUserArr containsObject:object.id]){
  119. [self.selectUserArr addObject:object.id];
  120. }
  121. }
  122. else{
  123. object.isSelect = NO;
  124. }
  125. [tempArr addObject:object];
  126. }
  127. }
  128. int x = 1;
  129. for (MOLinkMic *object in linkMics) {
  130. if(object.profile.id.length > 0){
  131. MOUserProfile *newObject = [object.profile copy];
  132. if([self.oldSelectUserArr containsObject:newObject.id]){
  133. isHaveOne = YES;
  134. newObject.isSelect = YES;
  135. if(![self.selectUserArr containsObject:newObject.id]){
  136. [self.selectUserArr addObject:newObject.id];
  137. }
  138. }
  139. else{
  140. newObject.isSelect = NO;
  141. }
  142. newObject.seatNum = x;
  143. [tempArr addObject:newObject];
  144. }
  145. x ++;
  146. }
  147. if(!isHaveOne){
  148. MOUserProfile *firstObject = tempArr.firstObject;
  149. firstObject.isSelect = YES;
  150. if(![self.selectUserArr containsObject:firstObject.id]){
  151. [self.selectUserArr addObject:firstObject.id];
  152. }
  153. }
  154. }
  155. else{
  156. if(self.oldArrIsChange){
  157. if(self.anchorUser){
  158. if(![self.anchorUser.id isEqualToString:GetUserId]){//不是自己
  159. MOUserProfile *object = [self.anchorUser copy];
  160. object.isSelect = NO;
  161. [tempArr addObject:object];
  162. }
  163. }
  164. }
  165. else{
  166. if(self.anchorUser){
  167. if(![self.anchorUser.id isEqualToString:GetUserId]){//不是自己
  168. MOUserProfile *object = [self.anchorUser copy];
  169. object.isSelect = YES;
  170. if(![self.selectUserArr containsObject:object.id]){
  171. [self.selectUserArr addObject:object.id];
  172. }
  173. [tempArr addObject:object];
  174. }
  175. }
  176. }
  177. int x = 1;
  178. for (MOLinkMic *object in linkMics) {
  179. if(object.profile.id.length > 0){
  180. MOUserProfile *newObject = [object.profile copy];
  181. newObject.isSelect = NO;
  182. newObject.seatNum = x;
  183. [tempArr addObject:newObject];
  184. }
  185. x ++;
  186. }
  187. }
  188. //排除自己
  189. NSMutableArray *filteredArr = [NSMutableArray array];
  190. NSString *myUserId = GetUserId;
  191. for (MOUserProfile *user in tempArr) {
  192. if (![user.id isEqualToString:myUserId]) {
  193. [filteredArr addObject:user];
  194. }
  195. }
  196. self.dataArr = [filteredArr copy];
  197. if(self.dataArr.count == 0){
  198. self.tipLab.hidden = NO;
  199. self.collectionView.hidden = YES;
  200. }
  201. else{
  202. self.tipLab.hidden = YES;
  203. self.collectionView.hidden = NO;
  204. }
  205. [self.collectionView reloadData];
  206. self.allBtn.hidden = NO;
  207. self.linkMicsView.hidden = YES;
  208. if(self.isSingleLinkMic){
  209. self.allBtn.hidden = YES;
  210. self.tipLab.hidden = YES;
  211. self.collectionView.hidden = YES;
  212. self.linkMicsView.hidden = NO;
  213. if(filteredArr.count == 1){
  214. MOUserProfile *model = filteredArr.firstObject;
  215. [self updateTheLinkMicViewWith:model];
  216. self.selectUserArr = [NSMutableArray arrayWithObject:model.id];
  217. self.oldSelectUserArr = [self.selectUserArr copy];
  218. }
  219. else if (filteredArr.count == 2){
  220. MOUserProfile *model = filteredArr[1];
  221. [self updateTheLinkMicViewWith:model];
  222. self.selectUserArr = [NSMutableArray arrayWithObject:model.id];
  223. self.oldSelectUserArr = [self.selectUserArr copy];
  224. }
  225. }
  226. }
  227. - (void)updateTheLinkMicViewWith:(MOUserProfile *)linkMic{
  228. [self.linkMicImageView sd_setImageWithURL:[NSURL URLWithString:linkMic.avatar] placeholderImage:[UIImage imageNamed:@"icon_mine_placeHolder"]];
  229. self.linkMicName.text = linkMic.nickname;
  230. }
  231. #pragma mark UICollectionViewDelegate,UICollectionViewDataSource
  232. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  233. {
  234. return 1;
  235. }
  236. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  237. {
  238. return self.dataArr.count;
  239. }
  240. -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  241. WEAKSELF
  242. MOUserProfile *model = self.dataArr[indexPath.row];
  243. MOGiftUserCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:MOGiftUserCell_ID forIndexPath:indexPath];
  244. cell.anchorUser = self.anchorUser;
  245. cell.isManage = NO;
  246. cell.cellIndexPath = indexPath;
  247. cell.cellModel = model;
  248. cell.cellStatusChangeBlock = ^(MOUserProfile * _Nonnull cellModel) {
  249. for (MOUserProfile *object in weakSelf.dataArr) {
  250. if([object.id isEqualToString:cellModel.id]){
  251. object.isSelect = cellModel.isSelect;
  252. if(object.isSelect){
  253. if(![weakSelf.selectUserArr containsObject:object.id]){
  254. [weakSelf.selectUserArr addObject:object.id];
  255. }
  256. }
  257. else{
  258. if([weakSelf.selectUserArr containsObject:object.id]){
  259. [weakSelf.selectUserArr removeObject:object.id];
  260. }
  261. }
  262. }
  263. }
  264. weakSelf.oldSelectUserArr = [weakSelf.selectUserArr copy];
  265. weakSelf.oldArrIsChange = YES;
  266. };
  267. return cell;
  268. }
  269. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  270. [collectionView deselectItemAtIndexPath:indexPath animated:YES];
  271. }
  272. #pragma mark - Lazy
  273. - (NSMutableArray *)selectUserArr{
  274. if(!_selectUserArr){
  275. _selectUserArr = [NSMutableArray array];
  276. }
  277. return _selectUserArr;
  278. }
  279. - (UILabel *)tipLab{
  280. if(!_tipLab){
  281. _tipLab = [[UILabel alloc] init];
  282. _tipLab.textColor = [MOTools colorWithHexString:@"#FFFFFF" alpha:0.5];
  283. _tipLab.font = [MOTextTools regularFont:12.0];
  284. _tipLab.text = NSLocalString(@"mimo_2_live_gift_send_0_tip");
  285. _tipLab.hidden = YES;
  286. }
  287. return _tipLab;
  288. }
  289. - (UIView *)linkMicsView{
  290. if(!_linkMicsView){
  291. _linkMicsView = [[UIView alloc] init];
  292. _linkMicsView.backgroundColor = [UIColor clearColor];
  293. }
  294. return _linkMicsView;
  295. }
  296. - (UIImageView *)linkMicImageView{
  297. if(!_linkMicImageView){
  298. _linkMicImageView = [[UIImageView alloc] init];
  299. _linkMicImageView.contentMode = UIViewContentModeScaleAspectFill;
  300. _linkMicImageView.layer.cornerRadius = 16.0;
  301. _linkMicImageView.layer.masksToBounds = YES;
  302. }
  303. return _linkMicImageView;
  304. }
  305. - (UILabel *)linkMicName{
  306. if(!_linkMicName){
  307. _linkMicName = [[UILabel alloc] init];
  308. _linkMicName.textColor = [MOTools colorWithHexString:@"#FFFFFF" alpha:8.0];
  309. _linkMicName.font = [MOTextTools poppinsRegularFont:12.0];
  310. }
  311. return _linkMicName;
  312. }
  313. @end