Files
yinmeng-ios-store/yinmeng-ios/yinmeng-ios/Main/Mew/Party/View/MewPartyViewController.m

217 lines
7.6 KiB
Mathematica
Raw Normal View History

2023-11-20 21:29:45 -08:00
//
// MewPartyViewController.m
// mew-ios
//
// Created by on 2023/11/13.
//
#import "MewPartyViewController.h"
#import "MewMineCollectionViewController.h"
2023-11-20 21:29:45 -08:00
/// View
#import "MewPartyListCollectionViewCell.h"
#import "MewRoomViewController.h"
/// Third
#import <Masonry/Masonry.h>
/// Tool
2023-12-05 18:37:33 +08:00
#import "MewMacro.h"
2023-11-20 21:29:45 -08:00
/// Model
#import "MewPartyModel.h"
2023-12-05 18:37:33 +08:00
#import "MewHomeRecommendRoomModel.h"
2023-11-20 21:29:45 -08:00
/// Presenter
2023-12-05 16:16:54 +08:00
#import "MewPartyPresenter.h"
#import "MewHomeProtocol.h"
@interface MewPartyViewController ()<UICollectionViewDelegate, UICollectionViewDataSource, MewHomeProtocol>
2023-11-20 21:29:45 -08:00
@property (nonatomic, strong) UIImageView *contentBgImageView;
//
@property (nonatomic, strong) UIImageView *partyBgImageView;
//
@property (nonatomic, strong) UIImageView *collectBgImageView;
//
@property (nonatomic, strong) UIImageView *mineCollectImageView;
//
@property (nonatomic, strong) UILabel *mineCollectLabel;
@property (nonatomic, strong) UIView *partyMineCollectView;
@property (nonatomic, strong) UICollectionView *partyCollectionView;
@property (nonatomic, strong) NSArray<MewPartyModel *> *collectModels;
@property (nonatomic, assign) CGSize itemSizes;
@property (nonatomic, assign) CGFloat itemMargin;
2023-12-05 18:37:33 +08:00
@property (nonatomic, strong) NSArray<MewHomeRecommendRoomModel *> *homeRecommendModels;
2023-11-20 21:29:45 -08:00
@end
@implementation MewPartyViewController
2023-12-05 15:49:24 +08:00
- (BOOL)mew_isHiddenNavBar {
2023-11-20 21:29:45 -08:00
return YES;
}
2023-12-05 16:16:54 +08:00
- (MewPartyPresenter *)createPresenter {
return [[MewPartyPresenter alloc] init];
2023-11-20 21:29:45 -08:00
}
#pragma mark - Life Cycle
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = UIColor.whiteColor;
self.collectModels = [MewPartyModel getMewPartyModels];
self.itemMargin = 17.0;
CGFloat itemWidth = (KScreenWidth - 3 * self.itemMargin)/2;
CGSize imageSize = [UIImage imageNamed:self.collectModels[0].imageName].size;
CGFloat itemHeight = (itemWidth * imageSize.height)/imageSize.width;
self.itemSizes = CGSizeMake(itemWidth, itemHeight);
2023-12-05 15:49:24 +08:00
[self mew_initView];
[self mew_loadData];
2023-11-20 21:29:45 -08:00
}
#pragma mark - Load Data
2023-12-05 15:49:24 +08:00
- (void)mew_loadData {
2023-12-05 16:16:54 +08:00
[self.presenter mew_partyRecommendRoomList];
2023-11-20 21:29:45 -08:00
}
2023-12-05 15:49:24 +08:00
#pragma mark - YMHomeProtocol
2023-12-05 16:16:54 +08:00
- (void)mew_partyRecommendRoomListSuccess:(NSArray *)list {
2023-11-20 21:29:45 -08:00
self.homeRecommendModels = list;
[self.partyCollectionView reloadData];
}
#pragma mark - UICollectionViewDelegate, UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.collectModels.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
MewPartyListCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([MewPartyListCollectionViewCell class]) forIndexPath:indexPath];
cell.model = self.collectModels[indexPath.row];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row >= self.homeRecommendModels.count) { return; }
2023-12-05 15:49:24 +08:00
2023-11-20 21:29:45 -08:00
NSString *roomId = self.homeRecommendModels[indexPath.row].roomUid;
[MewRoomViewController openRoom:roomId viewController:self];
}
2023-12-05 15:49:24 +08:00
- (void)mew_gotoWithMineCollection:(UITapGestureRecognizer *)tap {
MewMineCollectionViewController *controller = [[MewMineCollectionViewController alloc] init];
[self.navigationController pushViewController:controller animated:NO];
}
2023-11-20 21:29:45 -08:00
#pragma mark - Init
2023-12-05 15:49:24 +08:00
- (void)mew_initView {
2023-11-20 21:29:45 -08:00
[self.view addSubview:self.contentBgImageView];
[self.view addSubview:self.partyBgImageView];
[self.view addSubview:self.collectBgImageView];
[self.collectBgImageView addSubview:self.mineCollectImageView];
[self.collectBgImageView addSubview:self.mineCollectLabel];
[self.view addSubview:self.partyCollectionView];
2023-12-05 15:49:24 +08:00
[self mew_initLayout];
2023-11-20 21:29:45 -08:00
}
2023-12-05 15:49:24 +08:00
- (void)mew_initLayout {
2023-11-20 21:29:45 -08:00
[self.contentBgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
CGFloat bgHeight = [UIImage imageNamed:@"mew_party_header_bg"].size.height;
[self.partyBgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(14);
make.top.mas_equalTo(kStatusBarHeight+25);
make.height.mas_equalTo(bgHeight);
}];
[self.collectBgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.partyBgImageView);
make.right.mas_equalTo(-20);
}];
[self.mineCollectImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.collectBgImageView);
make.top.equalTo(self.collectBgImageView).offset(10);
}];
[self.mineCollectLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.mineCollectImageView.mas_bottom).offset(4);
make.centerX.equalTo(self.collectBgImageView);
make.height.mas_equalTo(16);
}];
[self.partyCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.collectBgImageView.mas_bottom).offset(28.0);
make.left.right.equalTo(self.view);
make.bottom.mas_equalTo(-kTabBarHeight);
}];
}
#pragma mark - Get
- (UIImageView *)contentBgImageView {
if (!_contentBgImageView) {
_contentBgImageView = [[UIImageView alloc] init];
_contentBgImageView.image = [UIImage imageNamed:@"mew_home_bg"];
}
return _contentBgImageView;
}
- (UIImageView *)partyBgImageView {
if (!_partyBgImageView) {
_partyBgImageView = [[UIImageView alloc] init];
_partyBgImageView.image = [UIImage imageNamed:@"mew_party_header_bg"];
}
return _partyBgImageView;
}
- (UIImageView *)collectBgImageView {
if (!_collectBgImageView) {
_collectBgImageView = [[UIImageView alloc] init];
_collectBgImageView.image = [UIImage imageNamed:@"mew_party_collection_bg"];
_collectBgImageView.userInteractionEnabled = YES;
2023-12-05 15:49:24 +08:00
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(mew_gotoWithMineCollection:)];
[_collectBgImageView addGestureRecognizer:tap];
2023-11-20 21:29:45 -08:00
}
return _collectBgImageView;
}
- (UIImageView *)mineCollectImageView {
if (!_mineCollectImageView) {
_mineCollectImageView = [[UIImageView alloc] init];
_mineCollectImageView.image = [UIImage imageNamed:@"mew_party_mine_collect"];
}
return _mineCollectImageView;
}
- (UILabel *)mineCollectLabel {
if (!_mineCollectLabel) {
_mineCollectLabel = [[UILabel alloc] init];
_mineCollectLabel.text = @"我的收藏";
_mineCollectLabel.textColor = UIColor.whiteColor;
_mineCollectLabel.font = kFontRegular(11);
}
return _mineCollectLabel;
}
- (UICollectionView *)partyCollectionView {
if (!_partyCollectionView) {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.itemSize = self.itemSizes;
layout.minimumInteritemSpacing = 17.0;
layout.minimumLineSpacing = 20.0;
layout.sectionInset = UIEdgeInsetsMake(0, 17.0, 0, 17.0);
_partyCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
_partyCollectionView.backgroundColor = UIColor.clearColor;
_partyCollectionView.delegate = self;
_partyCollectionView.dataSource = self;
_partyCollectionView.showsVerticalScrollIndicator = NO;
[_partyCollectionView registerClass:[MewPartyListCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([MewPartyListCollectionViewCell class])];
}
return _partyCollectionView;
}
@end