| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379 |
- //
- // MOGiftUserView.m
- // MiMoLive
- //
- // Created by SuperC on 2024/8/19.
- //
- #import "MOGiftUserView.h"
- #import "MOGiftUserCell.h"
- @interface MOGiftUserView ()<UICollectionViewDelegate,UICollectionViewDataSource>
- @property (weak, nonatomic) IBOutlet UILabel *tagLab;
- @property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
- @property (nonatomic, strong) UILabel *tipLab;
- @property (weak, nonatomic) IBOutlet BigBtn *allBtn;
- @property (nonatomic, strong) NSArray *dataArr;
- @property (nonatomic, assign) BOOL isAllChoose;
- @property (nonatomic, assign) BOOL oldArrIsChange;
- @property (nonatomic, strong) UIView *linkMicsView;
- @property (nonatomic, strong) UIImageView *linkMicImageView;
- @property (nonatomic, strong) UILabel *linkMicName;
- @end
- @implementation MOGiftUserView
- + (instancetype)moGiftUserView{
- return [[[NSBundle mainBundle] loadNibNamed:@"MOGiftUserView" owner:self options:nil] firstObject];
- }
- - (void)awakeFromNib{
- [super awakeFromNib];
-
- self.isAllChoose = NO;
-
- self.tagLab.text = NSLocalString(@"mimo_2_live_send_gift_tag");
-
- self.allBtn.layer.cornerRadius = 8.0;
- self.allBtn.layer.masksToBounds = YES;
-
- UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init];
-
- CGFloat width = 50.0;
- CGFloat height = 50.0;
- flow.scrollDirection = UICollectionViewScrollDirectionHorizontal;
- flow.itemSize = CGSizeMake(width, height);
- flow.minimumLineSpacing = 0.0;//行间距
- flow.minimumInteritemSpacing = 0.0;//列间距
- [self.collectionView setCollectionViewLayout:flow];
- self.collectionView.delegate = self;
- self.collectionView.dataSource = self;
- [self.collectionView registerNib:[UINib nibWithNibName:@"MOGiftUserCell" bundle:nil] forCellWithReuseIdentifier:MOGiftUserCell_ID];
-
- [self.allBtn setFont:[MOTextTools poppinsRegularFont:12.0]];
- self.tagLab.font = [MOTextTools regularFont:12.0];
-
- self.layer.cornerRadius = 16.0;
- self.layer.masksToBounds = YES;
- self.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner;
-
- [self addSubview:self.tipLab];
- [self.tipLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self.collectionView);
- }];
- self.tipLab.hidden = YES;
-
- [self addSubview:self.linkMicsView];
- [self.linkMicsView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self).offset(80.0);
- make.top.bottom.equalTo(self);
- make.right.equalTo(self).offset(-0.0);
- }];
- self.linkMicsView.hidden = YES;
-
- [self.linkMicsView addSubview:self.linkMicImageView];
- [self.linkMicImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.linkMicsView).offset(10.0);
- make.centerY.equalTo(self.linkMicsView);
- make.width.height.equalTo(@32.0);
- }];
-
- [self.linkMicsView addSubview:self.linkMicName];
- [self.linkMicName mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.linkMicImageView.mas_right).offset(6.0);
- make.centerY.equalTo(self.linkMicsView);
- make.right.equalTo(self.linkMicsView).offset(-10.0);
- }];
-
- }
- - (IBAction)allBtnClick:(id)sender {
-
- [self.selectUserArr removeAllObjects];
-
- self.isAllChoose = !self.isAllChoose;
- if(self.isAllChoose){
- for (MOUserProfile *object in self.dataArr) {
- object.isSelect = YES;
- [self.selectUserArr addObject:object.id];
- }
- }
- else{
- for (MOUserProfile *object in self.dataArr) {
- object.isSelect = NO;
- }
- }
-
- self.oldSelectUserArr = [self.selectUserArr copy];
- self.oldArrIsChange = YES;
- [self.collectionView reloadData];
- }
- - (void)setIsAllChoose:(BOOL)isAllChoose{
- _isAllChoose = isAllChoose;
-
- if(isAllChoose){
- NSArray *colorArr = @[[MOTools colorWithHexString:@"#FFFFFF" alpha:0.06],[MOTools colorWithHexString:@"#FFFFFF" alpha:0.06]];
- UIImage *image = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, 56.0, 24.0) Colors:colorArr GradientType:0];
- [self.allBtn setBackgroundImage:image forState:UIControlStateNormal];
-
- [self.allBtn setTitle:NSLocalString(@"mimo_voice_all_btn_no_choose") forState:UIControlStateNormal];
- [self.allBtn setTitleColor:[MOTools colorWithHexString:@"#FFFFFF" alpha:0.5] forState:UIControlStateNormal];
- }
- else{
- NSArray *colorArr = @[kBaseColorLeft,kBaseColorRight];
- UIImage *image = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, 56.0, 24.0) Colors:colorArr GradientType:0];
- [self.allBtn setBackgroundImage:image forState:UIControlStateNormal];
-
- [self.allBtn setTitle:NSLocalString(@"mimo_voice_all_btn_choose") forState:UIControlStateNormal];
- [self.allBtn setTitleColor:[MOTools colorWithHexString:@"#FFFFFF" alpha:1.0] forState:UIControlStateNormal];
- }
- }
- - (void)setLinkMics:(NSArray *)linkMics{
- _linkMics = linkMics;
-
- NSMutableArray *tempArr = [NSMutableArray array];
- if(self.oldSelectUserArr.count != 0){
-
- BOOL isHaveOne = NO;
-
- if(self.anchorUser){
- MOUserProfile *object = [self.anchorUser copy];
-
- if(![object.id isEqualToString:GetUserId]){
- if([self.oldSelectUserArr containsObject:object.id]){
- isHaveOne = YES;
- object.isSelect = YES;
- if(![self.selectUserArr containsObject:object.id]){
- [self.selectUserArr addObject:object.id];
- }
- }
- else{
- object.isSelect = NO;
- }
- [tempArr addObject:object];
- }
- }
-
- int x = 1;
- for (MOLinkMic *object in linkMics) {
- if(object.profile.id.length > 0){
- MOUserProfile *newObject = [object.profile copy];
-
- if([self.oldSelectUserArr containsObject:newObject.id]){
- isHaveOne = YES;
- newObject.isSelect = YES;
- if(![self.selectUserArr containsObject:newObject.id]){
- [self.selectUserArr addObject:newObject.id];
- }
- }
- else{
- newObject.isSelect = NO;
- }
- newObject.seatNum = x;
- [tempArr addObject:newObject];
- }
- x ++;
- }
-
- if(!isHaveOne){
- MOUserProfile *firstObject = tempArr.firstObject;
- firstObject.isSelect = YES;
- if(![self.selectUserArr containsObject:firstObject.id]){
- [self.selectUserArr addObject:firstObject.id];
- }
- }
-
- }
- else{
-
- if(self.oldArrIsChange){
- if(self.anchorUser){
- if(![self.anchorUser.id isEqualToString:GetUserId]){//不是自己
- MOUserProfile *object = [self.anchorUser copy];
- object.isSelect = NO;
- [tempArr addObject:object];
- }
- }
- }
- else{
- if(self.anchorUser){
- if(![self.anchorUser.id isEqualToString:GetUserId]){//不是自己
- MOUserProfile *object = [self.anchorUser copy];
- object.isSelect = YES;
- if(![self.selectUserArr containsObject:object.id]){
- [self.selectUserArr addObject:object.id];
- }
- [tempArr addObject:object];
- }
- }
- }
- int x = 1;
- for (MOLinkMic *object in linkMics) {
- if(object.profile.id.length > 0){
- MOUserProfile *newObject = [object.profile copy];
- newObject.isSelect = NO;
- newObject.seatNum = x;
- [tempArr addObject:newObject];
- }
- x ++;
- }
- }
-
- //排除自己
- NSMutableArray *filteredArr = [NSMutableArray array];
- NSString *myUserId = GetUserId;
- for (MOUserProfile *user in tempArr) {
- if (![user.id isEqualToString:myUserId]) {
- [filteredArr addObject:user];
- }
- }
-
- self.dataArr = [filteredArr copy];
-
- if(self.dataArr.count == 0){
- self.tipLab.hidden = NO;
- self.collectionView.hidden = YES;
- }
- else{
- self.tipLab.hidden = YES;
- self.collectionView.hidden = NO;
- }
-
- [self.collectionView reloadData];
-
- self.allBtn.hidden = NO;
- self.linkMicsView.hidden = YES;
-
- if(self.isSingleLinkMic){
- self.allBtn.hidden = YES;
- self.tipLab.hidden = YES;
- self.collectionView.hidden = YES;
- self.linkMicsView.hidden = NO;
-
- if(filteredArr.count == 1){
- MOUserProfile *model = filteredArr.firstObject;
- [self updateTheLinkMicViewWith:model];
- self.selectUserArr = [NSMutableArray arrayWithObject:model.id];
- self.oldSelectUserArr = [self.selectUserArr copy];
- }
- else if (filteredArr.count == 2){
- MOUserProfile *model = filteredArr[1];
- [self updateTheLinkMicViewWith:model];
- self.selectUserArr = [NSMutableArray arrayWithObject:model.id];
- self.oldSelectUserArr = [self.selectUserArr copy];
- }
- }
- }
- - (void)updateTheLinkMicViewWith:(MOUserProfile *)linkMic{
- [self.linkMicImageView sd_setImageWithURL:[NSURL URLWithString:linkMic.avatar] placeholderImage:[UIImage imageNamed:@"icon_mine_placeHolder"]];
- self.linkMicName.text = linkMic.nickname;
- }
- #pragma mark UICollectionViewDelegate,UICollectionViewDataSource
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
- {
- return 1;
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
- {
- return self.dataArr.count;
- }
- -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
- WEAKSELF
- MOUserProfile *model = self.dataArr[indexPath.row];
- MOGiftUserCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:MOGiftUserCell_ID forIndexPath:indexPath];
-
- cell.anchorUser = self.anchorUser;
- cell.isManage = NO;
- cell.cellIndexPath = indexPath;
- cell.cellModel = model;
- cell.cellStatusChangeBlock = ^(MOUserProfile * _Nonnull cellModel) {
- for (MOUserProfile *object in weakSelf.dataArr) {
- if([object.id isEqualToString:cellModel.id]){
- object.isSelect = cellModel.isSelect;
-
- if(object.isSelect){
- if(![weakSelf.selectUserArr containsObject:object.id]){
- [weakSelf.selectUserArr addObject:object.id];
- }
- }
- else{
- if([weakSelf.selectUserArr containsObject:object.id]){
- [weakSelf.selectUserArr removeObject:object.id];
- }
- }
- }
- }
-
- weakSelf.oldSelectUserArr = [weakSelf.selectUserArr copy];
- weakSelf.oldArrIsChange = YES;
- };
- return cell;
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
- [collectionView deselectItemAtIndexPath:indexPath animated:YES];
- }
- #pragma mark - Lazy
- - (NSMutableArray *)selectUserArr{
- if(!_selectUserArr){
- _selectUserArr = [NSMutableArray array];
- }
- return _selectUserArr;
- }
- - (UILabel *)tipLab{
- if(!_tipLab){
- _tipLab = [[UILabel alloc] init];
- _tipLab.textColor = [MOTools colorWithHexString:@"#FFFFFF" alpha:0.5];
- _tipLab.font = [MOTextTools regularFont:12.0];
- _tipLab.text = NSLocalString(@"mimo_2_live_gift_send_0_tip");
- _tipLab.hidden = YES;
- }
- return _tipLab;
- }
- - (UIView *)linkMicsView{
- if(!_linkMicsView){
- _linkMicsView = [[UIView alloc] init];
- _linkMicsView.backgroundColor = [UIColor clearColor];
- }
- return _linkMicsView;
- }
- - (UIImageView *)linkMicImageView{
- if(!_linkMicImageView){
- _linkMicImageView = [[UIImageView alloc] init];
- _linkMicImageView.contentMode = UIViewContentModeScaleAspectFill;
- _linkMicImageView.layer.cornerRadius = 16.0;
- _linkMicImageView.layer.masksToBounds = YES;
- }
- return _linkMicImageView;
- }
- - (UILabel *)linkMicName{
- if(!_linkMicName){
- _linkMicName = [[UILabel alloc] init];
- _linkMicName.textColor = [MOTools colorWithHexString:@"#FFFFFF" alpha:8.0];
- _linkMicName.font = [MOTextTools poppinsRegularFont:12.0];
- }
- return _linkMicName;
- }
- @end
|