夺宝精灵改动
This commit is contained in:
@@ -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;
|
||||
///正在播放声音的cell在UITableView的Y坐标
|
||||
@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.5秒播放录音,因为如果在麦上的话,需要先关麦再播放,所以要延时0.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
|
||||
|
Reference in New Issue
Block a user