Hibit_iOS/HiBit/Project/Player/View/GKDYVideoPortraitView.m
2024-06-11 10:51:38 +08:00

394 lines
13 KiB
Objective-C
Executable File

//
// GKDYVideoPortraitView.m
// GKDYVideo
//
// Created by QuintGao on 2023/3/17.
// Copyright © 2023 QuintGao. All rights reserved.
//
#import "GKDYVideoPortraitView.h"
#import "GKDYVideoItemButton.h"
#import "GKDoubleLikeView.h"
#import "UIButton+GKEnlarge.h"
@interface GKDYVideoPortraitView()
@property (nonatomic, strong) UIView * buttonContainerView;
@property (nonatomic, strong) UILabel * titleLabel;
@property (nonatomic, strong) UILabel * contentLabel;
@property (nonatomic, strong) UILabel * episcodeLabel;
@property (nonatomic, strong) UIButton * shareButton;
@property (nonatomic, strong) RSButton * episcodeButton;
@property (nonatomic, strong) UIButton * danmuButton;
@property (nonatomic, strong) UIButton * fullscreenButton;
@property (nonatomic, strong) GKDoubleLikeView * doubleLikeView;
@property (nonatomic, strong) NSDate * lastDoubleTapTime;
@end
@implementation GKDYVideoPortraitView
@synthesize player = _player;
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
[self initUI];
}
return self;
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)initUI {
[self addSubview:self.bottomContainerView];
[self.bottomContainerView addSubview:self.contentLabel];
[self.bottomContainerView addSubview:self.episcodeLabel];
[self.bottomContainerView addSubview:self.titleLabel];
[self.bottomContainerView addSubview:self.buttonContainerView];
[self.buttonContainerView addSubview:self.shareButton];
[self.buttonContainerView addSubview:self.episcodeButton];
[self.buttonContainerView addSubview:self.favoriteButton];
[self addSubview:self.slider];
[self addSubview:self.danmuButton];
[self addSubview:self.fullscreenButton];
[self addSubview:self.resumeButton];
[self.bottomContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self);
make.bottom.equalTo(self.mas_safeAreaLayoutGuideBottom);
}];
[self.slider mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self).offset(16.0);
make.right.equalTo(self).offset(-16.0);
make.bottom.equalTo(self.mas_safeAreaLayoutGuideBottom);
make.height.mas_equalTo(20.0);
}];
[self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.slider);
make.bottom.equalTo(self.slider.mas_top).offset(-10.0);
}];
[self.buttonContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.bottomContainerView);
make.right.equalTo(self.contentLabel);
make.bottom.equalTo(self.contentLabel.mas_top).offset(-30.0);
}];
[self.episcodeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentLabel);
make.bottom.equalTo(self.contentLabel.mas_top).offset(-12.0);
make.right.equalTo(self.buttonContainerView.mas_left).offset(-8.0);
}];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.episcodeLabel);
make.bottom.equalTo(self.episcodeLabel.mas_top).offset(-8.0);
}];
[self.shareButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.left.right.equalTo(self.buttonContainerView);
}];
[self.episcodeButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.buttonContainerView);
make.bottom.equalTo(self.shareButton.mas_top).offset(-26.0);
}];
[self.favoriteButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.top.right.equalTo(self.buttonContainerView);
make.bottom.equalTo(self.episcodeButton.mas_top).offset(-26.0);
}];
[self.danmuButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.bottomContainerView);
make.right.equalTo(self.mas_centerX).offset(-40);
make.width.height.mas_equalTo(30);
}];
[self.fullscreenButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.danmuButton);
make.left.equalTo(self.danmuButton.mas_right).offset(20);
make.width.mas_equalTo(80);
make.height.mas_equalTo(30);
}];
[self.resumeButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(self);
}];
}
#pragma mark - ZFPlayerMediaControl
- (void)gestureSingleTapped:(ZFPlayerGestureControl *)gestureControl {
CGFloat diff = [NSDate date].timeIntervalSince1970 - self.lastDoubleTapTime.timeIntervalSince1970;
if (diff < 0.6) {
[self handleDoubleTapped:gestureControl.singleTap];
self.lastDoubleTapTime = [NSDate date];
}else {
[self handleSingleTapped];
}
}
- (void)gestureDoubleTapped:(ZFPlayerGestureControl *)gestureControl {
[self handleDoubleTapped:gestureControl.doubleTap];
self.lastDoubleTapTime = [NSDate date];
}
- (void)handleSingleTapped {
id<ZFPlayerMediaPlayback> manager = self.player.currentPlayerManager;
if (manager.isPlaying) {
[manager pause];
[self.slider showLargeSlider];
self.resumeButton.hidden = NO;
self.resumeButton.transform = CGAffineTransformMakeScale(3, 3);
[UIView animateWithDuration:0.15 animations:^{
self.resumeButton.alpha = 1;
self.resumeButton.transform = CGAffineTransformIdentity;
}];
}else {
[manager play];
[self.slider showSmallSlider];
[UIView animateWithDuration:0.15 animations:^{
self.resumeButton.alpha = 0;
} completion:^(BOOL finished) {
self.resumeButton.hidden = YES;
}];
}
}
- (void)handleDoubleTapped:(UITapGestureRecognizer *)gesture {
CGPoint point = [gesture locationInView:gesture.view];
[self.doubleLikeView createAnimationWithPoint:point view:gesture.view completion:nil];
[self.favoriteButton startAnimationWithIsLike:YES];
self.model.is_collect = YES;
if ([self.delegate respondsToSelector:@selector(videoPortraitView:didClickFavorite:)]) {
[self.delegate videoPortraitView:self didClickFavorite:self.model];
}
}
- (void)setModel:(GKDYVideoModel *)model {
_model = model;
self.titleLabel.text = model.title;
self.contentLabel.text = model.detailText;
self.episcodeLabel.text = [NSString stringWithFormat:[@"player_text_episcode" language],model.videoInfo.episode,model.episode];
[self.favoriteButton setupLikeCount:[NSString stringWithFormat:@"%ld", model.collect_total]];
[self.favoriteButton setupLikeState:model.is_collect];
}
#pragma mark - Action
- (void)favoriteAction {
self.model.is_collect = !self.model.is_collect;
if ([self.delegate respondsToSelector:@selector(videoPortraitView:didClickFavorite:)]) {
[self.delegate videoPortraitView:self didClickFavorite:self.model];
}
}
- (void)episcodeAction {
if ([self.delegate respondsToSelector:@selector(videoPortraitView:didClickEpiscode:)]) {
[self.delegate videoPortraitView:self didClickEpiscode:self.model];
}
}
- (void)shareAction {
if ([self.delegate respondsToSelector:@selector(videoPortraitView:didClickShare:)]) {
[self.delegate videoPortraitView:self didClickShare:self.model];
}
}
- (void)danmuAction {
if ([self.delegate respondsToSelector:@selector(videoPortraitView:didClickDanmu:)]) {
[self.delegate videoPortraitView:self didClickDanmu:self.model];
}
}
- (void)fullscreenAction {
if ([self.delegate respondsToSelector:@selector(videoPortraitView:didClickFullscreen:)]) {
[self.delegate videoPortraitView:self didClickFullscreen:self.model];
}
}
- (void)sliderDragging:(BOOL)isDragging {
self.bottomContainerView.alpha = !isDragging;
}
- (void)willBeginDragging {
self.bottomContainerView.alpha = 0.4;
self.danmuButton.alpha = 0.4;
self.fullscreenButton.alpha = 0.4;
}
- (void)didEndDragging {
self.bottomContainerView.alpha = 1;
self.danmuButton.alpha = 1;
self.fullscreenButton.alpha = 1;
}
#pragma mark - Lazy
- (UIView *)bottomContainerView {
if (!_bottomContainerView) {
_bottomContainerView = [[UIView alloc] init];
}
return _bottomContainerView;
}
- (UIView *)buttonContainerView{
if (!_buttonContainerView) {
_buttonContainerView = [[UIView alloc] init];
}
return _buttonContainerView ;
}
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.font = [UIFont boldSystemFontOfSize:16];
_titleLabel.textColor = UIColor.whiteColor;
_titleLabel.userInteractionEnabled = YES;
}
return _titleLabel;
}
- (UILabel *)episcodeLabel {
if (!_episcodeLabel) {
_episcodeLabel = [[UILabel alloc] init];
_episcodeLabel.font = [UIFont systemFontOfSize:12.0 weight:UIFontWeightMedium];
_episcodeLabel.textColor = UIColor.whiteColor;
_episcodeLabel.text = @"Episode 1 Complete set : 999";
}
return _episcodeLabel;
}
- (UILabel *)contentLabel {
if (!_contentLabel) {
_contentLabel = [[UILabel alloc] init];
_contentLabel.font = [UIFont systemFontOfSize:12.0 weight:UIFontWeightLight];
_contentLabel.textColor = UIColor.whiteColor;
_contentLabel.numberOfLines = 4;
}
return _contentLabel;
}
- (GKDYVideoSlider *)slider {
if (!_slider) {
_slider = [[GKDYVideoSlider alloc] init];
@weakify(self);
_slider.slideBlock = ^(BOOL isDragging) {
@strongify(self);
[self sliderDragging:isDragging];
};
}
return _slider;
}
- (GKLikeView *)favoriteButton {
if (!_favoriteButton) {
_favoriteButton = [[GKLikeView alloc] init];
@weakify(self);
_favoriteButton.likeBlock = ^{
@strongify(self);
[self favoriteAction];
};
}
return _favoriteButton;
}
- (RSButton *)episcodeButton {
if (!_episcodeButton) {
_episcodeButton = [[RSButton alloc] initWithType:RSButtonTypeAbove];
_episcodeButton.margin = 4.0;
[_episcodeButton setTitleFont:[UIFont systemFontOfSize:12.0f weight:UIFontWeightRegular]];
[_episcodeButton setImage:[UIImage imageNamed:@"player_episode"] forState:UIControlStateNormal];
[_episcodeButton setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
[_episcodeButton setTitle:[@"player_text_series" language] forState:UIControlStateNormal];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(episcodeAction)];
[_episcodeButton addGestureRecognizer:tapGesture];
}
return _episcodeButton;
}
- (UIButton *)shareButton {
if (!_shareButton) {
_shareButton = [[UIButton alloc] init];
[_shareButton setImage:[UIImage imageNamed:@"player_shared"] forState:UIControlStateNormal];
[_shareButton addTarget:self action:@selector(shareAction) forControlEvents:UIControlEventTouchUpInside];
}
return _shareButton;
}
- (UIButton *)danmuButton {
if (!_danmuButton) {
_danmuButton = [[UIButton alloc] init];
_danmuButton.hidden = YES;
[_danmuButton setTitle:@"" forState:UIControlStateNormal];
[_danmuButton setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
_danmuButton.titleLabel.font = [UIFont systemFontOfSize:15];
_danmuButton.layer.cornerRadius = 15;
_danmuButton.layer.masksToBounds = YES;
_danmuButton.layer.borderColor = UIColor.whiteColor.CGColor;
_danmuButton.layer.borderWidth = 0.5;
[_danmuButton addTarget:self action:@selector(danmuAction) forControlEvents:UIControlEventTouchUpInside];
}
return _danmuButton;
}
- (UIButton *)fullscreenButton {
if (!_fullscreenButton) {
_fullscreenButton = [[UIButton alloc] init];
_fullscreenButton.hidden = YES;
[_fullscreenButton setTitle:@"全屏观看" forState:UIControlStateNormal];
[_fullscreenButton setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
_fullscreenButton.titleLabel.font = [UIFont systemFontOfSize:15];
_fullscreenButton.layer.cornerRadius = 15;
_fullscreenButton.layer.masksToBounds = YES;
_fullscreenButton.layer.borderColor = UIColor.whiteColor.CGColor;
_fullscreenButton.layer.borderWidth = 0.5;
[_fullscreenButton addTarget:self action:@selector(fullscreenAction) forControlEvents:UIControlEventTouchUpInside];
}
return _fullscreenButton;
}
- (UIButton *)resumeButton {
if (!_resumeButton) {
_resumeButton = [[UIButton alloc] init];
[_resumeButton setImage:[UIImage imageNamed:@"player_play"] forState:UIControlStateNormal];
_resumeButton.hidden = YES;
}
return _resumeButton;
}
- (GKDoubleLikeView *)doubleLikeView {
if (!_doubleLikeView) {
_doubleLikeView = [[GKDoubleLikeView alloc] init];
}
return _doubleLikeView;
}
@end