YOUPAIZYShortVideoVC.m 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. //
  2. // YOUPAIZYShortVideoVC.m
  3. // VQU
  4. //
  5. // Created by Elaine on 2020/11/6.
  6. // Copyright © 2020 leo. All rights reserved.
  7. //
  8. #import "YOUPAIZYShortVideoVC.h"
  9. #import "YOUPAIZYVideoModel.h"
  10. #import "YOUPAIEyeCatchingWaiterCell.h"
  11. #import "ZFPlayer.h"
  12. #import "ZFAVPlayerManager.h"
  13. #import "YOUPAIZFDouYinControlView.h"
  14. #import "YOUPAILZUserShowVC.h"
  15. #import "YOUPAILCIMSessionVC.h"
  16. #import "YOUPAIZYBiXinVC.h"
  17. #import "UIViewController+TFPresent.h"
  18. #import "YOUPAIZYVideoHeartGiftModel.h"
  19. #import "YOUPAILZCommonGiftView.h"
  20. #import "GKPushTransitionAnimation.h"
  21. #import "YOUPAIXRWalletVC.h"
  22. #import "YOUPAIHRChatRoomGiftView.h"
  23. @interface YOUPAIZYShortVideoVC ()<UITableViewDelegate, UITableViewDataSource,EyeCatchingWaiterCellDelegate,ZYBiXinDelegate,UINavigationControllerDelegate,UIGestureRecognizerDelegate>
  24. @property (nonatomic, strong) UITableView *youpaiptableView;
  25. @property (nonatomic, strong) ZFPlayerController *youpaipzFplayer;
  26. @property (nonatomic, strong) YOUPAIZFDouYinControlView *youpaipcontrolView;
  27. @property (nonatomic, strong) NSMutableArray * youpaipmp4UrlArray;
  28. @property (nonatomic,strong) NSMutableArray * youpaipvideoDataArray;
  29. @property(nonatomic,assign)NSInteger youpaipcurrentPage;//代表当前页码
  30. @property(nonatomic,assign)NSInteger youpaiptotalPage;//总页码
  31. @property(nonatomic,strong)UIImageView *youpaippromptImgView;//提示双击置顶
  32. @property(nonatomic,strong)YOUPAIZYVideoHeartGiftModel *youpaipheartGiftModel;
  33. @property (nonatomic,assign)BOOL youpaipisLeavePage;// 是否离开
  34. @property (nonatomic, strong) UIPercentDrivenInteractiveTransition *youpaippercentDrivenTransition;
  35. @end
  36. @implementation YOUPAIZYShortVideoVC
  37. //-(void)viewWillAppear:(BOOL)animated
  38. //{
  39. // [super viewWillAppear:animated];
  40. //// self.isLeavePage = NO;
  41. // [self.zFplayer.currentPlayerManager play];
  42. // [self.controlView youpaifresetControlView];
  43. //
  44. //}
  45. - (void)viewDidAppear:(BOOL)animated{
  46. [super viewDidAppear:animated];
  47. self.youpaipisLeavePage = NO;
  48. if(!self.youpaipzFplayer.currentPlayerManager.isPlaying){
  49. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  50. // 需要延迟执行的代码
  51. [self.youpaipzFplayer.currentPlayerManager play];
  52. [self.youpaipcontrolView youpaifresetControlView];
  53. });
  54. // [self performSelector:@selector(play) withObject:nil afterDelay:0.25f];
  55. // [self.controlView youpaifresetControlView];
  56. }
  57. self.navigationController.delegate = self;
  58. }
  59. //-(void)viewWillDisappear:(BOOL)animated{
  60. // [super viewWillDisappear:animated];
  61. // self.isLeavePage = YES;
  62. // [self.zFplayer.currentPlayerManager pause];
  63. // self.navigationController.delegate = nil;
  64. //}
  65. - (void)viewDidDisappear:(BOOL)animated{
  66. [super viewDidDisappear:animated];
  67. self.youpaipisLeavePage = YES;
  68. [self.youpaipzFplayer.currentPlayerManager pause];
  69. self.navigationController.delegate = nil;
  70. }
  71. -(void)youpaifdeletePromptImgView
  72. {
  73. [self.youpaippromptImgView removeFromSuperview];
  74. }
  75. -(void)youpaifdisplayPromptImgView
  76. {
  77. if (![LCSaveData getFirstDisplayVideoDynamicPage] && kAppDelegate.isDisplayVideoDynamicPage) {
  78. [LCSaveData saveFirstDisplayVideoDynamicPage:YES];
  79. self.youpaippromptImgView = [[UIImageView alloc] initWithFrame:CGRectMake(KScreenWidth/5.0+KScreenWidth/10.0-KScreenWidth*(135/375.0)/3.0,KScreenHeight-TabbarHeight-KScreenWidth*(135/375.0)*(83/135.0)-10,KScreenWidth*(135/375.0),KScreenWidth*(135/375.0)*(83/135.0))];
  80. self.youpaippromptImgView.image = [UIImage imageNamed:@"vqu_images_double_click"];
  81. [self.view addSubview:self.youpaippromptImgView];
  82. [NSTimer scheduledTimerWithTimeInterval:10.0f target:self selector:@selector(youpaifdeletePromptImgView) userInfo:nil repeats:NO];
  83. }
  84. }
  85. -(NSMutableArray *)youpaipvideoDataArray
  86. {
  87. if (!_youpaipvideoDataArray) {
  88. _youpaipvideoDataArray = [NSMutableArray array];
  89. }
  90. return _youpaipvideoDataArray;
  91. }
  92. -(NSMutableArray *)youpaipmp4UrlArray
  93. {
  94. if (!_youpaipmp4UrlArray) {
  95. _youpaipmp4UrlArray = [NSMutableArray array];
  96. }
  97. return _youpaipmp4UrlArray;
  98. }
  99. -(void)youpaifsetVideoType:(NSInteger)type andGender:(NSInteger)gender
  100. {
  101. self.youpaiptype = type;
  102. self.youpaipgender = gender;
  103. [self.youpaiptableView.mj_header beginRefreshing];
  104. }
  105. - (void)youpaifloadNewData{
  106. self.youpaiptableView.mj_footer.hidden = YES;
  107. [self.youpaiptableView.mj_footer endRefreshing];//先结束上拉,假如有的话
  108. [self.youpaiptableView.mj_footer endRefreshingWithNoMoreData];
  109. self.youpaiptableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(youpaifloadMoreData)];
  110. self.youpaipcurrentPage = 1;
  111. NSMutableDictionary *dict = [NSMutableDictionary new];
  112. [dict setObject:@(self.youpaipcurrentPage) forKey:@"page"];
  113. [dict setObject:@(1) forKey:@"type"];
  114. [dict setObject:@(self.youpaipgender) forKey:@"gender"];
  115. [LCHttpHelper requestWithURLString:TrendsLists parameters:dict needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  116. NSDictionary* dict = (NSDictionary*)responseObject;
  117. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  118. if (code==0) {//成功
  119. [self.youpaipvideoDataArray removeAllObjects];
  120. [self.youpaipmp4UrlArray removeAllObjects];
  121. self.youpaipheartGiftModel = [YOUPAIZYVideoHeartGiftModel mj_objectWithKeyValues:[[dict objectForKey:@"data"] objectForKey:@"heart_gift"]];
  122. self.youpaipvideoDataArray = [YOUPAIZYVideoModel mj_objectArrayWithKeyValuesArray:[[dict objectForKey:@"data"] objectForKey:@"list"]];
  123. self.youpaiptotalPage = [[[dict objectForKey:@"data"] objectForKey:@"total_page"] integerValue];
  124. NSInteger youpaipcurrentPage = [[[dict objectForKey:@"data"] objectForKey:@"page"] integerValue];
  125. self.youpaipcurrentPage = youpaipcurrentPage;
  126. for (YOUPAIZYVideoModel *model in self.youpaipvideoDataArray) {
  127. [self.youpaipmp4UrlArray addObject:[NSURL URLWithString:model.youpaipfile_url]];
  128. }
  129. NSLog(@"%@",self.youpaipmp4UrlArray);
  130. self.youpaipzFplayer.assetURLs = self.youpaipmp4UrlArray;
  131. [self.youpaiptableView reloadData];
  132. // __weak typeof(self) weakSelf = self;
  133. [self.youpaipzFplayer.currentPlayerManager pause];
  134. if (self.youpaipvideoDataArray.count != 0) {
  135. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
  136. [self youpaifplayTheVideoAtIndexPath:indexPath];
  137. if (self.youpaipisLeavePage) {
  138. [self.youpaipzFplayer.currentPlayerManager pause];
  139. }
  140. }
  141. // [self.zFplayer zf_filterShouldPlayCellWhileScrolled:^(NSIndexPath *indexPath) {
  142. // [weakSelf youpaifplayTheVideoAtIndexPath:indexPath];
  143. // NSLog(@"%@",indexPath);
  144. // }];
  145. if (youpaipcurrentPage >= self.youpaiptotalPage) {
  146. [self.youpaiptableView.mj_footer endRefreshingWithNoMoreData];
  147. self.youpaiptableView.mj_footer.hidden = YES;
  148. }
  149. [self.youpaiptableView.mj_header endRefreshing];
  150. }else{
  151. [self.youpaiptableView.mj_header endRefreshing];
  152. }
  153. } failure:^(NSError *error) {
  154. [self.youpaiptableView.mj_header endRefreshing];
  155. }];
  156. }
  157. - (void)youpaifloadMoreData{
  158. //先结束下拉 假如有的话
  159. [self.youpaiptableView.mj_header endRefreshing];
  160. [LCHttpHelper requestWithURLString:TrendsLists parameters:@{@"page":@(self.youpaipcurrentPage+1),@"type":@(1),@"gender":@(self.youpaipgender)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  161. NSDictionary* dict = (NSDictionary*)responseObject;
  162. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  163. if (code==0) {//成功
  164. NSInteger count = self.youpaipvideoDataArray.count;
  165. NSLog(@"count == %ld",count);
  166. NSMutableArray* modelArray = [YOUPAIZYVideoModel mj_objectArrayWithKeyValuesArray:[[dict objectForKey:@"data"]objectForKey:@"list"]];
  167. [self.youpaipvideoDataArray addObjectsFromArray:modelArray];
  168. self.youpaiptotalPage = [[[dict objectForKey:@"data"] objectForKey:@"total_page"] integerValue];
  169. NSInteger youpaipcurrentPage = [[[dict objectForKey:@"data"] objectForKey:@"page"] integerValue];
  170. self.youpaipcurrentPage = youpaipcurrentPage;
  171. NSLog(@"self.youpaipcurrentPage === %ld---",self.youpaipcurrentPage);
  172. for (YOUPAIZYVideoModel *model in modelArray) {
  173. [self.youpaipmp4UrlArray addObject:[NSURL URLWithString:model.youpaipfile_url]];
  174. }
  175. NSLog(@"count === %ld----%ld",self.youpaipvideoDataArray.count,self.youpaipmp4UrlArray.count);
  176. self.youpaipzFplayer.assetURLs = self.youpaipmp4UrlArray;
  177. [self.youpaiptableView reloadData];
  178. NSIndexPath* indexPath = [NSIndexPath indexPathForRow:count inSection:0];
  179. [self.youpaiptableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
  180. [self youpaifplayTheVideoAtIndexPath:indexPath];
  181. if (self.youpaipisLeavePage) {
  182. [self.youpaipzFplayer.currentPlayerManager pause];
  183. }
  184. // __weak typeof(self) weakSelf = self;
  185. // [self.zFplayer zf_filterShouldPlayCellWhileScrolled:^(NSIndexPath *indexPath) {
  186. // NSLog(@"row == %ld",indexPath.row);
  187. // NSIndexPath* index = [NSIndexPath indexPathForRow:indexPath.row+1 inSection:0];
  188. // [self.tableView scrollToRowAtIndexPath:index atScrollPosition:UITableViewScrollPositionTop animated:YES];
  189. // [weakSelf youpaifplayTheVideoAtIndexPath:index];
  190. // }];
  191. if (youpaipcurrentPage>=self.youpaiptotalPage) {
  192. [self.youpaiptableView.mj_footer endRefreshingWithNoMoreData];
  193. self.youpaiptableView.mj_footer.hidden = YES;
  194. }
  195. [self.youpaiptableView.mj_header endRefreshing];
  196. }
  197. [self.youpaiptableView.mj_footer endRefreshing];
  198. } failure:^(NSError *error) {
  199. [self.youpaiptableView.mj_footer endRefreshing];
  200. }];
  201. }
  202. -(void)dealloc
  203. {
  204. [[NSNotificationCenter defaultCenter] removeObserver:self];
  205. }
  206. -(void)youpaiftoTopAction
  207. {
  208. if (self.youpaipmp4UrlArray.count > 0) {
  209. // NSIndexPath* indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
  210. // [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
  211. [UIView animateWithDuration:0.25f animations:^{
  212. self.youpaiptableView.contentOffset = CGPointMake(0, 0);
  213. }];
  214. }
  215. if (!self.youpaiptableView.mj_header.isRefreshing) {
  216. [self.youpaiptableView.mj_header beginRefreshing];
  217. }
  218. }
  219. - (void)viewDidLoad {
  220. [super viewDidLoad];
  221. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaiftoTopAction) name:@"videoToTop" object:nil];//置顶
  222. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(youpaifchangeFollowStateNotification:) name:@"ChangeFollowState" object:nil];
  223. self.navigationController.navigationBarHidden = YES;
  224. [self youpaifinitTableView];
  225. // [self getData];
  226. // [self.tableView.mj_header beginRefreshing];
  227. @weakify(self);
  228. self.youpaipzFplayer.zf_playerShouldPlayInScrollView = ^(NSIndexPath * _Nonnull indexPath) {
  229. NSLog(@"%@",indexPath);
  230. @strongify(self);
  231. YOUPAIEyeCatchingWaiterCell *cell = (YOUPAIEyeCatchingWaiterCell*)[self.youpaiptableView cellForRowAtIndexPath:indexPath];
  232. for(UIView*firstView in cell.subviews) {
  233. for(UIView*lastView in firstView.subviews) {
  234. if(lastView.tag == 100) {
  235. for(UIView*playerPresentView in lastView.subviews) {
  236. playerPresentView.backgroundColor= [UIColor clearColor];
  237. }
  238. }
  239. }
  240. }
  241. };
  242. // 添加屏幕边缘手势
  243. UIScreenEdgePanGestureRecognizer *edgePagGesture = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(youpaifpanGestureAction:)];
  244. edgePagGesture.edges = UIRectEdgeRight;
  245. [self.view addGestureRecognizer:edgePagGesture];
  246. UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(youpaifpanGestureAction:)];
  247. panGesture.maximumNumberOfTouches = 1;
  248. panGesture.delegate = self;
  249. [self.view addGestureRecognizer:panGesture];
  250. }
  251. - (void)youpaifpanGestureAction:(UIPanGestureRecognizer *)gesture {
  252. CGPoint transition = [gesture translationInView:gesture.view];
  253. if (transition.x > 0) { // 右滑
  254. return;
  255. }
  256. // 进度
  257. CGFloat progress = transition.x / gesture.view.bounds.size.width;
  258. if (progress < 0) {
  259. progress = -progress;
  260. progress = MIN(1.0f, MAX(0.0f, progress));
  261. if (gesture.state == UIGestureRecognizerStateBegan) {
  262. self.youpaippercentDrivenTransition = [[UIPercentDrivenInteractiveTransition alloc] init];
  263. [self youpaifpushToNextViewController];
  264. }else if (gesture.state == UIGestureRecognizerStateChanged) {
  265. // 手势在慢慢划入 // 把手势的进度告诉 UIPercentDrivenInteractiveTransition
  266. [self.youpaippercentDrivenTransition updateInteractiveTransition:progress];
  267. }else if (gesture.state == UIGestureRecognizerStateEnded || gesture.state == UIGestureRecognizerStateCancelled) {
  268. if (progress > 0.3) {
  269. [self.youpaippercentDrivenTransition finishInteractiveTransition];
  270. }else{
  271. [self.youpaippercentDrivenTransition cancelInteractiveTransition];
  272. }
  273. self.youpaippercentDrivenTransition = nil;
  274. }
  275. }
  276. }
  277. - (void)youpaifpushToNextViewController{
  278. self.youpaipisLeavePage = YES;
  279. [self.youpaipzFplayer.currentPlayerManager pause];
  280. NSArray *visiblePaths = [self.youpaiptableView indexPathsForVisibleRows];
  281. if (visiblePaths.count != 0) {
  282. NSIndexPath *indexPath = visiblePaths[0];
  283. if (self.youpaipvideoDataArray.count >= indexPath.row) {
  284. YOUPAIZYVideoModel *model = self.youpaipvideoDataArray[indexPath.row];
  285. YOUPAILZUserShowVC *userShow = [[YOUPAILZUserShowVC alloc] init];
  286. userShow.youpaipuserId = model.youpaipuser_id;
  287. [self.navigationController pushViewController:userShow animated:YES];
  288. }
  289. }
  290. }
  291. - (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer{
  292. // 根据transition判断是左滑还是右滑
  293. CGPoint transition = [gestureRecognizer translationInView:gestureRecognizer.view];
  294. if (transition.x < 0) { // 左滑
  295. return YES;
  296. }else if (transition.x > 0) { // 右滑
  297. return NO;
  298. }
  299. // 忽略导航控制器正在做转场动画
  300. if ([[self.navigationController valueForKey:@"_isTransitioning"] boolValue]) return NO;
  301. return YES;
  302. }
  303. -(void)youpaifchangeFollowStateNotification:(NSNotification*)notification{
  304. NSDictionary *dict = [notification userInfo];
  305. NSString *idStr = dict[@"follow_uid"];
  306. NSInteger isfollow = [dict[@"is_follow"] intValue];
  307. NSArray *arr = self.youpaipvideoDataArray;
  308. if (arr.count>0) {
  309. NSIndexPath *index;
  310. NSMutableArray *arrM = [NSMutableArray new];
  311. for (int i = 0; i<arr.count; i++) {
  312. YOUPAIZYVideoModel *model = arr[i];
  313. if ([model.youpaipuser_id isEqualToString:idStr]) {
  314. model.youpaipis_follow = isfollow;
  315. index = [NSIndexPath indexPathForRow:i inSection:0];
  316. [arrM addObject:index];
  317. }
  318. }
  319. [UIView performWithoutAnimation:^{
  320. [self.youpaiptableView reloadRowsAtIndexPaths:arrM withRowAnimation:UITableViewRowAnimationFade];
  321. }];
  322. // [self.tableView reloadRowsAtIndexPaths:@[index] withRowAnimation:UITableViewRowAnimationFade];
  323. }
  324. }
  325. -(void)youpaifinitTableView{
  326. _youpaiptableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  327. _youpaiptableView.pagingEnabled = YES;
  328. [_youpaiptableView registerClass:[YOUPAIEyeCatchingWaiterCell class] forCellReuseIdentifier:@"YOUPAIEyeCatchingWaiterCell"];
  329. _youpaiptableView.backgroundColor = [UIColor blackColor];
  330. _youpaiptableView.delegate = self;
  331. _youpaiptableView.dataSource = self;
  332. _youpaiptableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  333. _youpaiptableView.showsVerticalScrollIndicator = NO;
  334. _youpaiptableView.scrollsToTop = NO;
  335. if (@available(iOS 11.0, *)) {
  336. _youpaiptableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  337. } else {
  338. self.automaticallyAdjustsScrollViewInsets = NO;
  339. }
  340. _youpaiptableView.estimatedRowHeight = 0;
  341. _youpaiptableView.estimatedSectionFooterHeight = 0;
  342. _youpaiptableView.estimatedSectionHeaderHeight = 0;
  343. _youpaiptableView.rowHeight = KScreenHeight - TabbarHeight;
  344. _youpaiptableView.scrollsToTop = NO;
  345. _youpaiptableView.mj_header = [LCRefreshDotGiftHeader headerWithRefreshingTarget:self refreshingAction:@selector(youpaifloadNewData)];
  346. if (@available(iOS 15.0, *)) {
  347. _youpaiptableView.sectionHeaderTopPadding = 0;
  348. }
  349. [self.view addSubview:_youpaiptableView];
  350. [self.youpaiptableView mas_makeConstraints:^(MASConstraintMaker *make) {
  351. make.left.top.bottom.right.offset(0.0f);
  352. }];
  353. [self.youpaiptableView.mj_header beginRefreshing];
  354. }
  355. //- (void)getData{
  356. // self.player.assetURLs = self.mp4UrlArray;
  357. // [self.tableView reloadData];
  358. // __weak typeof(self) weakSelf = self;
  359. // [self.player zf_filterShouldPlayCellWhileScrolled:^(NSIndexPath *indexPath) {
  360. // [weakSelf youpaifplayTheVideoAtIndexPath:indexPath];
  361. // }];
  362. //}
  363. /// play the video
  364. - (void)youpaifplayTheVideoAtIndexPath:(NSIndexPath *)indexPath {
  365. [self.youpaipzFplayer playTheIndexPath:indexPath];
  366. [self.youpaipcontrolView youpaifresetControlView];
  367. if (self.youpaipvideoDataArray.count == 0) {//新马甲没有视频的时候
  368. return;
  369. }
  370. YOUPAIZYVideoModel *model = self.youpaipvideoDataArray[indexPath.row];
  371. [self youpaiftrendsBrowser:model];
  372. }
  373. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  374. // self.tableView.mj_footer.hidden = self.videoDataArray.count>0?NO:YES;
  375. return self.youpaipvideoDataArray.count;
  376. }
  377. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  378. YOUPAIEyeCatchingWaiterCell * cell = [tableView dequeueReusableCellWithIdentifier:@"YOUPAIEyeCatchingWaiterCell" forIndexPath:indexPath];
  379. cell.backgroundColor = [UIColor blackColor];
  380. YOUPAIZYVideoModel *model = self.youpaipvideoDataArray[indexPath.row];
  381. cell.model = model;
  382. cell.delegate = self;
  383. cell.hidesBottomBar = self.hidesBottomBarWhenPushed;
  384. return cell;
  385. }
  386. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  387. [self youpaifplayTheVideoAtIndexPath:indexPath];
  388. }
  389. #pragma mark - UIScrollViewDelegate 列表播放必须实现
  390. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
  391. [scrollView zf_scrollViewDidEndDecelerating];
  392. }
  393. - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
  394. [scrollView zf_scrollViewDidEndDraggingWillDecelerate:decelerate];
  395. }
  396. - (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView {
  397. [scrollView zf_scrollViewDidScrollToTop];
  398. }
  399. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  400. [scrollView zf_scrollViewDidScroll];
  401. }
  402. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
  403. [scrollView zf_scrollViewWillBeginDragging];
  404. }
  405. #pragma mark - JXCategoryListContainerViewDelegate
  406. - (UIView *)listView{
  407. return self.view;
  408. }
  409. #pragma mark --- 懒加载
  410. - (YOUPAIZFDouYinControlView *)youpaipcontrolView {
  411. if (!_youpaipcontrolView) {
  412. _youpaipcontrolView = [YOUPAIZFDouYinControlView new];
  413. }
  414. return _youpaipcontrolView;
  415. }
  416. - (ZFPlayerController *)youpaipzFplayer{
  417. if (_youpaipzFplayer == nil) {
  418. ZFAVPlayerManager *playerManager = [[ZFAVPlayerManager alloc] init];
  419. _youpaipzFplayer = [ZFPlayerController playerWithScrollView:self.youpaiptableView playerManager:playerManager containerViewTag:100];
  420. _youpaipzFplayer.disableGestureTypes = ZFPlayerDisableGestureTypesDoubleTap | ZFPlayerDisableGestureTypesPan | ZFPlayerDisableGestureTypesPinch;
  421. _youpaipzFplayer.allowOrentitaionRotation = NO;
  422. _youpaipzFplayer.WWANAutoPlay = YES;
  423. _youpaipzFplayer.playerDisapperaPercent = 1.0;
  424. _youpaipzFplayer.controlView = self.youpaipcontrolView;
  425. __weak typeof(self) weakSelf = self;
  426. _youpaipzFplayer.playerDidToEnd = ^(id _Nonnull asset) { // 播放结束后重新播放
  427. [weakSelf.youpaipzFplayer.currentPlayerManager replay];
  428. };
  429. _youpaipzFplayer.presentationSizeChanged = ^(id<ZFPlayerMediaPlayback> _Nonnull asset, CGSize size) { // 视频画面显示的模式
  430. NSInteger index = [weakSelf.youpaipmp4UrlArray indexOfObject:asset.assetURL];
  431. if (weakSelf.youpaipvideoDataArray.count >= index) {
  432. YOUPAIZYVideoModel *model = weakSelf.youpaipvideoDataArray[index];
  433. if (model.youpaipmode == 0) {
  434. if (size.width >= size.height) {
  435. model.youpaipmode = UIViewContentModeScaleAspectFit;
  436. } else {
  437. model.youpaipmode = UIViewContentModeScaleAspectFill;
  438. }
  439. }
  440. if (model.youpaipmode == UIViewContentModeScaleAspectFit) {
  441. weakSelf.youpaipzFplayer.currentPlayerManager.scalingMode = ZFPlayerScalingModeAspectFit;
  442. }else{
  443. weakSelf.youpaipzFplayer.currentPlayerManager.scalingMode = ZFPlayerScalingModeAspectFill;
  444. }
  445. }
  446. };
  447. [_youpaipzFplayer setPlayerPrepareToPlay:^(id<ZFPlayerMediaPlayback> _Nonnull asset, NSURL * _Nonnull assetURL) {
  448. NSInteger index = [weakSelf.youpaipmp4UrlArray indexOfObject:asset.assetURL];
  449. if (weakSelf.youpaipvideoDataArray.count >= index) {
  450. YOUPAIZYVideoModel *model = weakSelf.youpaipvideoDataArray[index];
  451. if (model.youpaipmode == UIViewContentModeScaleAspectFit) {
  452. weakSelf.youpaipzFplayer.currentPlayerManager.scalingMode = ZFPlayerScalingModeAspectFit;
  453. }else{
  454. weakSelf.youpaipzFplayer.currentPlayerManager.scalingMode = ZFPlayerScalingModeAspectFill;
  455. }
  456. }
  457. }];
  458. /// 停止的时候找出最合适的播放
  459. _youpaipzFplayer.zf_scrollViewDidEndScrollingCallback = ^(NSIndexPath * _Nonnull indexPath) {
  460. if (weakSelf.youpaipzFplayer.playingIndexPath) return;
  461. /// 加载下一页数据
  462. weakSelf.youpaipzFplayer.assetURLs = weakSelf.youpaipmp4UrlArray;
  463. [weakSelf.youpaiptableView reloadData];
  464. [weakSelf youpaifplayTheVideoAtIndexPath:indexPath];
  465. };
  466. }
  467. return _youpaipzFplayer;
  468. }
  469. #pragma EyeCatchingWaiterCellDelegate //cell的代理
  470. - (void)youpaifclickAvatar:(YOUPAIZYVideoModel*)model;//点击了头像
  471. {
  472. // LCUserShowVC* userShow = [[LCUserShowVC alloc]init];
  473. YOUPAILZUserShowVC *userShow = [[YOUPAILZUserShowVC alloc] init];
  474. userShow.youpaipuserId = model.youpaipuser_id;
  475. // userShow.videoModel = model;
  476. // userShow.delegate = self;
  477. [self.navigationController pushViewController:userShow animated:YES];
  478. }
  479. -(void)youpaifclickNikname:(YOUPAIZYVideoModel *)model
  480. {
  481. YOUPAILZUserShowVC *userShow = [[YOUPAILZUserShowVC alloc] init];
  482. userShow.youpaipuserId = model.youpaipuser_id;
  483. // userShow.videoModel = model;
  484. // userShow.delegate = self;
  485. [self.navigationController pushViewController:userShow animated:YES];
  486. }
  487. - (void)youpaifclickAttention:(YOUPAIZYVideoModel*)model;//点击了关注
  488. {
  489. if (model.youpaipis_follow == 0) {//+关注
  490. [LCCommonHttp followUserId:model.youpaipuser_id];
  491. model.youpaipis_follow = 1;
  492. [self.youpaiptableView reloadData];
  493. }else{
  494. [LCCommonHttp followUserId:model.youpaipuser_id];
  495. model.youpaipis_follow = 0;
  496. [self.youpaiptableView reloadData];
  497. }
  498. }
  499. - (void)youpaifclickSupport:(YOUPAIZYVideoModel*)model;//点击了点赞
  500. {
  501. [self.youpaiptableView reloadData];
  502. }
  503. -(void)youpaifclickImVideo:(YOUPAIZYVideoModel *)model;//点击了视频
  504. {
  505. if ([YOUPAILZChatRoomManager shareManager].chatroomWindow != nil && [YOUPAILZChatRoomManager shareManager].chatroomWindow.hidden == NO) {
  506. [ZCHUDHelper showTitle:@"你正在房间中,暂不可拨打视频"];
  507. return;
  508. }
  509. [UCAuthorityManager cameraAuthority:^{
  510. [LCHttpHelper requestWithURLString:CallChatType parameters:@{@"to_uid":model.youpaipuser_id,@"type":@"0"} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  511. NSDictionary* dict = (NSDictionary*)responseObject;
  512. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  513. if (code==0) {//成功
  514. YOUPAILCVideoChatModel* videoModel = [YOUPAILCVideoChatModel mj_objectWithKeyValues:[dict objectForKey:@"data"]];
  515. [[YOUPAILZChatRoomManager shareManager] youpaifcloseChatRoom];
  516. [[NSNotificationCenter defaultCenter] postNotificationName:@"MeCallVideo" object:nil userInfo:nil];
  517. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  518. YOUPAILCVideoRequestVC* chatRequest = [[YOUPAILCVideoRequestVC alloc]init];
  519. chatRequest.youpaipvideoModel = videoModel;
  520. //modify by leo fix bug ios13
  521. ZCBaseNavigationVC *nav = [[ZCBaseNavigationVC alloc]initWithRootViewController:chatRequest];
  522. chatRequest.view.backgroundColor = HexColorFromRGBA(0x000000, 0.55);
  523. chatRequest.definesPresentationContext = YES;
  524. nav.modalPresentationStyle = UIModalPresentationOverCurrentContext;
  525. [self.navigationController presentViewController:nav animated:YES completion:^{
  526. // chatRequest.view.backgroundColor = HexColorFromRGBA(0x000000, 0.55);
  527. }];
  528. });
  529. }
  530. } failure:^(NSError *error) {
  531. }];
  532. } denied:^{
  533. dispatch_async(dispatch_get_main_queue(), ^{
  534. UIAlertController *systemAlert = [UIAlertController alertControllerWithTitle:@"请在iphone的“设置-隐私-相机”选项中,允许APP访问您的相机。" message:nil preferredStyle:UIAlertControllerStyleAlert];
  535. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"现在去设置" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
  536. if ([[UIDevice currentDevice].systemVersion floatValue] < 10.0)
  537. {
  538. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
  539. }
  540. else
  541. {
  542. // 去系统设置页面
  543. if (@available(iOS 10.0, *)) {
  544. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
  545. } else {
  546. // Fallback on earlier versions
  547. }
  548. }
  549. }];
  550. UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
  551. [systemAlert addAction:cancelAction];
  552. [systemAlert addAction:action];
  553. [self presentViewController: systemAlert animated: YES completion: nil];
  554. });
  555. }];
  556. }
  557. //累加视频动态浏览量
  558. -(void)youpaiftrendsBrowser:(YOUPAIZYVideoModel *)model{
  559. [LCHttpHelper requestWithURLString:TrendsBrowser parameters:@{@"vt_id":model.youpaipvideoId} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  560. NSDictionary* dict = (NSDictionary*)responseObject;
  561. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  562. if (code==0) {//成功
  563. NSString *view_count = [NSString stringWithFormat:@"%@",[[dict objectForKey:@"data"] objectForKey:@"view_count"]];
  564. model.youpaipview_count = [view_count integerValue];
  565. [self.youpaiptableView reloadData];
  566. }
  567. } failure:^(NSError *error) {
  568. }];
  569. }
  570. //点击了比心
  571. -(void)youpaifclickBiXin:(YOUPAIZYVideoModel *)model
  572. {
  573. NSLog(@"点击了比心");
  574. YOUPAIZYBiXinVC *VC= [[YOUPAIZYBiXinVC alloc]init];
  575. VC.youpaipdelegate = self;
  576. VC.vWidth = KScreenWidth-54;
  577. VC.vHeight = ((KScreenWidth-54)*165)/321.0+191;
  578. VC.youpaipvideoModel = model;
  579. VC.youpaipheartGiftModel = self.youpaipheartGiftModel;
  580. VC.isTouchDismiss = YES;
  581. [self TFPresentVC:VC completion:^{
  582. }];
  583. }
  584. // 点击了礼物
  585. - (void)youpaifclickGift:(YOUPAIZYVideoModel *)model{
  586. YOUPAILZCommonGiftView *view = [YOUPAILZCommonGiftView new];
  587. view.isTouchDismiss = YES;
  588. view.youpaipisAnchor = NO;
  589. [view setJumToWalletBlock1:^{
  590. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  591. [[NSNotificationCenter defaultCenter] postNotificationName:@"InsufficientBalanceNotice" object:nil userInfo:nil];
  592. YOUPAIXRWalletVC *coinRecharge = [[YOUPAIXRWalletVC alloc]init];
  593. [self.navigationController pushViewController:coinRecharge animated:YES];
  594. });
  595. }];
  596. [view setYoupaiplzgiftblock:^(YOUPAILCGiftModel * _Nonnull giftModel, NSInteger count,NSString*categoryID) {
  597. [LCHttpHelper requestWithURLString:SendGift_New parameters:@{@"type":@(6),@"to_uid":model.youpaipuser_id,@"gift_id":giftModel.youpaipid,@"num":@(count),@"gift_type_id":categoryID} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  598. NSDictionary* dict = (NSDictionary*)responseObject;
  599. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  600. if (code==0) {//成功
  601. [ZCHUDHelper showTitle:@"礼物赠送成功"];
  602. }
  603. } failure:^(NSError *error) {
  604. }];
  605. }];
  606. [self TFPresentVC:view completion:^{
  607. }];
  608. }
  609. #pragma mark -- LZUserShowVCDelegate
  610. -(void)youpaifclickUserShowVCAttention:(YOUPAIZYVideoModel *)model
  611. {
  612. [self.youpaiptableView reloadData];
  613. }
  614. #pragma mark -- ZYBiXinDelegate
  615. -(void)youpaifaddBiXinSuccess:(NSInteger)heart_count andVideoModel:(YOUPAIZYVideoModel *)model{//比心成功
  616. model.youpaipheart_count = heart_count;
  617. [self.youpaiptableView reloadData];
  618. }
  619. // 执行手势驱动代理方法
  620. - (id<UIViewControllerInteractiveTransitioning>)navigationController:(UINavigationController *)navigationController interactionControllerForAnimationController:(id<UIViewControllerAnimatedTransitioning>)animationController{
  621. if (self.youpaippercentDrivenTransition && [animationController isKindOfClass:[GKPushTransitionAnimation class]]) {
  622. return self.youpaippercentDrivenTransition;
  623. }
  624. return nil;
  625. }
  626. - (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC{
  627. if (self.youpaippercentDrivenTransition && operation == UINavigationControllerOperationPush) {
  628. return [[GKPushTransitionAnimation alloc] initWithScale:NO];
  629. }
  630. return nil;
  631. }
  632. @end