夺宝精灵改动

This commit is contained in:
liyuhua
2023-09-07 19:01:31 +08:00
parent 4e6769dee5
commit 68e6959cd1
133 changed files with 2845 additions and 571 deletions

View File

@@ -22,6 +22,9 @@
#import "AccountInfoStorage.h"
#import "TTPopup.h"
#import "NSArray+Safe.h"
#import "CountDownHelper.h"
#import "XPSkillCardPlayerManager.h"
#import "UploadFile.h"
///View
#import "XPNewHomePlayTableViewCell.h"
#import "XPNewHomeRecommendTableViewCell.h"
@@ -30,7 +33,8 @@
#import "XPNewHomePartyTableViewCell.h"
#import "XPRoomViewController.h"
#import "XPWebViewController.h"
#import "XPMineUserInfoViewController.h"
#import "SessionViewController.h"
///Model
#import "HomePlayRoomModel.h"
#import "HomeBannerInfoModel.h"
@@ -40,24 +44,25 @@
#import "XPNewHomeRecommendPresenter.h"
#import "XPNewHomeRecommendProtocol.h"
UIKIT_EXTERN NSString * const kShieldingNotification;
@interface XPHomeRecommendViewController ()<UITableViewDelegate, UITableViewDataSource, XPNewHomePlayTableViewCellDelegate, XPHomeBannerTableViewCellDelegate,XPNewHomeRecommendTableViewCellDelegate,XPNewHomeRecommendProtocol>
{
NSTimer * timer;
}
@interface XPHomeRecommendViewController ()<UITableViewDelegate, UITableViewDataSource, XPNewHomePlayTableViewCellDelegate, XPHomeBannerTableViewCellDelegate,XPNewHomeRecommendTableViewCellDelegate,XPNewHomeRecommendProtocol,XPNewHomePartyTableViewCellDelegate,CountDownHelperDelegate>
///
@property (nonatomic,strong) UITableView *tableView;
///
@property (nonatomic,strong) NSArray<HomePlayRoomModel *> *playTeamList;
@property (nonatomic,copy) NSArray<HomePlayRoomModel *> *playTeamList;
///
@property (nonatomic,strong) NSArray<HomePlayRoomModel *> *personalRoomList;
@property (nonatomic,strong) NSMutableArray<HomePlayRoomModel *> *personalRoomList;
///
@property (nonatomic,strong) RoomInfoModel * roomInfo;
///,
@property (nonatomic,assign) BOOL isRequestData;
///
@property (nonatomic,strong) CountDownHelper *countDownHelper;
///cell
@property(nonatomic,strong)XPNewHomePartyTableViewCell *cell;
///cellUITableViewY
@property(nonatomic,assign) CGFloat cellY;
@end
@implementation XPHomeRecommendViewController
@@ -71,70 +76,79 @@ UIKIT_EXTERN NSString * const kShieldingNotification;
- (void)viewDidLoad {
[super viewDidLoad];
[self initSubViews];
[self addTimer];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if (timer) {
[timer setFireDate:[NSDate distantPast]]; //
}
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
self.countDownHelper.delegate = self;
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
if (timer) {
//
[timer setFireDate:[NSDate distantFuture]]; //
-(void)viewDidDisappear:(BOOL)animated{
[super viewDidAppear:animated];
[self.countDownHelper stopCountDown];
self.countDownHelper.delegate = nil;
[[XPSkillCardPlayerManager shareInstance] stopMusic];
if(self.cell != nil){
[self.cell setPlaySoundStatus:NO];
self.cell = nil;
}
}
-(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);
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 getFriendListWithGroup:group];
});
dispatch_group_notify(group,dispatch_get_main_queue(), ^{
self.isRequestData = NO;
[self.tableView reloadData];
if(self.cell != nil){
if(self.refreshComplete){
self.refreshComplete();
}
});
return;
}///
///退bug
@synchronized (self.presenter) {
if(self.isRequestData == YES){
if(self.refreshComplete){
self.refreshComplete();
}
return;
}
self.isRequestData = YES;
///
dispatch_group_t group =dispatch_group_create();
//
dispatch_queue_t queue =dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0);
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 getFriendListWithGroup:group];
});
dispatch_group_notify(group,dispatch_get_main_queue(), ^{
self.isRequestData = NO;
if(self.refreshComplete){
self.refreshComplete();
}
[self.tableView reloadData];
});
}
}
- (void)headerRefresh {
@@ -176,20 +190,20 @@ UIKIT_EXTERN NSString * const kShieldingNotification;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.section == 0) {
XPNewHomePlayTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPNewHomePlayTableViewCell class])];
if (cell == nil) {
cell = [[XPNewHomePlayTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPNewHomePlayTableViewCell class])];
}
cell.playRoomList = self.playTeamList;
cell.delegate = self;
return cell;
}
if(indexPath.section == 0) {
XPNewHomePlayTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPNewHomePlayTableViewCell class])];
if (cell == nil) {
cell = [[XPNewHomePlayTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPNewHomePlayTableViewCell class])];
}
cell.playRoomList = self.playTeamList;
cell.delegate = self;
return cell;
}
if(self.personalRoomList.count == 0){
XPNewHomePlayEmptyTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPNewHomePlayEmptyTableViewCell class])];
if (cell == nil) {
@@ -200,26 +214,29 @@ UIKIT_EXTERN NSString * const kShieldingNotification;
[cell setTitle:YMLocalizedString(@"XPGuildEmptyCollectionViewCell0")];
return cell;
}
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;
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];
cell.delegate = self;
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 0.01;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 0.01;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 0.01;
}
@@ -237,6 +254,21 @@ UIKIT_EXTERN NSString * const kShieldingNotification;
}
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
if(self.cell != nil){
if(scrollView.contentOffset.y > self.cellY){
[self.countDownHelper stopCountDown];
self.countDownHelper .delegate = nil;
[[XPSkillCardPlayerManager shareInstance] stopMusic];
[self.cell setPlaySoundStatus:NO];
self.cell = nil;
}
}
if(self.scrollCallback){
self.scrollCallback(scrollView);
}
}
#pragma mark - XPNewHomeRecommendTableViewCellDelegate
- (void)xPNewHomeRecommendTableViewCell:(XPNewHomeRecommendTableViewCell *)view didSelectItem:(HomeRecommendRoomModel *)info {
if (info.roomUid.length > 0) {
@@ -251,19 +283,19 @@ UIKIT_EXTERN NSString * const kShieldingNotification;
}
}
- (void)chooseGameAction{
// XPHomeGameView *gameView = [XPHomeGameView new];
// gameView.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight);
// gameView.playGameList = self.littleGameArray;
// gameView.delegate = self;
// [kWindow addSubview:gameView];
// 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];
// 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 {
@@ -301,6 +333,21 @@ UIKIT_EXTERN NSString * const kShieldingNotification;
dispatch_group_leave(group);
}
- (void)getFriendListSuccess:(NSArray *)list withGroup:(dispatch_group_t)group{
for (int i = 0;i < list.count;i++) {
HomePlayRoomModel *model = list[i];
NSMutableArray *labels = [NSMutableArray array];
[labels addObject:[NSString calculateConstellationWithMonth:model.birth] ?: @""];
[labels addObjectsFromArray:model.labels];
model.labels = labels;
NSMutableArray *widthList = [NSMutableArray array];
for (NSString *text in model.labels) {
CGFloat width = [UILabel getWidthWithText:text height:kGetScaleWidth(18) font:kFontRegular(10)] + kGetScaleWidth(16) + 1;
[widthList addObject:@(width)];
}
model.labelsWidthList = widthList;
}
self.personalRoomList = [NSMutableArray arrayWithArray:list];
dispatch_group_leave(group);
}
@@ -320,14 +367,106 @@ UIKIT_EXTERN NSString * const kShieldingNotification;
return self.view;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if(self.scrollCallback){
self.scrollCallback(scrollView);
#pragma mark- XPNewHomePartyTableViewCellDelegate
///
-(void)xPNewHomePartyTableViewCell:(XPNewHomePartyTableViewCell *_Nullable)cell didSelectItem:(HomePlayRoomModel *_Nullable)roomModel{
XPMineUserInfoViewController *infoVC = [[XPMineUserInfoViewController alloc]init];
infoVC.uid = [roomModel.uid integerValue];
[self.navigationController pushViewController:infoVC animated:YES];
}
///
-(void)xPNewHomePartyTableViewCell:(XPNewHomePartyTableViewCell *_Nullable)cell didSelectChat:(HomePlayRoomModel *_Nonnull)roomModel{
if(roomModel.inMic == YES){
[XPRoomViewController openRoom:roomModel.uid fromNick:nil fromType:UserEnterRoomFromType_Home_Recommend fromUid:nil viewController:self];
return;
}
NIMSession * session = [NIMSession session:roomModel.uid type:NIMSessionTypeP2P];
SessionViewController * sessionVC = [[SessionViewController alloc] initWithSession:session];
[self.navigationController pushViewController:sessionVC animated:YES];
}
///
-(void)xPNewHomePartyTableViewCell:(XPNewHomePartyTableViewCell *_Nullable)cell didPlayVoice:(HomePlayRoomModel *_Nonnull)roomModel didClickPlaySound:(BOOL)isPlay{
if(isPlay == YES){
self.cell = cell;
CGRect cellRect = [self.tableView rectForRowAtIndexPath:[self.tableView indexPathForCell:self.cell]];
self.cellY = cellRect.origin.y;
NSString *fileName = [[roomModel.userVoice componentsSeparatedByString:@"/"] lastObject];
NSString *filePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) safeObjectAtIndex1:0] stringByAppendingPathComponent:@"kMineSoundCard"];
NSString *fullPath = [filePath stringByAppendingPathComponent:fileName];
if ([[NSFileManager defaultManager] fileExistsAtPath:fullPath]) {
[self playAudioWithUrl:fullPath isDelay:[XPSkillCardPlayerManager shareInstance].isMineInMic];
}else{
if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
NSFileManager *fileMgr = [[NSFileManager alloc] init];
[fileMgr createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil];
}
[UploadFile downloadAudioWithFileName:fileName musicUrl:roomModel.userVoice mainFileName:@"kMineSoundCard" completion:^(BOOL isSuccess, NSString *editAudioPath) {
if(isSuccess){
[self playAudioWithUrl:editAudioPath isDelay:[XPSkillCardPlayerManager shareInstance].isMineInMic];
}else{
[self.cell setPlaySoundStatus:NO];
[[XPSkillCardPlayerManager shareInstance] stopMusic];
self.cell = nil;
}
}];
}
}else{
[self.countDownHelper stopCountDown];
[self.cell setPlaySoundStatus:NO];
[[XPSkillCardPlayerManager shareInstance] stopMusic];
self.cell = nil;
}
}
///
/// - Parameters:
/// - url:
/// - isDelay: 0.50.5
-(void)playAudioWithUrl:(NSString*)url isDelay:(BOOL)isDelay{
if(isDelay == YES){
[[XPSkillCardPlayerManager shareInstance] playerNewVoiceWithPath:url completionBlock:^{
[[XPSkillCardPlayerManager shareInstance] stopMusic];
}];
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
NSInteger getCurrentTime = ceil([self.cell.roomInfo.voiceDura integerValue]);
[self.countDownHelper openCountdownWithTime:(int)getCurrentTime];
});
return;
}
NSInteger getCurrentTime = ceil([self.cell.roomInfo.voiceDura integerValue]);
[self.countDownHelper openCountdownWithTime:(int)getCurrentTime];
[[XPSkillCardPlayerManager shareInstance] playerVoiceWithPath:url completionBlock:^{
[[XPSkillCardPlayerManager shareInstance] stopMusic];
}];
}
///
- (void)onCountdownFinish{
if(self.cell != nil){
[self.cell setPlaySoundTime:0];
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[self.cell setPlaySoundStatus:NO];
self.cell = nil;
});
}
}
///
- (void)onCountdownOpen:(int)time{
if(self.cell != nil){
[self.cell setPlaySoundTime:(int)time + 1];
}
}
- (UITableView *)tableView {
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
@@ -345,4 +484,10 @@ UIKIT_EXTERN NSString * const kShieldingNotification;
}
return _tableView;
}
- (CountDownHelper *)countDownHelper{
if (!_countDownHelper){
_countDownHelper = [[CountDownHelper alloc]init];
}
return _countDownHelper;
}
@end