159 lines
5.2 KiB
Objective-C
159 lines
5.2 KiB
Objective-C
//
|
|
// MewRightFollowVoiceView.m
|
|
// mew-ios
|
|
//
|
|
// Created by 触海 on 2023/11/10.
|
|
//
|
|
|
|
#import "MewRightFollowVoiceView.h"
|
|
///View
|
|
#import "MewRightFollowVoiceCollectionCell.h"
|
|
/// Third
|
|
#import <Masonry/Masonry.h>
|
|
/// Tool
|
|
#import "YMMacro.h"
|
|
#import "ThemeColor.h"
|
|
#import "FansInfoModel.h"
|
|
#import "UserInfoModel.h"
|
|
#import "NSArray+Safe.h"
|
|
|
|
@interface MewRightFollowVoiceView() <UICollectionViewDelegate, UICollectionViewDataSource>
|
|
|
|
@property (nonatomic, strong) UILabel *followLabel;
|
|
@property (nonatomic, strong) UICollectionView *followCollectionView;
|
|
|
|
///当前页数
|
|
@property (nonatomic,assign) int page;
|
|
|
|
|
|
@end
|
|
|
|
@implementation MewRightFollowVoiceView
|
|
|
|
#pragma mark - Init
|
|
- (instancetype)initWithFrame:(CGRect)frame {
|
|
self = [super initWithFrame:frame];
|
|
if (self) {
|
|
[self initView];
|
|
[self initHeaderAndFooterRrfresh];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
#pragma mark - Set
|
|
- (void)setFansListModel:(NSArray<UserInfoModel *> *)fansListModel {
|
|
_fansListModel = fansListModel;
|
|
[self.followCollectionView reloadData];
|
|
}
|
|
|
|
#pragma mark - UICollectionViewDelegate, UICollectionViewDataSource
|
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
|
return self.fansListModel.count;
|
|
}
|
|
|
|
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
MewRightFollowVoiceCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([MewRightFollowVoiceCollectionCell class]) forIndexPath:indexPath];
|
|
UserInfoModel *model = [self.fansListModel safeObjectAtIndex1:indexPath.row];
|
|
cell.avater = model.avatar;
|
|
cell.nick = model.nick;
|
|
cell.sex = model.gender;
|
|
return cell;
|
|
}
|
|
|
|
|
|
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
if (self.delegate) {
|
|
[self.delegate didSelectRightFollowVoiceUser:self.fansListModel[indexPath.row]];
|
|
}
|
|
}
|
|
|
|
|
|
#pragma mark - Init View
|
|
- (void)initView {
|
|
[self addSubview:self.followLabel];
|
|
[self addSubview:self.followCollectionView];
|
|
[self initLayout];
|
|
}
|
|
|
|
- (void)initLayout {
|
|
[self.followLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.equalTo(self);
|
|
make.top.mas_equalTo(20);
|
|
}];
|
|
|
|
[self.followCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.equalTo(self.followLabel.mas_bottom).offset(20);
|
|
make.left.right.bottom.equalTo(self);
|
|
}];
|
|
}
|
|
|
|
#pragma mark - 下拉刷新
|
|
- (void)initHeaderAndFooterRrfresh {
|
|
MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(headerRefresh)];
|
|
header.stateLabel.font = [UIFont systemFontOfSize:10.0];
|
|
header.lastUpdatedTimeLabel.font = [UIFont systemFontOfSize:10.0];
|
|
header.stateLabel.textColor = [ThemeColor secondTextColor];
|
|
header.lastUpdatedTimeLabel.textColor = [ThemeColor secondTextColor];
|
|
self.followCollectionView.mj_header = header;
|
|
|
|
MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(footerRefresh)];
|
|
footer.stateLabel.textColor = [ThemeColor secondTextColor];
|
|
footer.stateLabel.font = [UIFont systemFontOfSize:10.0];
|
|
self.followCollectionView.mj_footer = footer;
|
|
|
|
[self headerRefresh];
|
|
}
|
|
|
|
#pragma mark - 刷新的fangfa
|
|
- (void)headerRefresh {
|
|
if (self.loadFollownRefresh) {
|
|
self.loadFollownRefresh();
|
|
}
|
|
// self.page = 1;
|
|
// [self.presenter getUserAttentionList:self.page pageSize:20 state:0];
|
|
}
|
|
|
|
- (void)footerRefresh {
|
|
if (self.moreFollownRefresh) {
|
|
self.moreFollownRefresh();
|
|
}
|
|
// if (self.hasNoMoreData) {
|
|
// [self showErrorToast:@"没有更多数据了"];
|
|
// return;
|
|
// }
|
|
// self.page++;
|
|
// [self.presenter getUserAttentionList:self.page pageSize:20 state:1];
|
|
}
|
|
|
|
|
|
#pragma mark - Get
|
|
- (UILabel *)followLabel {
|
|
if (!_followLabel) {
|
|
_followLabel = [[UILabel alloc] init];
|
|
_followLabel.text = @"我关注的声音";
|
|
_followLabel.textColor = UIColor.whiteColor;
|
|
_followLabel.font = kFontSemibold(16);
|
|
_followLabel.textAlignment = NSTextAlignmentCenter;
|
|
}
|
|
return _followLabel;
|
|
}
|
|
|
|
- (UICollectionView *)followCollectionView {
|
|
if (!_followCollectionView) {
|
|
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
|
layout.minimumLineSpacing = 16;
|
|
layout.minimumInteritemSpacing = 10;
|
|
layout.sectionInset = UIEdgeInsetsMake(0.0, 12.0, 0.0, 12.0);
|
|
CGFloat width = ((2 * (KScreenWidth - 48) / 3.0) - 40 - 2*12.0 - 10.0) / 2.0;
|
|
layout.itemSize = CGSizeMake(width, width + 20);
|
|
_followCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
|
|
_followCollectionView.delegate = self;
|
|
_followCollectionView.dataSource = self;
|
|
_followCollectionView.backgroundColor = UIColor.clearColor;
|
|
[_followCollectionView registerClass:[MewRightFollowVoiceCollectionCell class] forCellWithReuseIdentifier:NSStringFromClass([MewRightFollowVoiceCollectionCell class])];
|
|
}
|
|
return _followCollectionView;
|
|
}
|
|
|
|
@end
|