160 lines
6.1 KiB
Objective-C
160 lines
6.1 KiB
Objective-C
//
|
|
// XPMineUserInfoGiftWalllSubViewController.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2022/6/15.
|
|
//
|
|
|
|
#import "XPMineUserInfoGiftWallSubViewController.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
///Tool
|
|
///View
|
|
#import "XPMineUserInfoGiftWallCollectionViewCell.h"
|
|
#import "XPGuildEmptyCollectionViewCell.h"
|
|
///P
|
|
#import "XPMineUserInfoGiftWallPresenter.h"
|
|
#import "XPMineUserInfoGiftWallProtocol.h"
|
|
|
|
@interface XPMineUserInfoGiftWallSubViewController ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, XPMineUserInfoGiftWallProtocol>
|
|
///列表
|
|
@property (nonatomic,strong) UICollectionView *collectionView;
|
|
@property (nonatomic,strong) NSArray *datasource;
|
|
@property (nonatomic,assign) NSInteger giftNum;
|
|
@end
|
|
|
|
@implementation XPMineUserInfoGiftWallSubViewController
|
|
|
|
- (__kindof id)createPresenter {
|
|
return [[XPMineUserInfoGiftWallPresenter alloc] init];
|
|
}
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
[self.presenter getUserGiftWall:self.userUid giftType:self.type];
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
}
|
|
#pragma mark - Private Method
|
|
- (void)initSubViews {
|
|
self.view.backgroundColor = [UIColor whiteColor];
|
|
[self.view addSubview:self.collectionView];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.mas_equalTo(self.view);
|
|
}];
|
|
}
|
|
|
|
#pragma mark - UICollectionViewDelegate And UICollectionViewDatasource
|
|
|
|
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
|
|
if (self.giftNum == 0)return 1;
|
|
return 2;
|
|
|
|
|
|
}
|
|
|
|
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
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];
|
|
}
|
|
|
|
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
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 safeObjectAtIndex1:indexPath.row];
|
|
[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 safeObjectAtIndex1:indexPath.row];
|
|
}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;
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - JXCategoryListContentViewDelegate
|
|
- (UIView *)listView {
|
|
return self.view;
|
|
}
|
|
|
|
#pragma mark - XPMineUserInfoGiftWallProtocol
|
|
- (void)getUserGiftWallSuccess:(NSArray *)giftList {
|
|
_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];
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (UICollectionView *)collectionView{
|
|
if (!_collectionView) {
|
|
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
|
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;
|
|
}
|
|
|
|
|
|
|
|
@end
|