223 lines
7.5 KiB
Objective-C
223 lines
7.5 KiB
Objective-C
//
|
|
// XPHomeLittleGameViewController.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2022/3/24.
|
|
//
|
|
|
|
#import "XPHomeLittleGameViewController.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
#import <MJRefresh/MJRefresh.h>
|
|
///Tool
|
|
#import "ThemeColor.h"
|
|
#import "UIImage+Utils.h"
|
|
///Model
|
|
#import "HomeLittleGameRoomModel.h"
|
|
///View
|
|
#import "XPHomeLittleGameTableViewCell.h"
|
|
#import "XPHomeListEmptyTableViewCell.h"
|
|
///P
|
|
#import "XPHomeLittleGamePesenter.h"
|
|
#import "XPHomeLittleGameProtocol.h"
|
|
#import "XPRoomViewController.h"
|
|
|
|
@interface XPHomeLittleGameViewController ()<UITableViewDelegate, UITableViewDataSource, XPHomeLittleGameProtocol>
|
|
///列表
|
|
@property (nonatomic,strong) UITableView *tableView;
|
|
///快速匹配
|
|
@property (nonatomic,strong) UIButton *matchButton;
|
|
@property (nonatomic,strong) NSMutableArray *datasource;
|
|
@property (nonatomic,assign) int page;
|
|
@property (nonatomic,assign) BOOL hasNoMoreData;
|
|
@end
|
|
|
|
@implementation XPHomeLittleGameViewController
|
|
|
|
- (BOOL)isHiddenNavBar {
|
|
return YES;
|
|
}
|
|
|
|
- (XPHomeLittleGamePesenter *)createPresenter {
|
|
return [[XPHomeLittleGamePesenter alloc] init];;
|
|
}
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
[self initHeaderAndFooterRrfresh];
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
}
|
|
|
|
#pragma mark - Private Method
|
|
- (void)initSubViews {
|
|
[self.view addSubview:self.tableView];
|
|
[self.view addSubview:self.matchButton];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.mas_equalTo(self.view);
|
|
}];
|
|
|
|
[self.matchButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(118, 40));
|
|
make.right.mas_equalTo(self.view).offset(-5);
|
|
make.bottom.mas_equalTo(self.view).offset(-20);
|
|
}];
|
|
}
|
|
|
|
- (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.tableView.mj_header = header;
|
|
|
|
MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(footerRefresh)];
|
|
footer.stateLabel.textColor = [ThemeColor secondTextColor];
|
|
footer.stateLabel.font = [UIFont systemFontOfSize:10.0];
|
|
self.tableView.mj_footer = footer;
|
|
|
|
[self headerRefresh];
|
|
}
|
|
|
|
#pragma mark - 刷新的fangfa
|
|
- (void)headerRefresh {
|
|
self.page = 1;
|
|
[self.presenter getHomeLittleGameRoomList:self.page pageSize:20 state:0];
|
|
}
|
|
|
|
- (void)footerRefresh {
|
|
if (self.hasNoMoreData) {
|
|
[self showErrorToast:@"没有更多房间了"];
|
|
[self.tableView.mj_footer endRefreshing];
|
|
return;
|
|
}
|
|
self.page++;
|
|
[self.presenter getHomeLittleGameRoomList:self.page pageSize:20 state:1];
|
|
}
|
|
#pragma mark - UITableViewDelegate And UITableViewDataSource
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
return self.datasource.count > 0 ? self.datasource.count : 1;
|
|
}
|
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
return self.datasource.count > 0 ? 106 : 500;
|
|
}
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
if (self.datasource.count > 0) {
|
|
XPHomeLittleGameTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPHomeLittleGameTableViewCell class])];
|
|
if (cell == nil) {
|
|
cell = [[XPHomeLittleGameTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPHomeLittleGameTableViewCell class])];
|
|
}
|
|
cell.gameInfo = [self.datasource objectAtIndex:indexPath.row];
|
|
return cell;
|
|
}
|
|
XPHomeListEmptyTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPHomeListEmptyTableViewCell class])];
|
|
if (cell == nil) {
|
|
cell = [[XPHomeListEmptyTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPHomeListEmptyTableViewCell class])];
|
|
}
|
|
return cell;
|
|
}
|
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
|
if (self.datasource.count > 0) {
|
|
HomeLittleGameRoomModel * gameInfo = [self.datasource objectAtIndex:indexPath.row];
|
|
if (gameInfo.uid.length > 0) {
|
|
[XPRoomViewController openRoom:gameInfo.uid viewController:self];
|
|
}
|
|
}
|
|
}
|
|
|
|
#pragma mark - XPHomeLittleGameProtocol
|
|
- (void)quickMatchLittleGameRoomSuccess:(NSString *)uid {
|
|
if (uid.length > 0) {
|
|
[XPRoomViewController openRoom:uid viewController:self];
|
|
}
|
|
}
|
|
|
|
- (void)getHomeLittleGameRoomListSuccess:(NSArray *)array state:(int)state {
|
|
if (state == 0) {
|
|
self.hasNoMoreData = NO;
|
|
[self.datasource removeAllObjects];
|
|
[self.tableView.mj_header endRefreshing];
|
|
} else {
|
|
[self.tableView.mj_footer endRefreshing];
|
|
}
|
|
if (array.count > 0) {
|
|
self.hasNoMoreData = NO;
|
|
[self.datasource addObjectsFromArray:array];
|
|
} else {
|
|
self.hasNoMoreData = YES;
|
|
}
|
|
[self.tableView reloadData];
|
|
}
|
|
|
|
- (void)getHomeLittleGameRoomListFail:(NSString *)message state:(int)state {
|
|
if (state) {
|
|
[self.tableView.mj_header endRefreshing];
|
|
} else {
|
|
[self.tableView.mj_footer endRefreshing];
|
|
}
|
|
}
|
|
|
|
#pragma mark - JXCategoryListContentViewDelegate
|
|
- (UIView *)listView {
|
|
return self.view;
|
|
}
|
|
|
|
#pragma mark - Event Response
|
|
- (void)matchButtonAction:(UIButton *)sender {
|
|
[self.presenter quickMatchLittleGameRoom];
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (UITableView *)tableView {
|
|
if (!_tableView) {
|
|
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
|
|
_tableView.delegate = self;
|
|
_tableView.dataSource = self;
|
|
_tableView.tableFooterView = [UIView new];
|
|
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
|
_tableView.backgroundColor = [UIColor clearColor];
|
|
if (@available(iOS 11.0, *)) {
|
|
_tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
|
|
}
|
|
[_tableView registerClass:[XPHomeLittleGameTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPHomeLittleGameTableViewCell class])];
|
|
[_tableView registerClass:[XPHomeListEmptyTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPHomeListEmptyTableViewCell class])];
|
|
}
|
|
return _tableView;
|
|
}
|
|
|
|
- (UIButton *)matchButton {
|
|
if (!_matchButton) {
|
|
_matchButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_matchButton setTitle:@"快速匹配" forState:UIControlStateNormal];
|
|
[_matchButton setImage:[UIImage imageNamed:@"home_party_little_game_match"] forState:UIControlStateNormal];
|
|
[_matchButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
|
_matchButton.titleLabel.font = [UIFont systemFontOfSize:16];
|
|
[_matchButton setBackgroundImage:[UIImage gradientColorImageFromColors:@[[ThemeColor confirmButtonGradientStartColor], [ThemeColor confirmButtonGradientEndColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)] forState:UIControlStateNormal];
|
|
_matchButton.layer.masksToBounds = YES;
|
|
_matchButton.layer.cornerRadius = 20;
|
|
_matchButton.layer.shadowOffset = CGSizeMake(4, 4);
|
|
_matchButton.layer.shadowColor = UIColorRGBAlpha(0xFFAC38, 0.3).CGColor;
|
|
_matchButton.layer.opacity = 1;
|
|
[_matchButton addTarget:self action:@selector(matchButtonAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _matchButton;
|
|
}
|
|
|
|
- (NSMutableArray *)datasource {
|
|
if (!_datasource) {
|
|
_datasource = [NSMutableArray array];
|
|
}
|
|
return _datasource;
|
|
}
|
|
|
|
|
|
@end
|