493 lines
19 KiB
Objective-C
493 lines
19 KiB
Objective-C
//
|
||
// XPHomeMineViewController.m
|
||
// YuMi
|
||
//
|
||
// Created by P on 2024/6/18.
|
||
//
|
||
|
||
#import "XPHomeMineViewController.h"
|
||
|
||
#import <JXPagingView/JXPagerView.h>
|
||
#import <JXCategoryView/JXCategoryView.h>
|
||
#import <JXPagingView/JXPagerListRefreshView.h>
|
||
|
||
#import "XPHomeMinePresenter.h"
|
||
#import "XPHomePartyViewController.h"
|
||
#import "XPLittleGameRoomOpenView.h"
|
||
#import "XPRoomViewController.h"
|
||
#import "PIHomeCategoryTitleModel.h"
|
||
|
||
#import "XPHomeMineProtocol.h"
|
||
#import "HomeMineRoomModel.h"
|
||
#import "AccountInfoStorage.h"
|
||
#import "Api+Room.h"
|
||
|
||
@interface XPHomeMineRoomCard : UIView
|
||
|
||
@property (nonatomic, strong) HomeMineRoomModel *model;
|
||
|
||
@property (nonatomic, strong) NetImageView *avatarImageView;
|
||
@property (nonatomic, strong) UILabel *roomNameLabel;
|
||
@property (nonatomic, strong) UILabel *descLabel;
|
||
@property (nonatomic, strong) UILabel *heatLabel;
|
||
@property (nonatomic, strong) UIView *miniAvatarsContainer;
|
||
@property (nonatomic, copy) void(^didTapMyRoom)(void);
|
||
|
||
@end
|
||
|
||
@implementation XPHomeMineRoomCard
|
||
|
||
- (instancetype)init
|
||
{
|
||
self = [super init];
|
||
if (self) {
|
||
[self setupUI];
|
||
[self setupGesture];
|
||
}
|
||
return self;
|
||
}
|
||
|
||
- (void)setModel:(HomeMineRoomModel *)model {
|
||
_model = model;
|
||
if (model) {
|
||
self.avatarImageView.imageUrl = model.avatar;
|
||
self.roomNameLabel.text = model.title.length > 0 ? model.title : YMLocalizedString(@"XPMinePersonalCenterCell1");
|
||
self.descLabel.text = model.roomDesc.length > 0 ? model.roomDesc : YMLocalizedString(@"XPHomeMineViewController3");
|
||
self.heatLabel.text = [NSString stringWithFormat:@"%ld", model.onlineNum];
|
||
|
||
for (UIView *subView in self.miniAvatarsContainer.subviews) {
|
||
[subView removeFromSuperview];
|
||
}
|
||
|
||
NSInteger i = 0;
|
||
for (HomePlayMicUserModel *micUser in model.micUsers) {
|
||
NetImageConfig *config = [[NetImageConfig alloc]init];
|
||
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
|
||
NetImageView *iconView = [[NetImageView alloc]initWithConfig:config];
|
||
iconView.layer.cornerRadius = kGetScaleWidth(20)/2;
|
||
iconView.layer.masksToBounds = YES;
|
||
iconView.layer.borderWidth = 1;
|
||
iconView.layer.borderColor = [UIColor whiteColor].CGColor;
|
||
iconView.imageUrl = micUser.avatar;
|
||
[self.miniAvatarsContainer addSubview:iconView];
|
||
CGFloat left = i * kGetScaleWidth(14);
|
||
[iconView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.top.equalTo(self.miniAvatarsContainer);
|
||
make.leading.mas_equalTo(left);
|
||
make.width.height.mas_equalTo(20);
|
||
}];
|
||
i++;
|
||
}
|
||
} else {
|
||
self.roomNameLabel.text = YMLocalizedString(@"XPMinePersonalCenterCell1");
|
||
self.descLabel.text = YMLocalizedString(@"XPHomeMineViewController3");
|
||
self.heatLabel.text = @"0";
|
||
|
||
for (UIView *subView in self.miniAvatarsContainer.subviews) {
|
||
[subView removeFromSuperview];
|
||
}
|
||
}
|
||
}
|
||
|
||
- (void)setupUI {
|
||
UIImage *gradientColorImage = [UIImage gradientColorImageFromColors:@[[DJDKMIMOMColor colorWithHexString:@"#FFE993"],
|
||
[DJDKMIMOMColor colorWithHexString:@"#FDC36F"]]
|
||
gradientType:GradientTypeTopToBottom
|
||
imgSize:CGSizeMake(350, 100)];
|
||
UIImageView *backgroundImageView = [[UIImageView alloc] initWithImage:gradientColorImage];
|
||
backgroundImageView.layer.cornerRadius = 16;
|
||
backgroundImageView.clipsToBounds = YES;
|
||
[self addSubview:backgroundImageView];
|
||
[backgroundImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.center.mas_equalTo(self);
|
||
make.size.mas_equalTo(CGSizeMake(kGetScaleWidth(345), kGetScaleWidth(88)));
|
||
}];
|
||
|
||
[self addSubview:self.avatarImageView];
|
||
[self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.top.mas_equalTo(backgroundImageView).offset(8);
|
||
if (isMSRTL()) {
|
||
make.right.mas_equalTo(backgroundImageView).offset(-8);
|
||
} else {
|
||
make.left.mas_equalTo(backgroundImageView).offset(8);
|
||
}
|
||
make.bottom.mas_equalTo(backgroundImageView).offset(-8);
|
||
make.width.mas_equalTo(self.avatarImageView.mas_height);
|
||
}];
|
||
|
||
[self addSubview:self.roomNameLabel];
|
||
[self.roomNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.top.mas_equalTo(backgroundImageView).offset(16);
|
||
if (isMSRTL()) {
|
||
make.right.mas_equalTo(self.avatarImageView.mas_left).offset(-8);
|
||
make.left.mas_equalTo(backgroundImageView).offset(8);
|
||
} else {
|
||
make.left.mas_equalTo(self.avatarImageView.mas_right).offset(8);
|
||
make.right.mas_equalTo(backgroundImageView).offset(-8);
|
||
}
|
||
}];
|
||
|
||
[self addSubview:self.descLabel];
|
||
[self.descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.top.mas_equalTo(backgroundImageView).offset(40);
|
||
if (isMSRTL()) {
|
||
make.right.mas_equalTo(self.avatarImageView.mas_left).offset(-8);
|
||
make.left.mas_equalTo(backgroundImageView).offset(8);
|
||
} else {
|
||
make.left.mas_equalTo(self.avatarImageView.mas_right).offset(8);
|
||
make.right.mas_equalTo(backgroundImageView).offset(-8);
|
||
}
|
||
}];
|
||
|
||
[self addSubview:self.heatLabel];
|
||
[self.heatLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.bottom.mas_equalTo(backgroundImageView).offset(-8);
|
||
if (isMSRTL()) {
|
||
make.left.mas_equalTo(backgroundImageView).offset(16);
|
||
} else {
|
||
make.right.mas_equalTo(backgroundImageView).offset(-16);
|
||
}
|
||
}];
|
||
|
||
UIImageView *fireImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ms_home_heat_icon"]];
|
||
[self addSubview:fireImageView];
|
||
[fireImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.bottom.mas_equalTo(backgroundImageView).offset(-8);
|
||
// make.right.mas_equalTo(self.heatLabel.mas_left).offset(-8);
|
||
if (isMSRTL()) {
|
||
make.left.mas_equalTo(self.heatLabel.mas_right).offset(8);
|
||
} else {
|
||
make.right.mas_equalTo(self.heatLabel.mas_left).offset(-8);
|
||
}
|
||
}];
|
||
|
||
_miniAvatarsContainer = [[UIView alloc] init];
|
||
[self addSubview:_miniAvatarsContainer];
|
||
[_miniAvatarsContainer mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.bottom.mas_equalTo(backgroundImageView).offset(-8);
|
||
if (isMSRTL()) {
|
||
make.right.mas_equalTo(self.avatarImageView.mas_left).offset(-8);
|
||
} else {
|
||
make.left.mas_equalTo(self.avatarImageView.mas_right).offset(8);
|
||
}
|
||
make.width.mas_equalTo(120);
|
||
make.height.mas_equalTo(20);
|
||
}];
|
||
}
|
||
|
||
- (void)setupGesture {
|
||
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self
|
||
action:@selector(didTapCard)];
|
||
[self addGestureRecognizer:tap];
|
||
}
|
||
|
||
- (void)didTapCard {
|
||
if (_didTapMyRoom) {
|
||
_didTapMyRoom();
|
||
}
|
||
}
|
||
|
||
- (NetImageView *)avatarImageView {
|
||
if (!_avatarImageView) {
|
||
NetImageConfig * config = [[NetImageConfig alloc]init];
|
||
config.imageType = ImageTypeUserIcon;
|
||
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
|
||
_avatarImageView = [[NetImageView alloc] initWithConfig:config];
|
||
_avatarImageView.backgroundColor = [DJDKMIMOMColor colorWithHexString:@"F5EDFF"];
|
||
_avatarImageView.layer.masksToBounds = YES;
|
||
// _avatarImageView.layer.cornerRadius = 56/2;
|
||
_avatarImageView.layer.borderColor = [UIColor whiteColor].CGColor;
|
||
_avatarImageView.layer.borderWidth = 1;
|
||
[_avatarImageView setCornerWithLeftTopCorner:kGetScaleWidth(10)
|
||
rightTopCorner:kGetScaleWidth(10)
|
||
bottomLeftCorner:kGetScaleWidth(10)
|
||
bottomRightCorner:kGetScaleWidth(10)
|
||
size:CGSizeMake(kGetScaleWidth(72), kGetScaleWidth(72))];
|
||
}
|
||
return _avatarImageView;
|
||
}
|
||
|
||
- (UILabel *)roomNameLabel {
|
||
if (!_roomNameLabel) {
|
||
_roomNameLabel = [UILabel labelInitWithText:YMLocalizedString(@"XPMinePersonalCenterCell1")
|
||
font:[UIFont systemFontOfSize:15 weight:UIFontWeightBold]
|
||
textColor:[DJDKMIMOMColor colorWithHexString:@"18181A"]];
|
||
}
|
||
return _roomNameLabel;
|
||
}
|
||
|
||
- (UILabel *)descLabel {
|
||
if (!_descLabel) {
|
||
_descLabel = [UILabel labelInitWithText:YMLocalizedString(@"XPHomeMineViewController3")
|
||
font:[UIFont systemFontOfSize:13 weight:UIFontWeightMedium]
|
||
textColor:[DJDKMIMOMColor colorWithHexString:@"18181A"]];
|
||
}
|
||
return _descLabel;
|
||
}
|
||
|
||
- (UILabel *)heatLabel {
|
||
if (!_heatLabel) {
|
||
_heatLabel = [UILabel labelInitWithText:@"0"
|
||
font:[UIFont systemFontOfSize:13 weight:UIFontWeightMedium]
|
||
textColor:[DJDKMIMOMColor colorWithHexString:@"797B80"]];
|
||
}
|
||
return _heatLabel;
|
||
}
|
||
|
||
@end
|
||
|
||
@interface XPHomeMineViewController () <JXCategoryViewDelegate, JXPagerViewDelegate, JXPagerMainTableViewGestureDelegate, XPHomeMineProtocol>
|
||
|
||
@property (nonatomic, strong) XPHomeMineRoomCard *headView;
|
||
|
||
@property (nonatomic, assign) NSInteger currentIndex;
|
||
@property (nonatomic, strong) NSMutableDictionary *validListDict;
|
||
|
||
@property (nonatomic, strong) JXPagerView *pagingView;
|
||
@property (nonatomic, strong) JXCategoryTitleView *titleView;
|
||
@property (nonatomic, strong) NSMutableArray<PIHomeCategoryTitleModel *> *tagModelList;
|
||
@end
|
||
|
||
@implementation XPHomeMineViewController
|
||
|
||
- (void)viewDidLoad {
|
||
[super viewDidLoad];
|
||
|
||
self.currentIndex = 0;
|
||
|
||
[self setupNotifications];
|
||
|
||
[self setupUI];
|
||
[self setupRefreshHeader];
|
||
|
||
[self setupDefaultTags];
|
||
}
|
||
|
||
- (void)viewDidAppear:(BOOL)animated {
|
||
[super viewDidAppear:animated];
|
||
|
||
[self.pagingView.mainTableView.mj_header beginRefreshing];
|
||
}
|
||
|
||
- (BOOL)isHiddenNavBar {
|
||
return YES;
|
||
}
|
||
|
||
- (XPHomeMinePresenter *)createPresenter {
|
||
return [[XPHomeMinePresenter alloc] init];
|
||
}
|
||
|
||
- (void)setupNotifications {
|
||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||
selector:@selector(homeVCRefreshComplete)
|
||
name:@"khomeVCRefreshComplete"
|
||
object:nil];
|
||
}
|
||
|
||
- (void)setupUI {
|
||
self.view.backgroundColor = [UIColor clearColor];
|
||
[self.view addSubview:self.pagingView];
|
||
[self.pagingView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.top.equalTo(self.view).mas_offset(kGetScaleWidth(8));
|
||
make.leading.bottom.trailing.mas_equalTo(0);
|
||
}];
|
||
}
|
||
|
||
- (void)setupRefreshHeader {
|
||
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 = [DJDKMIMOMColor secondTextColor];
|
||
header.lastUpdatedTimeLabel.textColor = [DJDKMIMOMColor secondTextColor];
|
||
self.pagingView.mainTableView.mj_header = header;
|
||
}
|
||
|
||
- (void)setupDefaultTags {
|
||
NSMutableArray *titleArray = [NSMutableArray array];
|
||
for (PIHomeCategoryTitleModel *model in self.tagModelList) {
|
||
[titleArray addObject:model.name];
|
||
}
|
||
self.titleView.titles = titleArray;
|
||
[self.titleView reloadData];
|
||
|
||
[self headerRefresh];
|
||
}
|
||
|
||
#pragma mark -
|
||
- (void)headerRefresh {
|
||
[self.presenter getMyRoom];
|
||
|
||
PIHomeCategoryTitleModel *tagModel = [self.tagModelList xpSafeObjectAtIndex:self.currentIndex];
|
||
XPHomePartyViewController *homeVC = [self.validListDict objectForKey:[NSNumber numberWithInteger:self.currentIndex]];
|
||
homeVC.tagModel = tagModel;
|
||
}
|
||
|
||
- (void)homeVCRefreshComplete {
|
||
[self.pagingView.mainTableView.mj_header endRefreshing];
|
||
[self.pagingView.mainTableView.mj_footer endRefreshing];
|
||
}
|
||
|
||
-(void)pushMyRoomVC{
|
||
NSString* roomUid = [[AccountInfoStorage instance] getUid];
|
||
[Api getRoomInfo:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
||
if (code == 200) {
|
||
RoomInfoModel * roomInfo = [RoomInfoModel modelWithJSON:data.data];
|
||
if (roomInfo.isReselect) {
|
||
XPLittleGameRoomOpenView * roomOpenView = [[XPLittleGameRoomOpenView alloc] init];
|
||
roomOpenView.roomInfo = roomInfo;
|
||
roomOpenView.currentVC = self;
|
||
[TTPopup popupView:roomOpenView style:TTPopupStyleActionSheet];
|
||
} else {
|
||
[XPRoomViewController openRoom:roomUid viewController:self];
|
||
}
|
||
} else {
|
||
[self showErrorToast:msg];
|
||
}
|
||
}
|
||
uid:roomUid
|
||
intoUid:roomUid
|
||
];
|
||
}
|
||
|
||
#pragma mark - XPHomeMineProtocol
|
||
- (void)getMyRoomSuccess:(HomeMineRoomModel *)model {
|
||
self.headView.model = model;
|
||
[self.pagingView reloadData];
|
||
[self.pagingView resizeTableHeaderViewHeightWithAnimatable:NO duration:0 curve:0];
|
||
|
||
[self.pagingView.mainTableView.mj_header endRefreshing];
|
||
}
|
||
|
||
#pragma mark - JXPagerMainTableViewGestureDelegate
|
||
- (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
|
||
//禁止categoryView左右滑动的时候,上下和左右都可以滚动
|
||
if (otherGestureRecognizer.view == self.pagingView.listContainerView) {
|
||
return NO;
|
||
}
|
||
return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
|
||
}
|
||
|
||
#pragma mark - JXCategoryViewDelegate
|
||
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index{
|
||
self.currentIndex = index;
|
||
}
|
||
|
||
#pragma mark - JXCategoryViewDelegate
|
||
- (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
|
||
return kGetScaleWidth(98);
|
||
}
|
||
|
||
- (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
|
||
return self.headView;
|
||
}
|
||
|
||
- (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
|
||
return kGetScaleWidth(50);
|
||
}
|
||
|
||
- (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
|
||
return self.titleView;
|
||
}
|
||
|
||
- (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView {
|
||
return self.tagModelList.count;
|
||
}
|
||
|
||
- (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index {
|
||
id homeV = [self.validListDict objectForKey:[NSNumber numberWithInteger:index]];
|
||
if (homeV) {
|
||
return homeV;
|
||
}
|
||
XPHomePartyViewController *homeVC = [[XPHomePartyViewController alloc] init];
|
||
homeVC.tagModel = [self.tagModelList xpSafeObjectAtIndex:index];
|
||
[self.validListDict setObject:homeVC forKey:@(index)];
|
||
return homeVC;
|
||
}
|
||
|
||
#pragma mark -
|
||
- (XPHomeMineRoomCard *)headView {
|
||
if (!_headView) {
|
||
_headView = [[XPHomeMineRoomCard alloc] init];
|
||
@kWeakify(self);
|
||
_headView.didTapMyRoom = ^{
|
||
@kStrongify(self);
|
||
[self pushMyRoomVC];
|
||
};
|
||
}
|
||
return _headView;
|
||
}
|
||
|
||
- (JXPagerView *)pagingView {
|
||
if (!_pagingView) {
|
||
_pagingView = [[JXPagerView alloc] initWithDelegate:self listContainerType:0];
|
||
_pagingView.mainTableView.gestureDelegate = self;
|
||
_pagingView.backgroundColor = [UIColor clearColor];
|
||
_pagingView.listContainerView.backgroundColor = [UIColor clearColor];
|
||
_pagingView.listContainerView.listCellBackgroundColor = [UIColor clearColor];
|
||
_pagingView.mainTableView.backgroundColor = [UIColor clearColor];
|
||
}
|
||
return _pagingView;
|
||
}
|
||
|
||
- (NSMutableArray<PIHomeCategoryTitleModel *> *)tagModelList{
|
||
if(!_tagModelList){
|
||
_tagModelList = [NSMutableArray array];
|
||
|
||
PIHomeCategoryTitleModel *recommendModel = [PIHomeCategoryTitleModel new];
|
||
recommendModel.id = @"-12";
|
||
recommendModel.name = YMLocalizedString(@"XPHomeMineViewController1");
|
||
recommendModel.checkedWidth = [UILabel getWidthWithText:recommendModel.name height:kGetScaleWidth(27) font:kFontSemibold(14)];
|
||
recommendModel.noCheckedWidth = [UILabel getWidthWithText:recommendModel.name height:kGetScaleWidth(27) font:kFontRegular(14)];
|
||
recommendModel.isChecked = YES;
|
||
|
||
PIHomeCategoryTitleModel *hotModel = [PIHomeCategoryTitleModel new];
|
||
hotModel.id = @"-11";
|
||
hotModel.name = YMLocalizedString(@"XPMineFootPrintViewController5");
|
||
hotModel.checkedWidth = [UILabel getWidthWithText:recommendModel.name height:kGetScaleWidth(27) font:kFontSemibold(14)];
|
||
hotModel.noCheckedWidth = [UILabel getWidthWithText:recommendModel.name height:kGetScaleWidth(27) font:kFontRegular(14)];
|
||
|
||
[_tagModelList addObject:recommendModel];
|
||
[_tagModelList addObject:hotModel];
|
||
}
|
||
return _tagModelList;
|
||
}
|
||
|
||
- (NSMutableDictionary *)validListDict{
|
||
if(!_validListDict){
|
||
_validListDict = [NSMutableDictionary dictionary];
|
||
}
|
||
return _validListDict;
|
||
}
|
||
|
||
- (JXCategoryTitleView *)titleView {
|
||
if (!_titleView) {
|
||
_titleView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
|
||
_titleView.delegate = self;
|
||
_titleView.titles = @[];
|
||
_titleView.backgroundColor = [UIColor clearColor];
|
||
_titleView.titleColor = UIColorFromRGB(0x767585);
|
||
_titleView.titleSelectedColor = UIColorFromRGB(0x1E1E1E);
|
||
_titleView.titleFont = kFontBold(14);
|
||
_titleView.titleSelectedFont = kFontBold(14);
|
||
_titleView.titleLabelAnchorPointStyle = JXCategoryTitleLabelAnchorPointStyleCenter;
|
||
_titleView.contentScrollViewClickTransitionAnimationEnabled = NO;
|
||
_titleView.defaultSelectedIndex = 0;
|
||
_titleView.averageCellSpacingEnabled = NO;
|
||
|
||
// _titleView.cellWidth = 50;
|
||
_titleView.cellSpacing = kGetScaleWidth(28);
|
||
|
||
_titleView.listContainer = (id<JXCategoryViewListContainer>)self.pagingView.listContainerView;
|
||
|
||
JXCategoryIndicatorImageView *indicator = [[JXCategoryIndicatorImageView alloc] init];
|
||
indicator.indicatorImageView.image = [UIImage imageNamed:@"ms_hoem_index_icon"];
|
||
indicator.indicatorImageViewSize = CGSizeMake(kGetScaleWidth(24), kGetScaleWidth(24));
|
||
indicator.verticalMargin = -kGetScaleWidth(4);
|
||
indicator.contentMode = UIViewContentModeScaleAspectFit;
|
||
_titleView.indicators = @[indicator];
|
||
}
|
||
return _titleView;
|
||
}
|
||
|
||
@end
|