// // XPRoomRecommendView.m // xplan-ios // // Created by GreenLand on 2022/4/28. // #import "XPRoomRecommendView.h" ///Third #import ///Tool #import "XPMacro.h" #import "ThemeColor.h" ///View #import "XPRoomInsideRecommendCell.h" #import "XPRoomInsideRecommendEmptyCell.h" #import "XPRoomInsideOperationCell.h" @interface XPRoomRecommendView () ///模糊背景 @property (nonatomic, strong) UIToolbar *toolBar; @property (nonatomic, strong) UITableView *tableView; @property (nonatomic, strong) UICollectionView *collectionView; @property (nonatomic, strong) NSMutableArray *titleArray; @property (nonatomic, strong) NSMutableArray *imageArray; ///为你推荐 @property (nonatomic, strong) UILabel *recommentLabel; @end @implementation XPRoomRecommendView - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { [self setUpUI]; [self setUpConstraints]; } return self; } #pragma mark - lifeCycle - (void)setUpUI { [self addSubview:self.toolBar]; [self addSubview:self.collectionView]; [self addSubview:self.recommentLabel]; [self addSubview:self.tableView]; } - (void)setRoomList:(NSMutableArray *)roomList { _roomList = roomList; [self.tableView reloadData]; } #pragma mark - Constraints - (void)setUpConstraints { [self.toolBar mas_makeConstraints:^(MASConstraintMaker *make) { make.top.left.right.bottom.mas_equalTo(self); }]; [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.mas_equalTo(0); make.top.mas_equalTo(kStatusBarHeight + 8); make.height.mas_equalTo(82*2); }]; [self.recommentLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.collectionView.mas_bottom).mas_offset(16); make.left.mas_equalTo(11); }]; [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.bottom.mas_equalTo(0); make.top.mas_equalTo(self.recommentLabel.mas_bottom); }]; } #pragma mark - UICollectionViewDataSource - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.titleArray.count; } - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { XPRoomInsideOperationCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XPRoomInsideOperationCell class]) forIndexPath:indexPath]; cell.title = self.titleArray[indexPath.row]; cell.imageName = self.imageArray[indexPath.row]; return cell; } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row == 0) {//最小化房间 if (self.delegate && [self.delegate respondsToSelector:@selector(xPRoomRecommendViewMiniRoom)]) { [self.delegate xPRoomRecommendViewMiniRoom]; } } else if (indexPath.row == 1) {//分享房间 if (self.delegate && [self.delegate respondsToSelector:@selector(xPRoomRecommendViewShare)]) { [self.delegate xPRoomRecommendViewShare]; } } else if (indexPath.row == 2) {//退出房间 if (self.delegate && [self.delegate respondsToSelector:@selector(xPRoomRecommendViewExitRoom)]) { [self.delegate xPRoomRecommendViewExitRoom]; } } else {//举报房间 if (self.delegate && [self.delegate respondsToSelector:@selector(xPRoomRecommendViewReport)]) { [self.delegate xPRoomRecommendViewReport]; } } } #pragma mark - UITableViewDelegate - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.roomList.count ? self.roomList.count : 1; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if (self.roomList.count > 0) { XPRoomInsideRecommendCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPRoomInsideRecommendCell class])]; XPRoomRecommendModel *model = self.roomList[indexPath.row]; cell.model = model; return cell; } XPRoomInsideRecommendEmptyCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPRoomInsideRecommendEmptyCell class])]; if (cell == nil) { cell = [[XPRoomInsideRecommendEmptyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPRoomInsideRecommendEmptyCell class])]; } return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; if (self.roomList.count > 0) { XPRoomRecommendModel *model = self.roomList[indexPath.row]; if (self.delegate && [self.delegate respondsToSelector:@selector(xPRoomRecommendViewJumpToRoom:)]) { [self.delegate xPRoomRecommendViewJumpToRoom:[NSString stringWithFormat:@"%ld", model.uid]]; } } } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return self.roomList.count > 0 ? 84 : KScreenHeight - kStatusBarHeight -8 - 120; } #pragma mark - getter - (UIToolbar *)toolBar { if (!_toolBar) { _toolBar = [[UIToolbar alloc] init]; _toolBar.barStyle = UIBarStyleBlack; _toolBar.translucent = YES; } return _toolBar; } - (UILabel *)recommentLabel { if (!_recommentLabel) { _recommentLabel = [[UILabel alloc] init]; _recommentLabel.text = @"为你推荐"; _recommentLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium]; _recommentLabel.textColor = [UIColor whiteColor]; } return _recommentLabel; } - (UITableView *)tableView { if (!_tableView) { _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]; _tableView.delegate = self; _tableView.dataSource = self; _tableView.separatorStyle = UITableViewCellSeparatorStyleNone; _tableView.showsVerticalScrollIndicator = NO; [_tableView registerClass:[XPRoomInsideRecommendCell class] forCellReuseIdentifier:NSStringFromClass([XPRoomInsideRecommendCell class])]; [_tableView registerClass:[XPRoomInsideRecommendEmptyCell class] forCellReuseIdentifier:NSStringFromClass([XPRoomInsideRecommendEmptyCell class])]; _tableView.backgroundColor = [UIColor clearColor]; } return _tableView; } - (UICollectionView *)collectionView { if (!_collectionView) { UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; layout.scrollDirection = UICollectionViewScrollDirectionVertical; layout.minimumLineSpacing = 14; layout.minimumInteritemSpacing = (250 - 3 * 52) / 4; layout.itemSize = CGSizeMake(52, 68); layout.sectionInset = UIEdgeInsetsMake(0, (250 - 3 * 52) / 4, 0, (250 - 3 * 52) / 4); _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout]; [_collectionView registerClass:[XPRoomInsideOperationCell class] forCellWithReuseIdentifier:NSStringFromClass([XPRoomInsideOperationCell class])]; _collectionView.delegate = self; _collectionView.dataSource = self; _collectionView.backgroundColor = [UIColor clearColor]; } return _collectionView; } - (NSMutableArray *)titleArray { if (!_titleArray) { _titleArray = [NSMutableArray arrayWithObjects:@"收起房间", @"分享房间", @"退出房间", @"举报房间", nil]; } return _titleArray; } - (NSMutableArray *)imageArray { if (!_imageArray) { _imageArray = [NSMutableArray arrayWithObjects:@"room_info_mini", @"room_info_share", @"room_info_exit", @"room_info_report", nil]; } return _imageArray; } @end