Files
peko-ios/YuMi/Modules/YMNewHome/View/XPHomeRecommendViewController.m

369 lines
12 KiB
Mathematica
Raw Normal View History

2023-07-14 18:50:55 +08:00
//
// XPHomeRecommendViewController.m
// YuMi
//
// Created by YuMi on 2022/2/21.
//
#import "XPHomeRecommendViewController.h"
///Third
#import <Masonry/Masonry.h>
#import <JXCategoryView/JXCategoryView.h>
#import <MJRefresh/MJRefresh.h>
#import <ReactiveObjC/ReactiveObjC.h>
///Tool
#import "YUMIMacroUitls.h"
#import "DJDKMIMOMColor.h"
#import "XPWeakTimer.h"
#import "ClientConfig.h"
#import "UIImage+Utils.h"
#import "Api+Room.h"
#import "Api+RoomSetting.h"
#import "AccountInfoStorage.h"
#import "TTPopup.h"
#import "NSArray+Safe.h"
///View
#import "XPNewHomePlayTableViewCell.h"
#import "XPNewHomeRecommendTableViewCell.h"
#import "XPNewHomePlayEmptyTableViewCell.h"
#import "XPHomeBannerTableViewCell.h"
#import "XPNewHomePartyTableViewCell.h"
#import "XPRoomViewController.h"
#import "XPWebViewController.h"
///Model
#import "HomePlayRoomModel.h"
#import "HomeBannerInfoModel.h"
#import "HomeRecommendRoomModel.h"
#import "ClanDetailInfoModel.h"
///P
#import "XPNewHomeRecommendPresenter.h"
#import "XPNewHomeRecommendProtocol.h"
UIKIT_EXTERN NSString * const kShieldingNotification;
2023-09-05 11:45:21 +08:00
@interface XPHomeRecommendViewController ()<UITableViewDelegate, UITableViewDataSource, XPNewHomePlayTableViewCellDelegate, XPHomeBannerTableViewCellDelegate,XPNewHomeRecommendTableViewCellDelegate,XPNewHomeRecommendProtocol>
2023-07-14 18:50:55 +08:00
{
NSTimer * timer;
}
///
@property (nonatomic,strong) UITableView *tableView;
2023-09-05 11:45:21 +08:00
2023-07-14 18:50:55 +08:00
///
@property (nonatomic,strong) NSArray<HomePlayRoomModel *> *playTeamList;
///
@property (nonatomic,strong) NSArray<HomePlayRoomModel *> *personalRoomList;
///
@property (nonatomic,strong) RoomInfoModel * roomInfo;
///,
@property (nonatomic,assign) BOOL isRequestData;
@end
@implementation XPHomeRecommendViewController
- (XPNewHomeRecommendPresenter *)createPresenter {
return [[XPNewHomeRecommendPresenter alloc] init];
}
- (BOOL)isHiddenNavBar {
return YES;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self initSubViews];
[self initHeaderAndFooterRrfresh];
[self addTimer];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if (timer) {
[timer setFireDate:[NSDate distantPast]]; //
}
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
if (timer) {
//
[timer setFireDate:[NSDate distantFuture]]; //
}
}
-(void)dealloc{
[[NSNotificationCenter defaultCenter]removeObserver:self];
}
#pragma mark - InitHttp
- (void)addTimer {
timer = [XPWeakTimer scheduledTimerWithTimeInterval:15 block:^(id userInfo) {
[self requestData];
} userInfo:nil repeats:YES];
}
-(void)requestData{
///退bug
@synchronized (self.presenter) {
if(self.isRequestData == YES)return;
self.isRequestData = YES;
///
dispatch_group_t group =dispatch_group_create();
//
dispatch_queue_t queue =dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0);
2023-09-05 11:45:21 +08:00
2023-07-14 18:50:55 +08:00
dispatch_group_enter(group);
dispatch_group_async(group, queue, ^{
[self.presenter getPlayGameWithTeam:1 withGroup:group];
});
dispatch_group_enter(group);
dispatch_group_async(group, queue, ^{
[self.presenter getHomePersonalRoomListWithGroup:group];
});
2023-09-05 11:45:21 +08:00
2023-07-14 18:50:55 +08:00
dispatch_group_notify(group,dispatch_get_main_queue(), ^{
self.isRequestData = NO;
[self.tableView.mj_header endRefreshing];
[self.tableView reloadData];
});
}
}
- (void)headerRefresh {
self.isRequestData = NO;
[self requestData];
}
2023-09-05 11:45:21 +08:00
2023-07-14 18:50:55 +08:00
- (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 = [DJDKMIMOMColor secondTextColor];
header.lastUpdatedTimeLabel.textColor = [DJDKMIMOMColor secondTextColor];
self.tableView.mj_header = header;
[self.tableView.mj_header beginRefreshing];
}
#pragma mark - Private Method
- (void)initSubViews {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(shieldingNotification) name:kShieldingNotification object:nil];
self.view.backgroundColor = [UIColor clearColor];
[self.view addSubview:self.tableView];
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
}];
}
-(void)shieldingNotification{
[self requestData];
}
#pragma mark - UITableViewDelegate And UITableViewDataSource
2023-09-05 11:45:21 +08:00
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 2;
}
2023-07-14 18:50:55 +08:00
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
2023-09-05 11:45:21 +08:00
if(section == 0)return self.playTeamList.count > 0 ? 1 : 0;
return self.personalRoomList.count > 0 ? self.personalRoomList.count : 1;
2023-07-14 18:50:55 +08:00
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
2023-09-05 11:45:21 +08:00
return kGetScaleWidth(102);
2023-07-14 18:50:55 +08:00
}
2023-09-05 11:45:21 +08:00
return self.personalRoomList.count > 0 ? kGetScaleWidth(104) : 300;
2023-07-14 18:50:55 +08:00
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
2023-09-05 11:45:21 +08:00
if(indexPath.section == 0) {
2023-07-14 18:50:55 +08:00
XPNewHomePlayTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPNewHomePlayTableViewCell class])];
if (cell == nil) {
cell = [[XPNewHomePlayTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPNewHomePlayTableViewCell class])];
}
2023-09-05 11:45:21 +08:00
2023-07-14 18:50:55 +08:00
cell.playRoomList = self.playTeamList;
cell.delegate = self;
return cell;
2023-09-05 11:45:21 +08:00
}
if(self.personalRoomList.count == 0){
XPNewHomePlayEmptyTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPNewHomePlayEmptyTableViewCell class])];
if (cell == nil) {
cell = [[XPNewHomePlayEmptyTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPNewHomePlayEmptyTableViewCell class])];
2023-07-14 18:50:55 +08:00
}
2023-09-05 11:45:21 +08:00
[cell setConstraints];
[cell setTitle:YMLocalizedString(@"XPGuildEmptyCollectionViewCell0")];
return cell;
}
2023-07-14 18:50:55 +08:00
XPNewHomePartyTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPNewHomePartyTableViewCell class])];
if (cell == nil) {
cell = [[XPNewHomePartyTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPNewHomePartyTableViewCell class])];
}
cell.roomInfo = [self.personalRoomList safeObjectAtIndex1:indexPath.row];
return cell;
2023-09-05 11:45:21 +08:00
2023-07-14 18:50:55 +08:00
}
2023-09-05 11:45:21 +08:00
2023-07-14 18:50:55 +08:00
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
2023-09-05 11:45:21 +08:00
2023-07-14 18:50:55 +08:00
return 0.01;
2023-09-05 11:45:21 +08:00
}
2023-07-14 18:50:55 +08:00
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 0.01;
}
2023-09-05 11:45:21 +08:00
2023-07-14 18:50:55 +08:00
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if(indexPath.section == 3) {
if (self.personalRoomList.count > 0) {
HomePlayRoomModel * roomInfo1 = [self.personalRoomList safeObjectAtIndex1:indexPath.row];
if (roomInfo1.uid.length > 0) {
[XPRoomViewController openRoom:roomInfo1.uid viewController:self];
}
}
}
}
#pragma mark - XPNewHomeRecommendTableViewCellDelegate
- (void)xPNewHomeRecommendTableViewCell:(XPNewHomeRecommendTableViewCell *)view didSelectItem:(HomeRecommendRoomModel *)info {
if (info.roomUid.length > 0) {
[XPRoomViewController openRoom:info.roomUid viewController:self];
}
}
#pragma mark - XPNewHomePlayTableViewCellDelegate
- (void)xPNewHomePlayTableViewCell:(XPNewHomePlayTableViewCell *)cell didSelectItem:(HomePlayRoomModel *)info {
if (info.uid.length > 0) {
[XPRoomViewController openRoom:info.uid viewController:self];
}
}
- (void)chooseGameAction{
// XPHomeGameView *gameView = [XPHomeGameView new];
// gameView.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight);
// gameView.playGameList = self.littleGameArray;
// gameView.delegate = self;
// [kWindow addSubview:gameView];
}
#pragma mark - XPNewHomePlayEmptyTableViewCellDelegate
- (void)emptyCellChooseGameAction{
// XPHomeGameView *gameView = [XPHomeGameView new];
// gameView.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight);
// gameView.playGameList = self.littleGameArray;
// gameView.delegate = self;
// [kWindow addSubview:gameView];
}
#pragma mark - XPHomeBannerTableViewCell
- (void)xPHomeBannerTableViewCell:(XPHomeBannerTableViewCell *)view didClickBanner:(HomeBannerInfoModel *)info {
switch (info.skipType) {
case HomeBannerInfoSkipType_Room:
{
if (info.skipUri.length > 0) {
[XPRoomViewController openRoom:info.skipUri viewController:self];
}
}
break;
case HomeBannerInfoSkipType_Web:
{
XPWebViewController *vc = [[XPWebViewController alloc]init];
vc.url = info.skipUri;
[self.navigationController pushViewController:vc animated:YES];
}
break;
default:
break;
}
}
#pragma mark - XPHomeRecommendProtocol
2023-09-05 11:45:21 +08:00
2023-07-14 18:50:55 +08:00
///
- (void)getHomeRecommendRoomListSuccess:(NSArray *)list withGroup:(nonnull dispatch_group_t)group{
2023-09-05 11:45:21 +08:00
2023-07-14 18:50:55 +08:00
}
///
- (void)getHomePersonalRoomListSuccess:(NSArray *)list withGroup:(nonnull dispatch_group_t)group {
NSMutableArray * array = [NSMutableArray array];
for (HomePlayRoomModel * info in list) {
2023-09-05 11:45:21 +08:00
[array addObject:info];
2023-07-14 18:50:55 +08:00
}
self.personalRoomList = array;
dispatch_group_leave(group);
}
///
- (void)getPlayGameWithTeamSuccess:(NSArray *)list withGroup:(nonnull dispatch_group_t)group{
NSMutableArray * array = [NSMutableArray array];
for (HomePlayRoomModel * info in list) {
2023-09-05 11:45:21 +08:00
[array addObject:info];
2023-07-14 18:50:55 +08:00
}
self.playTeamList = array;
dispatch_group_leave(group);
}
- (void)getHomeRecommendDataFailWithGroup:(dispatch_group_t)group {
dispatch_group_leave(group);
}
2023-09-01 18:58:41 +08:00
#pragma mark - JXPagingViewListViewDelegate
- (UIScrollView *)listScrollView {
return self.tableView;
}
- (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback {
self.scrollCallback = callback;
}
2023-07-14 18:50:55 +08:00
- (UIView *)listView {
return self.view;
}
2023-09-01 18:58:41 +08:00
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if(self.scrollCallback){
self.scrollCallback(scrollView);
}
}
2023-07-14 18:50:55 +08:00
- (UITableView *)tableView {
if (!_tableView) {
2023-09-05 11:45:21 +08:00
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
2023-07-14 18:50:55 +08:00
_tableView.delegate = self;
_tableView.dataSource = self;
2023-07-18 18:26:10 +08:00
_tableView.contentInset = UIEdgeInsetsMake(0, 0, 100, 0);
2023-07-14 18:50:55 +08:00
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.backgroundColor = [UIColor clearColor];
if (@available(iOS 11.0, *)) {
_tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
[_tableView registerClass:[XPNewHomePlayTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPNewHomePlayTableViewCell class])];
[_tableView registerClass:[XPNewHomePlayEmptyTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPNewHomePlayEmptyTableViewCell class])];
[_tableView registerClass:[XPNewHomePartyTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPNewHomePartyTableViewCell class])];
}
return _tableView;
}
@end