Files
peko-ios/YuMi/Modules/YMMine/View/MineInfo/XPMineUserInfoGiftWallSubViewController.m

160 lines
6.1 KiB
Mathematica
Raw Normal View History

2023-07-06 16:54:13 +08:00
//
2023-08-10 18:44:46 +08:00
// XPMineUserInfoGiftWalllSubViewController.m
// xplan-ios
2023-07-06 16:54:13 +08:00
//
2023-08-10 18:44:46 +08:00
// Created by on 2022/6/15.
2023-07-06 16:54:13 +08:00
//
2023-07-14 18:50:55 +08:00
#import "XPMineUserInfoGiftWallSubViewController.h"
///Third
2023-07-06 16:54:13 +08:00
#import <Masonry/Masonry.h>
2023-07-14 18:50:55 +08:00
///Tool
///View
#import "XPMineUserInfoGiftWallCollectionViewCell.h"
#import "XPGuildEmptyCollectionViewCell.h"
///P
#import "XPMineUserInfoGiftWallPresenter.h"
#import "XPMineUserInfoGiftWallProtocol.h"
2023-07-06 16:54:13 +08:00
2023-07-14 18:50:55 +08:00
@interface XPMineUserInfoGiftWallSubViewController ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, XPMineUserInfoGiftWallProtocol>
///
2023-07-06 16:54:13 +08:00
@property (nonatomic,strong) UICollectionView *collectionView;
@property (nonatomic,strong) NSArray *datasource;
2023-08-10 18:44:46 +08:00
@property (nonatomic,assign) NSInteger giftNum;
2023-07-06 16:54:13 +08:00
@end
2023-07-14 18:50:55 +08:00
@implementation XPMineUserInfoGiftWallSubViewController
2023-07-06 16:54:13 +08:00
2023-07-14 18:50:55 +08:00
- (__kindof id)createPresenter {
2023-08-10 18:44:46 +08:00
return [[XPMineUserInfoGiftWallPresenter alloc] init];
2023-07-06 16:54:13 +08:00
}
- (void)viewDidLoad {
2023-08-10 18:44:46 +08:00
[super viewDidLoad];
[self.presenter getUserGiftWall:self.userUid giftType:self.type];
[self initSubViews];
[self initSubViewConstraints];
2023-07-06 16:54:13 +08:00
}
#pragma mark - Private Method
- (void)initSubViews {
2023-08-10 18:44:46 +08:00
self.view.backgroundColor = [UIColor whiteColor];
[self.view addSubview:self.collectionView];
2023-07-06 16:54:13 +08:00
}
2023-07-14 18:50:55 +08:00
- (void)initSubViewConstraints {
2023-08-10 18:44:46 +08:00
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
}];
2023-07-06 16:54:13 +08:00
}
#pragma mark - UICollectionViewDelegate And UICollectionViewDatasource
2023-08-10 18:44:46 +08:00
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
if (self.giftNum == 0)return 1;
return 2;
2023-07-06 16:54:13 +08:00
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
2023-08-10 18:44:46 +08:00
if(self.giftNum > 0){
CGFloat width = KScreenWidth - kGetScaleWidth(60);
return indexPath.section == 0 ? CGSizeMake(width / 3 , kGetScaleWidth(110)): CGSizeMake((width - kGetScaleWidth(15))/4 , kGetScaleWidth(105));
}
return CGSizeMake(KScreenWidth - 30, 65 * 3 + 30);
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
if(self.giftNum > 0){
return section == 0 ? UIEdgeInsetsMake(0, kGetScaleWidth(15), kGetScaleWidth(15), kGetScaleWidth(15)):UIEdgeInsetsMake(0, kGetScaleWidth(15), 0, kGetScaleWidth(15));
}
return UIEdgeInsetsMake(0, 0, 0, 0);
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
if (self.giftNum == 0)return 1;
return [self.datasource[section] count];
2023-07-06 16:54:13 +08:00
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
2023-08-10 18:44:46 +08:00
if (self.giftNum > 0) {
XPMineUserInfoGiftWallCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XPMineUserInfoGiftWallCollectionViewCell class]) forIndexPath:indexPath];
if (indexPath.section == 0 && self.datasource.count > 0){
NSArray *dataList = self.datasource[indexPath.section];
if(indexPath.row < dataList.count){
cell.giftInfo = [dataList xpSafeObjectAtIndex:indexPath.row];
2023-08-10 18:44:46 +08:00
[cell setLevel:((int)indexPath.row + 1)];
}else{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([UICollectionViewCell class]) forIndexPath:indexPath];
return cell;
}
}
if (indexPath.section == 1 && self.datasource.count > 1){
NSArray *dataList = self.datasource[indexPath.section];
if(indexPath.row < dataList.count){
cell.giftInfo = [dataList xpSafeObjectAtIndex:indexPath.row];
2023-08-10 18:44:46 +08:00
}else{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([UICollectionViewCell class]) forIndexPath:indexPath];
return cell;
}
[cell setLevel:4];
}
return cell;
}
XPGuildEmptyCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XPGuildEmptyCollectionViewCell class]) forIndexPath:indexPath];
return cell;
2023-07-06 16:54:13 +08:00
}
2023-08-10 18:44:46 +08:00
2023-07-06 16:54:13 +08:00
#pragma mark - JXCategoryListContentViewDelegate
- (UIView *)listView {
2023-08-10 18:44:46 +08:00
return self.view;
2023-07-06 16:54:13 +08:00
}
2023-07-14 18:50:55 +08:00
#pragma mark - XPMineUserInfoGiftWallProtocol
- (void)getUserGiftWallSuccess:(NSArray *)giftList {
2023-08-10 18:44:46 +08:00
_giftNum = giftList.count ;
NSMutableArray *firstDataSource = [NSMutableArray array];
NSMutableArray *secondDataSource = [NSMutableArray array];
for (int i = 0; i < giftList.count; i++) {
UserGiftWallInfoModel *obj = giftList[i];
if(i < 3){
[firstDataSource addObject:obj];
}else{
[secondDataSource addObject:obj];
}
}
_datasource = @[firstDataSource,secondDataSource];
[self.collectionView reloadData];
2023-07-06 16:54:13 +08:00
}
#pragma mark - Getters And Setters
- (UICollectionView *)collectionView{
2023-08-10 18:44:46 +08:00
if (!_collectionView) {
2024-04-12 15:55:09 +08:00
MSBaseRTLFlowLayout *layout = [[MSBaseRTLFlowLayout alloc] init];
2023-08-10 18:44:46 +08:00
layout.minimumLineSpacing = kGetScaleWidth(15);
layout.minimumInteritemSpacing = 0;
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
_collectionView.dataSource = self;
_collectionView.delegate = self;
_collectionView.pagingEnabled = NO;
_collectionView.backgroundColor = [UIColor clearColor];
[_collectionView registerClass:[XPMineUserInfoGiftWallCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([XPMineUserInfoGiftWallCollectionViewCell class])];
[_collectionView registerClass:[XPGuildEmptyCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([XPGuildEmptyCollectionViewCell class])];
[_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([UICollectionViewCell class])];
}
return _collectionView;
2023-07-06 16:54:13 +08:00
}
2023-08-10 18:44:46 +08:00
2023-07-06 16:54:13 +08:00
@end