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-24 17:58:28 +08:00
|
|
|
#import "NSArray+Safe.h"
|
2022-11-24 19:05:40 +08:00
|
|
|
#import "XPSessionListFansPartyModel.h"
|
|
|
|
#import "XCCurrentVCStackManager.h"
|
|
|
|
#import "XPRoomViewController.h"
|
2022-11-17 18:58:56 +08:00
|
|
|
|
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
|
2022-12-26 15:52:07 +08:00
|
|
|
@property (nonatomic, strong) UILabel *partyView;
|
|
|
|
///显示烟花
|
|
|
|
@property (nonatomic,strong) UIImageView *fireImageView;
|
2022-11-17 18:58:56 +08:00
|
|
|
///好友列表
|
|
|
|
@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.collectionView];
|
2022-11-21 11:50:51 +08:00
|
|
|
[self.friendContentView addSubview:self.partyView];
|
2022-12-26 15:52:07 +08:00
|
|
|
[self.friendContentView addSubview:self.fireImageView];
|
2022-11-17 18:58:56 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)initContraints {
|
|
|
|
[self.mainStackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.edges.mas_equalTo(0);
|
|
|
|
}];
|
|
|
|
[self.partyView mas_makeConstraints:^(MASConstraintMaker *make) {
|
2022-11-21 11:50:51 +08:00
|
|
|
make.left.mas_equalTo(21);
|
2022-11-17 18:58:56 +08:00
|
|
|
make.top.mas_equalTo(12);
|
|
|
|
}];
|
2022-12-26 15:52:07 +08:00
|
|
|
|
|
|
|
[self.fireImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.size.mas_equalTo(CGSizeMake(15, 17));
|
|
|
|
make.centerY.mas_equalTo(self.partyView);
|
|
|
|
make.left.mas_equalTo(self.partyView.mas_right).offset(5);
|
|
|
|
}];
|
|
|
|
|
2022-11-17 18:58:56 +08:00
|
|
|
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.left.mas_equalTo(16);
|
|
|
|
make.right.mas_equalTo(-16);
|
2022-11-21 11:50:51 +08:00
|
|
|
make.height.mas_equalTo(90);
|
|
|
|
make.top.mas_equalTo(self.partyView.mas_bottom).mas_offset(-5);
|
2022-11-17 18:58:56 +08:00
|
|
|
make.bottom.mas_equalTo(0);
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - UICollectionViewDelegate
|
|
|
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
2022-11-24 19:05:40 +08:00
|
|
|
return self.friendsArray.count;
|
2022-11-17 18:58:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
XPSessionListHeadFriendCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XPSessionListHeadFriendCell class]) forIndexPath:indexPath];
|
2022-11-24 19:05:40 +08:00
|
|
|
XPSessionListFansPartyModel *model = [self.friendsArray safeObjectAtIndex1:indexPath.row];
|
|
|
|
[cell configData:model];
|
2022-11-17 18:58:56 +08:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
|
2022-11-24 19:05:40 +08:00
|
|
|
XPSessionListFansPartyModel *model = [self.friendsArray safeObjectAtIndex1:indexPath.row];
|
|
|
|
[XPRoomViewController openRoom:model.uid viewController:[XCCurrentVCStackManager shareManager].getCurrentVC];
|
2022-11-17 18:58:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
- (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];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-24 17:58:28 +08:00
|
|
|
- (void)updateBadgeWithSessionId:(NSString *)sessionId unreadCount:(NSInteger)unreadCount {
|
|
|
|
for (int i = 0; i<[ClientConfig shareConfig].configInfo.officialMsgUids.count; i++) {
|
|
|
|
NSString *str = [[ClientConfig shareConfig].configInfo.officialMsgUids safeObjectAtIndex1:i];
|
|
|
|
if ([str isEqualToString:sessionId]) {
|
|
|
|
XPSessionListHeadItemView *itemView = [self.toolStackView.subviews safeObjectAtIndex1:i];
|
|
|
|
if (i == 2) {
|
|
|
|
itemView.showDot = unreadCount;
|
|
|
|
} else {
|
|
|
|
itemView.badgeValue = unreadCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-17 18:58:56 +08:00
|
|
|
- (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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-24 19:05:40 +08:00
|
|
|
- (void)setFriendsArray:(NSArray *)friendsArray {
|
|
|
|
_friendsArray = friendsArray;
|
|
|
|
if (friendsArray.count) {
|
|
|
|
self.friendContentView.hidden = NO;
|
|
|
|
[self.collectionView reloadData];
|
|
|
|
}
|
|
|
|
}
|
2022-11-17 18:58:56 +08:00
|
|
|
- (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];
|
2022-11-24 19:05:40 +08:00
|
|
|
_friendContentView.hidden = YES;
|
2022-11-17 18:58:56 +08:00
|
|
|
}
|
|
|
|
return _friendContentView;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UICollectionView *)collectionView {
|
|
|
|
if (!_collectionView) {
|
|
|
|
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
|
|
|
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
|
2022-11-21 11:50:51 +08:00
|
|
|
layout.minimumLineSpacing = 18;
|
|
|
|
// layout.minimumInteritemSpacing = 18;
|
|
|
|
layout.itemSize = CGSizeMake(48, 90);
|
2022-11-17 18:58:56 +08:00
|
|
|
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;
|
2022-12-26 15:52:07 +08:00
|
|
|
_collectionView.backgroundColor = [UIColor clearColor];
|
2022-11-17 18:58:56 +08:00
|
|
|
_collectionView.layer.cornerRadius = 8;
|
|
|
|
_collectionView.layer.masksToBounds = YES;
|
2022-11-21 11:50:51 +08:00
|
|
|
_collectionView.showsHorizontalScrollIndicator = NO;
|
2022-11-17 18:58:56 +08:00
|
|
|
}
|
|
|
|
return _collectionView;
|
|
|
|
}
|
|
|
|
|
2022-12-26 15:52:07 +08:00
|
|
|
- (UILabel *)partyView {
|
2022-11-17 18:58:56 +08:00
|
|
|
if (!_partyView) {
|
2022-12-26 15:52:07 +08:00
|
|
|
_partyView = [[UILabel alloc] init];
|
|
|
|
_partyView.text = @"好友派对中";
|
|
|
|
_partyView.font = [UIFont systemFontOfSize:12];
|
|
|
|
_partyView.textColor = [ThemeColor mainTextColor];
|
2022-11-17 18:58:56 +08:00
|
|
|
}
|
|
|
|
return _partyView;
|
|
|
|
}
|
2022-12-26 15:52:07 +08:00
|
|
|
- (UIImageView *)fireImageView {
|
|
|
|
if (!_fireImageView) {
|
|
|
|
_fireImageView = [[UIImageView alloc] init];
|
|
|
|
_fireImageView.userInteractionEnabled = YES;
|
|
|
|
_fireImageView.image = [UIImage imageNamed:@"session_list_head_friend"];
|
|
|
|
}
|
|
|
|
return _fireImageView;
|
|
|
|
}
|
2022-11-17 18:58:56 +08:00
|
|
|
|
|
|
|
@end
|