BGConversationServiceController.m 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069
  1. //
  2. // BGConversationServiceController.m
  3. // BuguLive
  4. //
  5. // Created by 朱庆彬 on 2017/8/18.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "BGConversationServiceController.h"
  9. #import "ExchangeCoinView.h"
  10. #import "ExchangeView.h"
  11. #import "GiftView.h"
  12. #import "IncomeViewController.h"
  13. #import "OtherChangeView.h"
  14. #import "RechargeView.h"
  15. #import "SHomePageVC.h"
  16. #import "dataModel.h"
  17. #import "BogoRechargePopView.h"
  18. #import "AudioChatTool.h"
  19. @interface BGConversationServiceController () <GiftViewDelegate, ExchangeCoinViewDelegate, RechargeViewDelegate, ExchangeViewDelegate, OtherChangeViewDelegate,AudioChatToolDelegate>
  20. {
  21. ExchangeCoinView *_exchangeView;
  22. UIWindow *_bgWindow;
  23. UIView *_exchangeBgView;
  24. ExchangeCoinView *_sendDiamondView;
  25. UIWindow *_sendDiamondbgWindow;
  26. UIView *_sendDiamondBgView;
  27. }
  28. @property (nonatomic, strong) RechargeView *rechargeView;
  29. @property (nonatomic, strong) ExchangeView *exchangeCoinView;
  30. @property (nonatomic, strong) OtherChangeView *otherChangeView;
  31. @property(nonatomic, strong) BogoRechargePopView *rechargePopView;
  32. @property (nonatomic,assign) BOOL isApplyingAudioChat;
  33. @property (nonatomic,assign) BOOL isApplyingVideoChat;
  34. @end
  35. @implementation BGConversationServiceController
  36. + (BGConversationServiceController *)makeChatVCWith:(SFriendObj *)chattag isHalf:(BOOL)mbhalf
  37. {
  38. BGConversationServiceController *chatvc = [[BGConversationServiceController alloc] initWithNibName:@"BGBaseChatController" bundle:nil];
  39. chatvc.mbhalf = mbhalf;
  40. chatvc.hidesBottomBarWhenPushed = YES;
  41. chatvc.mChatFriend = chattag;
  42. return chatvc;
  43. }
  44. + (BGConversationServiceController *)makeChatVCWith:(SFriendObj *)chattag
  45. {
  46. BGConversationServiceController *chatvc = [[BGConversationServiceController alloc] initWithNibName:@"BGBaseChatController" bundle:nil];
  47. chatvc.hidesBottomBarWhenPushed = YES;
  48. chatvc.mChatFriend = chattag;
  49. return chatvc;
  50. }
  51. - (void)dealloc
  52. {
  53. [[NSNotificationCenter defaultCenter] removeObserver:self];
  54. }
  55. - (void)viewDidLoad
  56. {
  57. self.mCannotLoadNewestMsg = YES;
  58. [super viewDidLoad];
  59. self.mtoptitle.text = self.mChatFriend.mNick_name;
  60. [self cfgmoremoregiftview];
  61. if (self.BuguLive.appModel.open_send_coins_module == 1)
  62. {
  63. [self createExchangeCoinView];
  64. }
  65. if (self.BuguLive.appModel.open_send_diamonds_module == 1)
  66. {
  67. [self createSendDiamondView];
  68. }
  69. [SFriendObj ignoreMsg:@[self.mChatFriend]
  70. block:^(SResBase *resb){
  71. }];
  72. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IMChatMsgNotfication:) name:g_notif_chatmsg object:nil];
  73. self.view.backgroundColor = kWhiteColor;
  74. id traget = self.navigationController.interactivePopGestureRecognizer.delegate;
  75. UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc]initWithTarget:traget action:nil];
  76. [self.view addGestureRecognizer:pan];
  77. self.clickBGBlock = ^(BOOL isRefresh) {
  78. self.mGiftView.hidden = YES;
  79. };
  80. AudioChatTool.shareInstance.delegate = self;
  81. }
  82. -(void)sendTimes:(NSString *)msg{
  83. // [self willSendThisText:msg];
  84. [self.mChatFriend sendTextMsg:msg
  85. block:^(SResBase *resb, SIMMsgObj *newObj) {
  86. if (!resb.msuccess)
  87. {
  88. [SVProgressHUD showErrorWithStatus:resb.mmsg];
  89. }else{
  90. [self didSendThisMsg:newObj];
  91. // [[V2TIMManager sharedInstance] markC2CMessageAsRead:@"" succ:^{
  92. // NSLog(@"设置已读成功");
  93. // } fail:^(int code, NSString *desc) {
  94. //
  95. // }];
  96. // [self.mChatFriend ignoreThisUnReadCount];
  97. }
  98. }];
  99. // if (obj)
  100. // [self addOneMsg:obj];
  101. // [self.mChatFriend ignoreThisUnReadCount];
  102. // [self willSendThisText:msg];
  103. }
  104. - (void)viewWillAppear:(BOOL)animated
  105. {
  106. [super viewWillAppear:animated];
  107. self.navigationController.navigationBarHidden = YES;
  108. }
  109. - (void)viewWillDisappear:(BOOL)animated
  110. {
  111. [super viewWillAppear:animated];
  112. if (self.mbhalf == NO) {
  113. self.navigationController.navigationBarHidden = NO;
  114. }
  115. }
  116. - (void)IMChatMsgNotfication:(NSNotification *)notifcation
  117. {
  118. if (![NSThread isMainThread])
  119. {
  120. [self performSelectorOnMainThread:@selector(IMChatMsgNotfication:) withObject:notifcation waitUntilDone:NO];
  121. return;
  122. }
  123. SIMMsgObj *thatmsg = (SIMMsgObj *) notifcation.object;
  124. if (thatmsg.mSenderId == self.mChatFriend.mUser_id)
  125. { //如果是这个人的消息,就显示出来
  126. if (thatmsg.mMsgType == MSG_PRIVATE_CallAudio || thatmsg.mMsgType == MSG_PRIVATE_CallVideo) {
  127. } else {
  128. //并且还要清除 未读
  129. // [self.mChatFriend ignoreThisUnReadCount];
  130. [self addOneMsg:thatmsg];
  131. }
  132. }
  133. }
  134. - (void)getMsgBefor:(ConversationModel *)msg block:(void (^)(NSArray *all))block
  135. {
  136. [self.mChatFriend getMsgList:YES
  137. posmsg:(SIMMsgObj *) msg
  138. block:^(SResBase *resb, NSArray *all) {
  139. if (!resb.msuccess)
  140. {
  141. [SVProgressHUD showErrorWithStatus:resb.mmsg];
  142. }
  143. block(all);
  144. }];
  145. }
  146. - (void)clickedtophead:(UIButton *)sender
  147. {
  148. SHomePageVC *tmpController = [[SHomePageVC alloc] init];
  149. tmpController.user_id = [NSString stringWithFormat:@"%d", self.mChatFriend.mUser_id];
  150. // tmpController.user_nickname = self.mChatFriend.mNick_name;
  151. tmpController.type = 0;
  152. [self.navigationController pushViewController:tmpController animated:NO];
  153. }
  154. - (void)willSendThisText:(NSString *)txt
  155. {
  156. [super willSendThisText:txt];
  157. SIMMsgObj *obj =
  158. [self.mChatFriend sendTextMsg:txt
  159. block:^(SResBase *resb, SIMMsgObj *newObj) {
  160. if (!resb.msuccess)
  161. {
  162. [SVProgressHUD showErrorWithStatus:resb.mmsg];
  163. }
  164. [self didSendThisMsg:newObj];
  165. }];
  166. if (obj)
  167. [self addOneMsg:obj];
  168. }
  169. - (void)willSendThisImg:(UIImage *)img
  170. {
  171. [super willSendThisImg:img];
  172. SIMMsgObj *ss =
  173. [self.mChatFriend sendPicMsg:img
  174. block:^(SResBase *resb, SIMMsgObj *thatmsg) {
  175. if (!resb.msuccess)
  176. {
  177. [SVProgressHUD showErrorWithStatus:resb.mmsg];
  178. }
  179. [self didSendThisMsg:thatmsg];
  180. }];
  181. if (ss)
  182. [self addOneMsg:ss];
  183. }
  184. - (void)willSendThisVoice:(NSURL *)voicepath duration:(NSTimeInterval)duration
  185. {
  186. if (duration < 1)
  187. {
  188. [SVProgressHUD showErrorWithStatus:ASLocalizedString(@"说话时间太短,取消发送!")];
  189. return;
  190. }
  191. [super willSendThisVoice:voicepath duration:duration];
  192. SIMMsgObj *ss =
  193. [self.mChatFriend sendVoiceMsg:voicepath
  194. duration:duration
  195. block:^(SResBase *resb, SIMMsgObj *thatmsg) {
  196. if (!resb.msuccess)
  197. {
  198. [SVProgressHUD showErrorWithStatus:resb.mmsg];
  199. }
  200. [self didSendThisMsg:thatmsg];
  201. }];
  202. if (ss)
  203. [self addOneMsg:ss];
  204. }
  205. - (void)willReSendThisMsg:(ConversationModel *)msg
  206. {
  207. [super willReSendThisMsg:msg];
  208. [self.mChatFriend reSendMsg:(SIMMsgObj *) msg
  209. block:^(SResBase *resb, SIMMsgObj *thatmsg) {
  210. if (!resb.msuccess)
  211. {
  212. [SVProgressHUD showErrorWithStatus:resb.mmsg];
  213. }
  214. [self didSendThisMsg:thatmsg];
  215. }];
  216. }
  217. - (void)wantFetchMsg:(ConversationModel *)msg block:(void (^)(NSString *, ConversationModel *))block
  218. {
  219. [super wantFetchMsg:msg block:block];
  220. }
  221. - (void)msgClicked:(ConversationModel *)msgobj
  222. {
  223. [super msgClicked:msgobj];
  224. if (msgobj.mMsgType == 4)
  225. {
  226. if (!msgobj.mIsSendOut)
  227. {
  228. if (!self.mbhalf)
  229. {
  230. //如果不包含游戏币就能跳转
  231. if (![msgobj.mGiftDesc containsString:ASLocalizedString(@"游戏币")] && ![msgobj.mGiftDesc containsString:self.BuguLive.appModel.diamond_name])
  232. {
  233. IncomeViewController *incomeVC = [[IncomeViewController alloc] init];
  234. [self.navigationController pushViewController:incomeVC animated:YES];
  235. }
  236. }
  237. }
  238. }
  239. }
  240. - (void)cfgmoremoregiftview
  241. {
  242. NSArray *list = [GiftListManager sharedInstance].giftMArray;
  243. NSMutableArray *giftMArray = [NSMutableArray array];
  244. if (list && [list isKindOfClass:[NSArray class]])
  245. {
  246. for (NSDictionary *key in list)
  247. {
  248. GiftModel *giftModel = [GiftModel mj_objectWithKeyValues:key];
  249. [giftMArray addObject:giftModel];
  250. }
  251. }
  252. CGFloat _giftViewHeight = KGiftViewHeight;
  253. // MorePanH + MG_BOTTOM_MARGIN;
  254. //礼物视图
  255. GiftView *_giftView = [[GiftView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, _giftViewHeight)];
  256. _giftView.delegate = self;
  257. _giftView.hidden = YES;
  258. [_giftView setGiftView:giftMArray];
  259. //[self addSubview:_giftView];
  260. // long _currentDiamonds = [[IMAPlatform sharedInstance].host getDiamonds];
  261. // [_giftView setDiamondsLabelTxt:[NSString stringWithFormat:@"%ld",_currentDiamonds]];
  262. //
  263. self.mGiftView = _giftView;
  264. [self.view addSubview:_giftView];
  265. //刷新砖石数目
  266. [self refreshDiamonds];
  267. }
  268. - (void)showRechargeView:(GiftView *)giftView
  269. {
  270. [self.rechargePopView show:[UIApplication sharedApplication].keyWindow type:FDPopTypeBottom];
  271. // self.rechargeView.hidden = NO;
  272. // [self.rechargeView loadRechargeData];
  273. // [UIView animateWithDuration:0.5 animations:^{
  274. // //_rechargeView.frame = CGRectMake(10, (kScreenH-kRechargeViewHeight)/2, kScreenW-20, kRechargeViewHeight);
  275. // _rechargeView.transform = CGAffineTransformMakeTranslation(0, (kScreenH-kRechargeViewHeight)/2-kScreenH);
  276. // } completion:^(BOOL finished) {
  277. //
  278. // }];
  279. }
  280. - (void)senGift:(GiftView *)giftView AndGiftModel:(GiftModel *)giftModel
  281. {
  282. //[SVProgressHUD showWithStatus:ASLocalizedString(@"正在发送礼物...")];
  283. [self.mChatFriend sendGiftMsg:giftModel
  284. block:^(SResBase *resb, SIMMsgObj *thatmsg) {
  285. if (!resb.msuccess)
  286. {
  287. // 刷新钻石
  288. [self refreshDiamonds];
  289. //[SVProgressHUD showErrorWithStatus:resb.mmsg];
  290. [SVProgressHUD dismiss];
  291. }
  292. else
  293. { // 如果成功了,刷新钻石
  294. FWWeakify(self)
  295. [[IMAPlatform sharedInstance].host getMyInfo:^(AppBlockModel *blockModel) {
  296. FWStrongify(self)
  297. long currentDiamonds = [[IMAPlatform sharedInstance].host getDiamonds];
  298. [(GiftView *) self.mGiftView setDiamondsLabelTxt:[NSString stringWithFormat:@"%ld", currentDiamonds]];
  299. }];
  300. [SVProgressHUD dismiss];
  301. }
  302. [self didSendThisMsg:thatmsg];
  303. }];
  304. }
  305. #pragma mark -返回按键 方法
  306. //ykk 重写父类的返回方法
  307. - (void)backclicked:(id)sender
  308. {
  309. if ([self.navigationController topViewController] == self)
  310. { //如果有导航控制器,,并且顶部就是自己,,那么应该 返回
  311. if (self.navigationController.viewControllers.count == 1)
  312. { //如果只有一个,,,那么
  313. if (self.presentingViewController)
  314. { //如果有,,那么就dismiss
  315. [self dismissViewControllerAnimated:YES
  316. completion:^{
  317. }];
  318. return;
  319. }
  320. else
  321. {
  322. [self backOrGoNextVCBlock:1];
  323. }
  324. }
  325. else
  326. [self.navigationController popViewControllerAnimated:YES];
  327. }
  328. else //其他情况,就再判断是否有 presentingViewController
  329. if (self.presentingViewController)
  330. { //如果有,,那么就dismiss
  331. [self dismissViewControllerAnimated:YES
  332. completion:^{
  333. }];
  334. return;
  335. }
  336. else
  337. {
  338. [self backOrGoNextVCBlock:1];
  339. }
  340. }
  341. #pragma mark -goNextVC
  342. //ykk
  343. - (void)backOrGoNextVCBlock:(int)tag
  344. {
  345. NSLog(@"%s", __func__);
  346. //1返回 2 去下个界面
  347. if (self.backOrGoNextVCBlock)
  348. {
  349. self.backOrGoNextVCBlock(tag);
  350. }
  351. }
  352. #pragma 加载半imMsgVC
  353. //ykk 加载banVC
  354. + (BGConversationServiceController *)createIMMsgVCWithHalfWith:(SFriendObj *)friend_Obj form:(UIViewController *)full_VC
  355. isRelive:(BOOL)sender
  356. {
  357. //1.0
  358. BGConversationServiceController *imMsgChat_VC = [[BGConversationServiceController alloc] initWithNibName:@"BGBaseChatController"
  359. bundle:nil];
  360. //1.2
  361. imMsgChat_VC.mbhalf = YES;
  362. imMsgChat_VC.mChatFriend = friend_Obj;
  363. //1.1
  364. imMsgChat_VC.view.frame = CGRectMake(kScreenW, kScreenH / 2, kScreenW, kScreenH / 2 );
  365. //1.3
  366. [UIView animateWithDuration:kHalfVCViewanimation
  367. animations:^{
  368. imMsgChat_VC.view.x = 0;
  369. }
  370. completion:^(BOOL finished){
  371. }];
  372. //2.
  373. BGLiveServiceController *live_VC = (BGLiveServiceController *) full_VC;
  374. //
  375. [live_VC addChildViewController:imMsgChat_VC];
  376. [live_VC.view addSubview:imMsgChat_VC.view];
  377. [live_VC.view bringSubviewToFront:imMsgChat_VC.view];
  378. return imMsgChat_VC;
  379. }
  380. #pragma mark 刷新钻石数量
  381. - (void)refreshDiamonds
  382. {
  383. FWWeakify(self)
  384. [[IMAPlatform sharedInstance].host getMyInfo:^(AppBlockModel *blockModel) {
  385. FWStrongify(self)
  386. long currentDiamonds = [[IMAPlatform sharedInstance].host getDiamonds];
  387. [(GiftView *) self.mGiftView setDiamondsLabelTxt:[NSString stringWithFormat:@"%ld", currentDiamonds]];
  388. }];
  389. }
  390. #pragma mark-----------------------------赠送游戏币相关---------------------------
  391. #pragma mark 创建赠送游戏币视图
  392. - (void)createExchangeCoinView
  393. {
  394. // [SUS_WINDOW.rootViewController presentViewController:alertC animated:YES completion:nil];
  395. if (!SUS_WINDOW.isSusWindow)
  396. {
  397. _bgWindow = [[UIApplication sharedApplication].delegate window];
  398. }
  399. else
  400. {
  401. _bgWindow = SUS_WINDOW;
  402. }
  403. if (!_exchangeView)
  404. {
  405. _exchangeBgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
  406. _exchangeBgView.backgroundColor = kGrayTransparentColor4;
  407. _exchangeBgView.hidden = YES;
  408. [_bgWindow addSubview:_exchangeBgView];
  409. UITapGestureRecognizer *bgViewTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(exchangeBgViewTap)];
  410. [_exchangeBgView addGestureRecognizer:bgViewTap];
  411. _exchangeView = [ExchangeCoinView EditNibFromXib];
  412. _exchangeView.exchangeType = 3;
  413. _exchangeView.delegate = self;
  414. _exchangeView.frame = CGRectMake((kScreenW - 300) / 2, kScreenH, 270, 246);
  415. [_exchangeView createSomething];
  416. [_bgWindow addSubview:_exchangeView];
  417. NSLog(@"++++****%@", _exchangeView);
  418. }
  419. }
  420. - (void)createSendDiamondView
  421. {
  422. // [SUS_WINDOW.rootViewController presentViewController:alertC animated:YES completion:nil];
  423. if (!SUS_WINDOW.isSusWindow)
  424. {
  425. _sendDiamondbgWindow = [[UIApplication sharedApplication].delegate window];
  426. }
  427. else
  428. {
  429. _sendDiamondbgWindow = SUS_WINDOW;
  430. }
  431. if (!_sendDiamondView)
  432. {
  433. _sendDiamondBgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
  434. _sendDiamondBgView.backgroundColor = kGrayTransparentColor4;
  435. _sendDiamondBgView.hidden = YES;
  436. [_sendDiamondbgWindow addSubview:_sendDiamondBgView];
  437. UITapGestureRecognizer *bgViewTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(sendDiamondViewTap)];
  438. [_sendDiamondBgView addGestureRecognizer:bgViewTap];
  439. _sendDiamondView = [ExchangeCoinView EditNibFromXib];
  440. _sendDiamondView.exchangeType = 4;
  441. _sendDiamondView.delegate = self;
  442. _sendDiamondView.frame = CGRectMake((kScreenW - 300) / 2, kScreenH, 300, 230);
  443. [_sendDiamondView createSomething];
  444. [_sendDiamondbgWindow addSubview:_sendDiamondView];
  445. NSLog(@"++++****%@", _sendDiamondView);
  446. }
  447. }
  448. #pragma mark ExchangeCoinViewDelegate代理
  449. - (void)comfirmClickWithExchangeCoinView:(ExchangeCoinView *)exchangeCoinView
  450. {
  451. if (_exchangeView == exchangeCoinView)
  452. {
  453. [self sendCoinRequest:_exchangeView.diamondLeftTextfield.text];
  454. }
  455. else if (_sendDiamondView == exchangeCoinView)
  456. {
  457. [self sendDiamondsRequest:_sendDiamondView.diamondLeftTextfield.text];
  458. }
  459. }
  460. - (void)exchangeViewDownWithExchangeCoinView:(ExchangeCoinView *)exchangeCoinView
  461. {
  462. if (self.mbhalf)
  463. {
  464. //[self clickedfacemore:NO];
  465. }
  466. if (_exchangeView == exchangeCoinView)
  467. {
  468. [_exchangeView.diamondLeftTextfield resignFirstResponder];
  469. _exchangeView.diamondLeftTextfield.text = nil;
  470. [UIView animateWithDuration:0.3
  471. animations:^{
  472. _exchangeView.frame = CGRectMake((kScreenW - 270) / 2, kScreenH, 270, 246);
  473. }
  474. completion:^(BOOL finished) {
  475. _exchangeBgView.hidden = YES;
  476. }];
  477. }
  478. else if (_sendDiamondView == exchangeCoinView)
  479. {
  480. [_sendDiamondView.diamondLeftTextfield resignFirstResponder];
  481. _sendDiamondView.diamondLeftTextfield.text = nil;
  482. [UIView animateWithDuration:0.3
  483. animations:^{
  484. _sendDiamondView.frame = CGRectMake((kScreenW - 300) / 2, kScreenH, 300, 230);
  485. }
  486. completion:^(BOOL finished) {
  487. _sendDiamondBgView.hidden = YES;
  488. }];
  489. }
  490. }
  491. - (void)exchangeBgViewTap
  492. {
  493. [self exchangeViewDownWithExchangeCoinView:_exchangeView];
  494. }
  495. - (void)sendDiamondViewTap
  496. {
  497. [self exchangeViewDownWithExchangeCoinView:_sendDiamondView];
  498. }
  499. - (void)sendCoin
  500. {
  501. NSLog(@"%d", self.mChatFriend.mUser_id);
  502. // [self createAlertController];
  503. [self displayExchangeView];
  504. }
  505. - (void)displayExchangeView
  506. {
  507. [self updateCoinWithExchangeCoinView:_exchangeView];
  508. [_bgWindow bringSubviewToFront:_exchangeBgView];
  509. [_bgWindow bringSubviewToFront:_exchangeView];
  510. [UIView animateWithDuration:0.3
  511. animations:^{
  512. _exchangeBgView.hidden = NO;
  513. [_exchangeView.diamondLeftTextfield becomeFirstResponder];
  514. if (self.mbhalf)
  515. {
  516. _exchangeView.frame = CGRectMake((kScreenW - 270) / 2, (kScreenH - 350) / 2, 270, 246);
  517. }
  518. else
  519. {
  520. _exchangeView.frame = CGRectMake((kScreenW - 270) / 2, (kScreenH - 450) / 2, 270, 246);
  521. }
  522. }];
  523. }
  524. - (void)sendDiamonds
  525. {
  526. NSLog(@"%d", self.mChatFriend.mUser_id);
  527. [self displaySendDiamondView];
  528. }
  529. - (void)displaySendDiamondView
  530. {
  531. [self updateCoinWithExchangeCoinView:_sendDiamondView];
  532. [_sendDiamondbgWindow bringSubviewToFront:_sendDiamondBgView];
  533. [_sendDiamondbgWindow bringSubviewToFront:_sendDiamondView];
  534. [UIView animateWithDuration:0.3
  535. animations:^{
  536. _sendDiamondBgView.hidden = NO;
  537. [_sendDiamondView.diamondLeftTextfield becomeFirstResponder];
  538. if (self.mbhalf)
  539. {
  540. _sendDiamondView.frame = CGRectMake((kScreenW - 300) / 2, (kScreenH - 350) / 2, 300, 230);
  541. }
  542. else
  543. {
  544. _sendDiamondView.frame = CGRectMake((kScreenW - 300) / 2, (kScreenH - 450) / 2, 300, 230);
  545. }
  546. }];
  547. }
  548. - (void)createAlertController
  549. {
  550. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:ASLocalizedString(@"赠送游戏币")message:nil
  551. preferredStyle:UIAlertControllerStyleAlert];
  552. //确定:UIAlertActionStyleDefault
  553. UIAlertAction *okAction = [UIAlertAction actionWithTitle:ASLocalizedString(@"确定")style:UIAlertActionStyleDestructive
  554. handler:^(UIAlertAction *_Nonnull action) {
  555. _coinTextField = alertController.textFields.firstObject;
  556. if ([_coinTextField.text integerValue] > 0)
  557. {
  558. // [self postSendCoinRequest:_coinTextField.text];
  559. [self sendCoinRequest:_coinTextField.text];
  560. }
  561. else
  562. {
  563. [SVProgressHUD showInfoWithStatus:ASLocalizedString(@"请输入金额")];
  564. }
  565. [self clickedfacemore:NO];
  566. }];
  567. [alertController addAction:okAction];
  568. [alertController addTextFieldWithConfigurationHandler:^(UITextField *_Nonnull textField) {
  569. textField.keyboardType = UIKeyboardTypeNumberPad;
  570. textField.placeholder = ASLocalizedString(@"请输入金额");
  571. }];
  572. //取消:UIAlertActionStyleDestructive
  573. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:ASLocalizedString(@"取消")style:UIAlertActionStyleCancel
  574. handler:^(UIAlertAction *_Nonnull action) {
  575. [self clickedfacemore:NO];
  576. }];
  577. [alertController addAction:cancelAction];
  578. [self presentViewController:alertController animated:YES completion:nil];
  579. }
  580. #pragma mark-- 获取游戏币余额
  581. - (void)updateCoinWithExchangeCoinView:(ExchangeCoinView *)sendView
  582. {
  583. NSMutableDictionary *parmDict = [[NSMutableDictionary alloc] init];
  584. [parmDict setObject:@"games" forKey:@"ctl"];
  585. [parmDict setObject:@"userDiamonds" forKey:@"act"];
  586. [[NetHttpsManager manager] POSTWithParameters:parmDict
  587. SuccessBlock:^(NSDictionary *responseJson) {
  588. if ([responseJson toInt:@"status"] == 1)
  589. {
  590. if (sendView == _exchangeView)
  591. {
  592. NSString *coinStr = [responseJson toString:@"coin"];
  593. _exchangeView.ticket = coinStr;
  594. _exchangeView.diamondLabel.text = [NSString stringWithFormat:ASLocalizedString(@"游戏币余额:%@"), _exchangeView.ticket];
  595. }
  596. else if (sendView == _sendDiamondView)
  597. {
  598. NSString *coinStr = [responseJson toString:@"user_diamonds"];
  599. _sendDiamondView.ticket = coinStr;
  600. _sendDiamondView.diamondLabel.text = [NSString stringWithFormat:ASLocalizedString(@"钻石余额:%@"), _sendDiamondView.ticket];
  601. }
  602. }
  603. }
  604. FailureBlock:^(NSError *error){
  605. }];
  606. }
  607. #pragma mark 赠送金币请求
  608. - (void)sendCoinRequest:(NSString *)coin
  609. {
  610. // [SVProgressHUD showWithStatus:ASLocalizedString(@"正在赠送游戏币...")];
  611. [self.mChatFriend sendCoinMsgWithCoin:coin
  612. block:^(SResBase *resb, SIMMsgObj *thatmsg) {
  613. if (!resb.msuccess)
  614. {
  615. [[BGHUDHelper sharedInstance] tipMessage:resb.mmsg];
  616. }
  617. [[NSNotificationCenter defaultCenter] postNotificationName:@"updateCoin" object:nil];
  618. [self didSendThisMsg:thatmsg];
  619. }];
  620. }
  621. #pragma mark 赠送钻石请求
  622. - (void)sendDiamondsRequest:(NSString *)diamonds
  623. {
  624. [self.mChatFriend sendDiamondsMsgWithDiamonds:diamonds
  625. block:^(SResBase *resb, SIMMsgObj *thatmsg) {
  626. if (!resb.msuccess)
  627. {
  628. // 刷新钻石
  629. [self refreshDiamonds];
  630. //[SVProgressHUD showErrorWithStatus:resb.mmsg];
  631. [SVProgressHUD dismiss];
  632. }
  633. else
  634. { // 如果成功了,刷新钻石
  635. FWWeakify(self)
  636. [[IMAPlatform sharedInstance].host getMyInfo:^(AppBlockModel *blockModel) {
  637. FWStrongify(self)
  638. long currentDiamonds = [[IMAPlatform sharedInstance].host getDiamonds];
  639. [(GiftView *) self.mGiftView setDiamondsLabelTxt:[NSString stringWithFormat:@"%ld", currentDiamonds]];
  640. }];
  641. [SVProgressHUD dismiss];
  642. }
  643. [self didSendThisMsg:thatmsg];
  644. }];
  645. }
  646. - (RechargeView *) rechargeView
  647. {
  648. if (_rechargeView == nil)
  649. {
  650. _rechargeView = [[RechargeView alloc] initWithFrame:CGRectMake(kRechargeMargin, kScreenH, kScreenW-2*kRechargeMargin, kRechargeViewHeight) andUIViewController:self];
  651. _rechargeView.hidden = YES;
  652. _rechargeView.delegate = self;
  653. //[self.liveUIViewController.liveView addSubview:_rechargeView];
  654. self.mrechargeView = _rechargeView;
  655. [self.view addSubview:_rechargeView];
  656. }
  657. return _rechargeView;
  658. }
  659. -(void)closeRechargeWithRechargeView:(RechargeView *)rechargeView{
  660. [UIView animateWithDuration:0.5 animations:^{
  661. rechargeView.transform = CGAffineTransformIdentity;
  662. } completion:^(BOOL finished) {
  663. rechargeView.hidden = YES;
  664. }];
  665. self.mGiftView.hidden = NO;
  666. }
  667. - (OtherChangeView *)otherChangeView
  668. {
  669. if (_otherChangeView == nil)
  670. {
  671. _otherChangeView = [[OtherChangeView alloc] initWithFrame:CGRectMake(kRechargeMargin, kScreenH, kScreenW-2*kRechargeMargin, 300) andUIViewController:self];
  672. _otherChangeView.hidden = YES;
  673. _otherChangeView.delegate = self;
  674. //[self.liveUIViewController.liveView addSubview:_otherChangeView];
  675. [self.view addSubview:_otherChangeView];
  676. }
  677. return _otherChangeView;
  678. }
  679. - (ExchangeView *)exchangeCoinView
  680. {
  681. if (_exchangeCoinView == nil)
  682. {
  683. _exchangeCoinView = [[ExchangeView alloc] initWithFrame:CGRectMake(kRechargeMargin, kScreenH, kScreenW-2*kRechargeMargin, 260)];
  684. _exchangeCoinView.hidden = YES;
  685. _exchangeCoinView.delegate = self;
  686. //[self.liveUIViewController.liveView addSubview:_exchangeView];
  687. [self.view addSubview:_exchangeCoinView];
  688. }
  689. return _exchangeCoinView;
  690. }
  691. - (void)choseRecharge:(BOOL)recharge orExchange:(BOOL)exchange
  692. {
  693. if (recharge) {
  694. self.rechargeView.hidden = NO;
  695. // [self.liveUIViewController.liveView bringSubviewToFront:self.rechargeView];
  696. [UIView animateWithDuration:0.5 animations:^{
  697. //_rechargeView.frame = CGRectMake(10, (kScreenH-kRechargeViewHeight)/2, kScreenW-20, kRechargeViewHeight);
  698. self.rechargeView.transform = CGAffineTransformMakeTranslation(0, (kScreenH-kRechargeViewHeight)/2-kScreenH);
  699. } completion:^(BOOL finished) {
  700. }];
  701. }
  702. else if(exchange)
  703. {
  704. [self.view endEditing:YES];
  705. self.exchangeCoinView.hidden = NO;
  706. self.exchangeCoinView.model = self.rechargeView.model;
  707. [UIView animateWithDuration:0.5 animations:^{
  708. //_exchangeCoinView.frame = CGRectMake(10, kScreenH-230-kNumberBoardHeight, kScreenW-20, 230);
  709. self.exchangeCoinView.transform = CGAffineTransformMakeTranslation(0, -260-kNumberBoardHeight);
  710. } completion:^(BOOL finished) {
  711. }];
  712. }
  713. }
  714. //- (void)choseOtherRechargeWithRechargeView:(RechargeView *)rechargeView
  715. //{
  716. // [self.view endEditing:YES];
  717. // self.otherChangeView.hidden = NO;
  718. // self.otherChangeView.selectIndex = rechargeView.indexPayWay;
  719. // self.otherChangeView.model = rechargeView.model;
  720. // self.otherChangeView.otherPayArr = rechargeView.model.pay_list;
  721. // [UIView animateWithDuration:0.5 animations:^{
  722. // //self.otherChangeView.frame = CGRectMake(10, kScreenH-260-kNumberBoardHeight, kScreenW-20, 260);
  723. // self.otherChangeView.transform = CGAffineTransformMakeTranslation(0, -300-kNumberBoardHeight);
  724. // } completion:^(BOOL finished) {
  725. //
  726. // }];
  727. //}
  728. ////点击其它支付的确定按钮
  729. //- (void)clickOtherRechergeWithView:(OtherChangeView *)otherView
  730. //{
  731. // PayMoneyModel *model = [[PayMoneyModel alloc] init];
  732. // model.hasOtherPay = YES;
  733. // self.rechargeView.money = otherView.textField.text;
  734. // [self.rechargeView payRequestWithModel:model withPayWayIndex:otherView.selectIndex];
  735. //}
  736. //
  737. //- (void)rechargeSuccessWithRechargeView:(RechargeView *)rechargeView
  738. //{
  739. // FWWeakify(self)
  740. // [[IMAPlatform sharedInstance].host getMyInfo:^(AppBlockModel *blockModel) {
  741. //
  742. // FWStrongify(self)
  743. //
  744. // long currentDiamonds = [[IMAPlatform sharedInstance].host getDiamonds];
  745. // [(GiftView*)self.mGiftView setDiamondsLabelTxt:[NSString stringWithFormat:@"%ld",currentDiamonds]];
  746. //
  747. // if (self.otherChangeView.hidden == NO)
  748. // {
  749. // [self.otherChangeView disChangeText];
  750. // }
  751. //
  752. // }];
  753. //}
  754. - (void)clickExchangeWithView:(OtherChangeView *)otherView
  755. {
  756. [self choseRecharge:NO orExchange:YES];
  757. }
  758. - (void)didReceiveMemoryWarning
  759. {
  760. [super didReceiveMemoryWarning];
  761. // Dispose of any resources that can be recreated.
  762. }
  763. - (BogoRechargePopView *)rechargePopView{
  764. if (!_rechargePopView) {
  765. _rechargePopView = [[BogoRechargePopView alloc]initWithFrame:CGRectMake(0, kScreenH, kScreenW, kScreenH - kRealValue(180))];
  766. // _rechargePopView.clickHideBlock = ^(BOOL isClick) {
  767. // self.mGiftView.hidden = YES;
  768. // };
  769. }
  770. return _rechargePopView;
  771. }
  772. #pragma mark - ********************* 音视频通话 ***********************
  773. #pragma mark - ********** 语音 ***********
  774. - (void)applyAudioMethod {
  775. if (AppDelegate.sharedAppDelegate.isInAudioVideoChatVc) {
  776. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"通话中,请结束通话后再试")];
  777. return;
  778. }
  779. if (self.isApplyingAudioChat) {
  780. return;
  781. }
  782. self.isApplyingAudioChat = YES;
  783. WeakSelf
  784. [AudioChatTool.shareInstance getOtherIsOnlineStatusWithUserID:[NSString stringWithFormat:@"%d",self.mChatFriend.mUser_id] block:^(V2TIMUserStatusType statusType) {
  785. // 查询其他人的状态成功
  786. if (statusType == V2TIM_USER_STATUS_ONLINE) {
  787. [weakSelf sendCallAudioChatApplyMsg];
  788. return;
  789. }
  790. //不在线,请求接口
  791. // [AudioChatTool.shareInstance requestCallApplyWithAudio:YES block:^(BOOL isSuccess) {
  792. // if (isSuccess) {
  793. // [weakSelf pushAudioChatVC];
  794. // return;
  795. // }
  796. // weakSelf.isApplyingAudioChat = NO;
  797. // }];
  798. //第二套方案
  799. [self sendCallAudioChatApplyMsgWithPush];
  800. }];
  801. }
  802. - (void)sendCallAudioChatApplyMsg {
  803. WeakSelf
  804. SIMMsgObj *obj = [self.mChatFriend sendCustomCallAudioTextMsg:@"主动发起语音通话" callAudioType:AudioChatType_call
  805. isCall:YES
  806. block:^(SResBase *resb, SIMMsgObj *newObj) {
  807. if (!resb.msuccess)
  808. {
  809. [SVProgressHUD showErrorWithStatus:resb.mmsg];
  810. } else {
  811. //发送成功了,跳语音页面
  812. [weakSelf pushAudioChatVC];
  813. }
  814. }];
  815. }
  816. - (void)sendCallAudioChatApplyMsgWithPush {
  817. WeakSelf
  818. SIMMsgObj *obj = [self.mChatFriend sendCustomCallAudioTextMsgWithPush:@"主动发起语音通话" callAudioType:AudioChatType_call
  819. isCall:YES
  820. block:^(SResBase *resb, SIMMsgObj *newObj) {
  821. if (!resb.msuccess)
  822. {
  823. [SVProgressHUD showErrorWithStatus:resb.mmsg];
  824. } else {
  825. //发送成功了,跳语音页面
  826. [weakSelf pushAudioChatVC];
  827. }
  828. }];
  829. }
  830. - (void)pushAudioChatVC {
  831. WeakSelf
  832. [AudioChatTool.shareInstance audioGetMainPushVoiceRoomIsZhuDongCall:YES withFriendObj:self.mChatFriend loadEndBlock:^{
  833. [AudioChatTool.shareInstance.recordAudioChatViewController reloadDataWithType:AudioChatType_call];
  834. weakSelf.isApplyingAudioChat = NO;
  835. }];
  836. }
  837. #pragma mark - ********** 视频 ***********
  838. - (void)applyVideoMethod {
  839. if (AppDelegate.sharedAppDelegate.isInAudioVideoChatVc) {
  840. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"通话中,请结束通话后再试")];
  841. return;
  842. }
  843. if (self.isApplyingVideoChat) {
  844. return;
  845. }
  846. self.isApplyingVideoChat = YES;
  847. WeakSelf
  848. [AudioChatTool.shareInstance getOtherIsOnlineStatusWithUserID:[NSString stringWithFormat:@"%d",self.mChatFriend.mUser_id] block:^(V2TIMUserStatusType statusType) {
  849. // 查询其他人的状态成功
  850. if (statusType == V2TIM_USER_STATUS_ONLINE) {
  851. [weakSelf sendVideoChatApplyMsg];
  852. return;
  853. }
  854. //不在线,请求接口
  855. // [AudioChatTool.shareInstance requestCallApplyWithAudio:NO block:^(BOOL isSuccess) {
  856. // if (isSuccess) {
  857. // //发送成功了,跳语音页面
  858. // [weakSelf pushVideoChatVC];
  859. // return;
  860. // }
  861. // weakSelf.isApplyingVideoChat = NO;
  862. // }];
  863. //第二套方案
  864. [self sendVideoChatApplyMsgWithPush];
  865. }];
  866. }
  867. - (void)sendVideoChatApplyMsg {
  868. WeakSelf
  869. SIMMsgObj *obj = [self.mChatFriend sendCustomCallVideoTextMsg:@"主动发起语音通话" callAudioType:AudioChatType_call
  870. isCall:YES
  871. block:^(SResBase *resb, SIMMsgObj *newObj) {
  872. if (!resb.msuccess)
  873. {
  874. [SVProgressHUD showErrorWithStatus:resb.mmsg];
  875. } else {
  876. //发送成功了,跳语音页面
  877. [weakSelf pushVideoChatVC];
  878. }
  879. }];
  880. }
  881. -(void)sendVideoChatApplyMsgWithPush{
  882. WeakSelf
  883. SIMMsgObj *obj = [self.mChatFriend sendCustomCallVideoTextMsgWithPush:@"主动发起语音通话" callAudioType:AudioChatType_call
  884. isCall:YES
  885. block:^(SResBase *resb, SIMMsgObj *newObj) {
  886. if (!resb.msuccess)
  887. {
  888. [SVProgressHUD showErrorWithStatus:resb.mmsg];
  889. } else {
  890. //发送成功了,跳语音页面
  891. [weakSelf pushVideoChatVC];
  892. }
  893. }];
  894. }
  895. - (void)pushVideoChatVC {
  896. WeakSelf
  897. [AudioChatTool.shareInstance videoGetMainPushVoiceRoomIsZhuDongCall:YES withFriendObj:self.mChatFriend loadEndBlock:^{
  898. [AudioChatTool.shareInstance.recordVideoChatVC reloadDataWithType:AudioChatType_call];
  899. weakSelf.isApplyingVideoChat = NO;
  900. }];
  901. }
  902. @end