chore: add media type with gif and video

This commit is contained in:
sunxiaojian 2021-03-12 15:41:57 +08:00
parent 2e31280819
commit 6b5edff677
4 changed files with 70 additions and 22 deletions

View File

@ -210,8 +210,7 @@ extension StatusSection {
playerViewController.delegate = cell.delegate?.playerViewControllerDelegate
playerViewController.player = videoPlayerViewModel.player
playerViewController.showsPlaybackControls = videoPlayerViewModel.videoKind != .gif
playerContainerView.gifIndicatorLabel.isHidden = videoPlayerViewModel.videoKind != .gif
playerContainerView.setMediaKind(kind: videoPlayerViewModel.videoKind)
playerContainerView.isHidden = false
} else {

View File

@ -37,6 +37,7 @@ internal enum Asset {
internal static let disabled = ColorAsset(name: "Colors/Background/Poll/disabled")
internal static let highlight = ColorAsset(name: "Colors/Background/Poll/highlight")
}
internal static let mediaTypeIndicotor = ColorAsset(name: "Colors/Background/mediaTypeIndicotor")
internal static let onboardingBackground = ColorAsset(name: "Colors/Background/onboarding.background")
internal static let secondaryGroupedSystemBackground = ColorAsset(name: "Colors/Background/secondary.grouped.system.background")
internal static let secondarySystemBackground = ColorAsset(name: "Colors/Background/secondary.system.background")

View File

@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "0.600",
"blue" : "0",
"green" : "0",
"red" : "0"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@ -26,14 +26,28 @@ final class PlayerContainerView: UIView {
let playerViewController = AVPlayerViewController()
let gifIndicatorLabel: UILabel = {
let mediaTypeIndicotorLabel: UILabel = {
let label = UILabel()
label.font = .systemFont(ofSize: 16, weight: .heavy)
label.text = "GIF"
label.font = .systemFont(ofSize: 18, weight: .heavy)
label.textColor = .white
label.textAlignment = .right
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()
let mediaTypeIndicotorView: UIView = {
let view = UIView()
view.backgroundColor = Asset.Colors.Background.mediaTypeIndicotor.color
view.translatesAutoresizingMaskIntoConstraints = false
let rect = CGRect(x: 0, y: 0, width: 47, height: 50)
let path = UIBezierPath(roundedRect: rect, byRoundingCorners: [.topLeft], cornerRadii: CGSize(width: 50, height: 50))
let maskLayer = CAShapeLayer()
maskLayer.frame = rect
maskLayer.path = path.cgPath
view.layer.mask = maskLayer
return view
}()
weak var delegate: PlayerContainerViewDelegate?
override init(frame: CGRect) {
@ -60,14 +74,6 @@ extension PlayerContainerView {
containerHeightLayoutConstraint,
])
addSubview(gifIndicatorLabel)
gifIndicatorLabel.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
gifIndicatorLabel.bottomAnchor.constraint(equalTo: bottomAnchor, constant: 4),
gifIndicatorLabel.trailingAnchor.constraint(equalTo: trailingAnchor)
])
// will not influence full-screen playback
playerViewController.view.layer.masksToBounds = true
playerViewController.view.layer.cornerRadius = PlayerContainerView.cornerRadius
@ -80,8 +86,24 @@ extension PlayerContainerView {
contentWarningOverlayView.trailingAnchor.constraint(equalTo: trailingAnchor),
contentWarningOverlayView.bottomAnchor.constraint(equalTo: bottomAnchor)
])
contentWarningOverlayView.delegate = self
// mediaType
addSubview(mediaTypeIndicotorView)
NSLayoutConstraint.activate([
mediaTypeIndicotorView.bottomAnchor.constraint(equalTo: bottomAnchor),
mediaTypeIndicotorView.trailingAnchor.constraint(equalTo: trailingAnchor),
mediaTypeIndicotorView.heightAnchor.constraint(equalToConstant: 25),
mediaTypeIndicotorView.widthAnchor.constraint(equalToConstant: 47)
])
mediaTypeIndicotorView.addSubview(mediaTypeIndicotorLabel)
NSLayoutConstraint.activate([
mediaTypeIndicotorLabel.topAnchor.constraint(equalTo: mediaTypeIndicotorView.topAnchor),
mediaTypeIndicotorLabel.leadingAnchor.constraint(equalTo: mediaTypeIndicotorView.leadingAnchor),
mediaTypeIndicotorLabel.bottomAnchor.constraint(equalTo: mediaTypeIndicotorView.bottomAnchor),
mediaTypeIndicotorView.trailingAnchor.constraint(equalTo: mediaTypeIndicotorLabel.trailingAnchor, constant: 8)
])
}
}
@ -96,8 +118,6 @@ extension PlayerContainerView {
func reset() {
// note: set playerViewController.player pause() and nil in data source configuration process make reloadData not break playing
gifIndicatorLabel.removeFromSuperview()
playerViewController.willMove(toParent: nil)
playerViewController.view.removeFromSuperview()
playerViewController.removeFromParent()
@ -137,13 +157,21 @@ extension PlayerContainerView {
containerHeightLayoutConstraint.constant = floor(rect.height)
containerHeightLayoutConstraint.isActive = true
gifIndicatorLabel.translatesAutoresizingMaskIntoConstraints = false
touchBlockingView.addSubview(gifIndicatorLabel)
NSLayoutConstraint.activate([
touchBlockingView.trailingAnchor.constraint(equalTo: gifIndicatorLabel.trailingAnchor, constant: 8),
touchBlockingView.bottomAnchor.constraint(equalTo: gifIndicatorLabel.bottomAnchor, constant: 8),
])
bringSubviewToFront(mediaTypeIndicotorView)
return playerViewController
}
func setMediaKind(kind: VideoPlayerViewModel.Kind) {
switch kind {
case .gif:
mediaTypeIndicotorLabel.text = "GIF"
case .video:
let configuration = UIImage.SymbolConfiguration(font: .systemFont(ofSize: 18, weight: .regular))
let image = UIImage(systemName: "video.fill", withConfiguration: configuration)!
let attachment = NSTextAttachment()
attachment.image = image.withTintColor(.white)
mediaTypeIndicotorLabel.attributedText = NSAttributedString(attachment: attachment)
}
}
}