2022-11-17 18:58:56 +08:00
|
|
|
//
|
|
|
|
// XPSessionListHeadView.m
|
|
|
|
// xplan-ios
|
|
|
|
//
|
|
|
|
// Created by GreenLand on 2022/11/17.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "XPSessionListHeadView.h"
|
|
|
|
#import <Masonry/Masonry.h>
|
|
|
|
#import "UIImage+Utils.h"
|
|
|
|
#import "ThemeColor.h"
|
|
|
|
#import "ClientConfig.h"
|
|
|
|
#import "UserInfoModel.h"
|
|
|
|
#import "XPSessionListHeadItem.h"
|
|
|
|
#import "XPSessionListHeadItemView.h"
|
|
|
|
#import "XPSessionListHeadFriendCell.h"
|
|
|
|
|
2022-11-18 19:12:35 +08:00
|
|
|
NSString * const kMengXinShowReadDotKey = @"kMengXinShowReadDotKey";
|
|
|
|
|
2022-11-17 18:58:56 +08:00
|
|
|
@interface XPSessionListHeadView()<UICollectionViewDelegate, UICollectionViewDataSource>
|
|
|
|
|
|
|
|
@property (nonatomic, strong) UIStackView *mainStackView;
|
|
|
|
///工具条
|
|
|
|
@property (nonatomic, strong) UIStackView *toolStackView;
|
|
|
|
///好友容器
|
|
|
|
@property (nonatomic, strong) UIView *friendContentView;
|
|
|
|
///好友派对view
|
|
|
|
@property (nonatomic, strong) UIImageView *partyView;
|
|
|
|
///好友派对中~
|
|
|
|
@property (nonatomic, strong) UIButton *partyButton;
|
|
|
|
///好友列表
|
|
|
|
@property (nonatomic, strong) UICollectionView *collectionView;
|
|
|
|
|
|
|
|
///工具item集合
|
|
|
|
@property (nonatomic, strong) NSMutableArray *funtionArray;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation XPSessionListHeadView
|
|
|
|
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame {
|
|
|
|
if (self = [super initWithFrame:frame]) {
|
|
|
|
[self initItemData];
|
|
|
|
[self initView];
|
|
|
|
[self initContraints];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)initItemData {
|
|
|
|
XPSessionListHeadItem *officeItem = [[XPSessionListHeadItem alloc] init];
|
|
|
|
officeItem.title = @"官方公告";
|
|
|
|
officeItem.imageName = @"session_list_head_office";
|
|
|
|
officeItem.type = XPSessionListHeadItemType_Office;
|
|
|
|
|
|
|
|
XPSessionListHeadItem *activityItem = [[XPSessionListHeadItem alloc] init];
|
|
|
|
activityItem.title = @"活动通知";
|
|
|
|
activityItem.imageName = @"session_list_head_activity";
|
|
|
|
activityItem.type = XPSessionListHeadItemType_Activity;
|
|
|
|
|
|
|
|
XPSessionListHeadItem *subscribeItem = [[XPSessionListHeadItem alloc] init];
|
|
|
|
subscribeItem.title = @"订阅提醒";
|
|
|
|
subscribeItem.imageName = @"session_list_head_subscribe";
|
|
|
|
subscribeItem.type = XPSessionListHeadItemType_Subscribe;
|
|
|
|
|
|
|
|
[self.funtionArray addObject:officeItem];
|
|
|
|
[self.funtionArray addObject:activityItem];
|
|
|
|
[self.funtionArray addObject:subscribeItem];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)initView {
|
|
|
|
[self addSubview:self.mainStackView];
|
|
|
|
[self.mainStackView addArrangedSubview:self.toolStackView];
|
|
|
|
[self.mainStackView addArrangedSubview:self.friendContentView];
|
|
|
|
for (XPSessionListHeadItem *item in self.funtionArray) {
|
|
|
|
XPSessionListHeadItemView *itemView = [[XPSessionListHeadItemView alloc] init];
|
|
|
|
itemView.imageName = item.imageName;
|
|
|
|
itemView.title = item.title;
|
|
|
|
itemView.showDot = item.showRedDot;
|
|
|
|
itemView.tag = item.type;
|
|
|
|
[self.toolStackView addArrangedSubview:itemView];
|
|
|
|
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapItem:)];
|
|
|
|
[itemView addGestureRecognizer:tap];
|
|
|
|
}
|
|
|
|
[self.friendContentView addSubview:self.partyView];
|
|
|
|
[self.partyView addSubview:self.partyButton];
|
|
|
|
[self.friendContentView addSubview:self.collectionView];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)initContraints {
|
|
|
|
[self.mainStackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.edges.mas_equalTo(0);
|
|
|
|
}];
|
|
|
|
[self.partyView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.left.mas_equalTo(26);
|
|
|
|
make.top.mas_equalTo(12);
|
|
|
|
make.size.mas_equalTo(CGSizeMake(82, 16));
|
|
|
|
}];
|
|
|
|
[self.partyButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.edges.mas_equalTo(0);
|
|
|
|
}];
|
|
|
|
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.left.mas_equalTo(16);
|
|
|
|
make.right.mas_equalTo(-16);
|
|
|
|
make.height.mas_equalTo(82);
|
|
|
|
make.top.mas_equalTo(self.partyView.mas_bottom);
|
|
|
|
make.bottom.mas_equalTo(0);
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - UICollectionViewDelegate
|
|
|
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
|
|
|
return self.friendsArray.count;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
XPSessionListHeadFriendCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XPSessionListHeadFriendCell class]) forIndexPath:indexPath];
|
|
|
|
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)updateToolViewWithUserLevel:(NSInteger)level {
|
|
|
|
if( [ClientConfig shareConfig].configInfo.findNewbieCharmLevel <= level) {
|
|
|
|
XPSessionListHeadItem *mengxinItem = [[XPSessionListHeadItem alloc] init];
|
|
|
|
mengxinItem.title = @"发现萌新";
|
|
|
|
mengxinItem.imageName = @"session_list_head_mengxin";
|
|
|
|
mengxinItem.type = XPSessionListHeadItemType_MemgXin;
|
|
|
|
[self.funtionArray addObject:mengxinItem];
|
|
|
|
|
|
|
|
XPSessionListHeadItemView *itemView = [[XPSessionListHeadItemView alloc] init];
|
|
|
|
itemView.imageName = mengxinItem.imageName;
|
|
|
|
itemView.title = mengxinItem.title;
|
2022-11-18 19:12:35 +08:00
|
|
|
BOOL hidden = [[NSUserDefaults standardUserDefaults] boolForKey:kMengXinShowReadDotKey];
|
|
|
|
itemView.showDot = !hidden;
|
2022-11-17 18:58:56 +08:00
|
|
|
itemView.tag = mengxinItem.type;
|
|
|
|
[self.toolStackView addArrangedSubview:itemView];
|
|
|
|
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapItem:)];
|
|
|
|
[itemView addGestureRecognizer:tap];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)tapItem:(UITapGestureRecognizer *)ges {
|
|
|
|
XPSessionListHeadItemView *view = (XPSessionListHeadItemView *)ges.view;
|
|
|
|
switch (view.tag) {
|
|
|
|
case XPSessionListHeadItemType_Office:
|
|
|
|
{
|
2022-11-18 19:12:35 +08:00
|
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(XPSessionListHeadViewDidClickOffice)]) {
|
|
|
|
[self.delegate XPSessionListHeadViewDidClickOffice];
|
|
|
|
}
|
2022-11-17 18:58:56 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case XPSessionListHeadItemType_Activity:
|
|
|
|
{
|
2022-11-18 19:12:35 +08:00
|
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(XPSessionListHeadViewDidClickActivity)]) {
|
|
|
|
[self.delegate XPSessionListHeadViewDidClickActivity];
|
|
|
|
}
|
2022-11-17 18:58:56 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case XPSessionListHeadItemType_Subscribe:
|
|
|
|
{
|
2022-11-18 19:12:35 +08:00
|
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(XPSessionListHeadViewDidClickSubscribe)]) {
|
|
|
|
[self.delegate XPSessionListHeadViewDidClickSubscribe];
|
|
|
|
}
|
2022-11-17 18:58:56 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case XPSessionListHeadItemType_MemgXin:
|
|
|
|
{
|
2022-11-18 19:12:35 +08:00
|
|
|
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:kMengXinShowReadDotKey];
|
|
|
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
|
|
|
XPSessionListHeadItemView *itemView = [self.toolStackView.subviews lastObject];
|
|
|
|
itemView.showDot = NO;
|
|
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(XPSessionListHeadViewDidClickMengxin)]) {
|
|
|
|
[self.delegate XPSessionListHeadViewDidClickMengxin];
|
|
|
|
}
|
2022-11-17 18:58:56 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UIStackView *)mainStackView {
|
|
|
|
if (!_mainStackView) {
|
|
|
|
_mainStackView = [[UIStackView alloc] init];
|
|
|
|
_mainStackView.axis = UILayoutConstraintAxisVertical;
|
|
|
|
_mainStackView.distribution = UIStackViewDistributionFill;
|
|
|
|
_mainStackView.alignment = UIStackViewAlignmentFill;
|
|
|
|
}
|
|
|
|
return _mainStackView;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UIStackView *)toolStackView {
|
|
|
|
if (!_toolStackView) {
|
|
|
|
_toolStackView = [[UIStackView alloc] init];
|
|
|
|
_toolStackView.axis = UILayoutConstraintAxisHorizontal;
|
|
|
|
_toolStackView.distribution = UIStackViewDistributionFillEqually;
|
|
|
|
_toolStackView.alignment = UIStackViewAlignmentCenter;
|
|
|
|
}
|
|
|
|
return _toolStackView;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSMutableArray *)funtionArray {
|
|
|
|
if (!_funtionArray) {
|
|
|
|
_funtionArray = [NSMutableArray array];
|
|
|
|
}
|
|
|
|
return _funtionArray;
|
|
|
|
}
|
|
|
|
- (UIView *)friendContentView {
|
|
|
|
if (!_friendContentView) {
|
|
|
|
_friendContentView = [[UIView alloc] init];
|
|
|
|
// _friendContentView.hidden = YES;
|
|
|
|
}
|
|
|
|
return _friendContentView;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UICollectionView *)collectionView {
|
|
|
|
if (!_collectionView) {
|
|
|
|
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
|
|
|
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
|
|
|
|
layout.minimumLineSpacing = 0;
|
|
|
|
layout.minimumInteritemSpacing = 18;
|
|
|
|
layout.itemSize = CGSizeMake(48, 68);
|
|
|
|
layout.sectionInset = UIEdgeInsetsMake(0, 16, 0, 16);
|
|
|
|
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
|
|
|
|
[_collectionView registerClass:[XPSessionListHeadFriendCell class] forCellWithReuseIdentifier:NSStringFromClass([XPSessionListHeadFriendCell class])];
|
|
|
|
_collectionView.delegate = self;
|
|
|
|
_collectionView.dataSource = self;
|
|
|
|
_collectionView.backgroundColor = UIColorRGBAlpha(0x5FCCE4, 0.12);
|
|
|
|
_collectionView.layer.cornerRadius = 8;
|
|
|
|
_collectionView.layer.masksToBounds = YES;
|
|
|
|
}
|
|
|
|
return _collectionView;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UIImageView *)partyView {
|
|
|
|
if (!_partyView) {
|
|
|
|
_partyView = [[UIImageView alloc] init];
|
|
|
|
_partyView.image = [UIImage gradientColorImageFromColors:@[UIColorFromRGB(0x70F2F2), UIColorFromRGB(0x4ECDFF)] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(82, 16)];
|
|
|
|
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 82, 16) byRoundingCorners:UIRectCornerTopRight | UIRectCornerTopLeft cornerRadii:CGSizeMake(6, 6)];
|
|
|
|
CAShapeLayer *maskLayer = [CAShapeLayer layer];
|
|
|
|
maskLayer.path = path.CGPath;
|
|
|
|
_partyView.layer.mask = maskLayer;
|
|
|
|
}
|
|
|
|
return _partyView;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UIButton *)partyButton {
|
|
|
|
if (!_partyButton) {
|
|
|
|
_partyButton = [[UIButton alloc] init];
|
|
|
|
[_partyButton setTitle:@"好友派对中~" forState:UIControlStateNormal];
|
|
|
|
[_partyButton setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
|
|
|
|
_partyButton.titleLabel.font = [UIFont systemFontOfSize:10];
|
|
|
|
_partyButton.titleLabel.textColor = [ThemeColor mainTextColor];
|
|
|
|
|
|
|
|
}
|
|
|
|
return _partyButton;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|