Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: 재생화면 설명 뷰 버그 수정 & 플레이어뷰 옵저버 제거 코드 추가 #235

Merged
merged 4 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions iOS/Layover/Layover/Scenes/Playback/Cell/PlaybackCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,52 +10,55 @@ import UIKit
import AVFoundation

final class PlaybackCell: UICollectionViewCell {
let playbackView: PlaybackView = PlaybackView()
var timeObserverToken: Any?
var boardID: Int = 0

var boardID: Int?

var playbackView: PlaybackView?

override init(frame: CGRect) {
super.init(frame: frame)
configure()
}

required init?(coder: NSCoder) {
super.init(coder: coder)
configure()
}

override func prepareForReuse() {
resetObserver()
}

func setPlaybackContents(info: PlaybackModels.PlaybackInfo) {
playbackView = nil
boardID = info.boardID
playbackView.descriptionView.titleLabel.text = info.title
playbackView.descriptionView.setText(info.content)
playbackView.profileLabel.text = info.profileName
playbackView.tagStackView.resetTagStackView()
playbackView = PlaybackView(frame: .zero, content: info.content)
playbackView?.descriptionView.titleLabel.text = info.title
configure()
playbackView?.descriptionView.setText(info.content)
playbackView?.profileLabel.text = info.profileName
playbackView?.tagStackView.resetTagStackView()
info.tag.forEach { tag in
playbackView.tagStackView.addTag(tag)
playbackView?.tagStackView.addTag(tag)
}
}

func addAVPlayer(url: URL) {
playbackView.resetPlayer()
playbackView.addAVPlayer(url: url)
playbackView.setPlayerSlider()
playbackView?.resetPlayer()
playbackView?.addAVPlayer(url: url)
playbackView?.setPlayerSlider()
}

func addPlayerSlider(tabBarHeight: CGFloat) {
playbackView.addWindowPlayerSlider(tabBarHeight)
playbackView?.addWindowPlayerSlider(tabBarHeight)

}

func resetObserver() {
playbackView.removeTimeObserver()
playbackView.removePlayerSlider()
playbackView?.removeTimeObserver()
playbackView?.removePlayerSlider()
}

private func configure() {
guard let playbackView else { return }
playbackView.translatesAutoresizingMaskIntoConstraints = false
contentView.addSubview(playbackView)
NSLayoutConstraint.activate([
Expand Down
8 changes: 5 additions & 3 deletions iOS/Layover/Layover/Scenes/Playback/PlaybackInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,16 @@ final class PlaybackInteractor: PlaybackBusinessLogic, PlaybackDataStore {
}

func controlPlaybackMovie(with request: PlaybackModels.SeekVideo.Request) {
guard let prevCell else { return }
let willMoveLocation: Float64 = request.currentLocation * prevCell.playbackView.getDuration()
guard let prevCell,
let playbackView = prevCell.playbackView
else { return }
let willMoveLocation: Float64 = request.currentLocation * playbackView.getDuration()
let response: Models.SeekVideo.Response = Models.SeekVideo.Response(willMoveLocation: willMoveLocation, curCell: prevCell)
presenter?.presentSeekVideo(with: response)
}

func hidePlayerSlider() {
guard let prevCell else { return }
prevCell.playbackView.playerSlider?.isHidden = true
prevCell.playbackView?.playerSlider?.isHidden = true
}
}
38 changes: 25 additions & 13 deletions iOS/Layover/Layover/Scenes/Playback/PlaybackView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ final class PlaybackView: UIView {

// MARK: - Properties

var descriptionContent: String

private var timeObserverToken: Any?

private var playerObserverToken: Any?

// MARK: - UI Components
// TODO: private 다시 붙이고 Method 처리
let descriptionView: LODescriptionView = {
lazy var descriptionView: LODescriptionView = {
let descriptionView: LODescriptionView = LODescriptionView()
descriptionView.setText("밤새 모니터에 튀긴 침이 마르기도 전에 대기실로 아참 교수님이 문신 땜에 긴팔 입고 오래 난 시작도 전에 눈을 감았지")
descriptionView.setText(descriptionContent)
descriptionView.clipsToBounds = true
return descriptionView
}()
Expand Down Expand Up @@ -88,19 +92,19 @@ final class PlaybackView: UIView {

// MARK: - View Life Cycle

override init(frame: CGRect) {
init(frame: CGRect, content: String) {
self.descriptionContent = content
super.init(frame: frame)
setUI()
addDescriptionAnimateGesture()
setSubViewsInPlayerViewConstraints()
// addDescriptionAnimateGesture()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 주석은 사용하는 것인가욤

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

안 사용해요 지울게요

setPlayerView()
}

required init?(coder: NSCoder) {
self.descriptionContent = ""
super.init(coder: coder)
setUI()
addDescriptionAnimateGesture()
setSubViewsInPlayerViewConstraints()
// addDescriptionAnimateGesture()
setPlayerView()
}

Expand All @@ -118,9 +122,11 @@ final class PlaybackView: UIView {

func stopPlayer() {
playerView.pause()
NotificationCenter.default.removeObserver(self)
}

func playPlayer() {
NotificationCenter.default.addObserver(self, selector: #selector(playerDidFinishPlaying), name: .AVPlayerItemDidPlayToEndTime, object: playerView.player?.currentItem)
playerView.play()
}

Expand Down Expand Up @@ -192,24 +198,30 @@ private extension PlaybackView {
func setPlayerView() {
let playerViewGesture: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(playerViewDidTap))
self.addGestureRecognizer(playerViewGesture)
NotificationCenter.default.addObserver(self, selector: #selector(playerDidFinishPlaying), name: .AVPlayerItemDidPlayToEndTime, object: playerView.player?.currentItem)
}

func addDescriptionAnimateGesture() {
let descriptionViewGesture: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(descriptionViewDidTap(_:)))
for recognizer in descriptionView.descriptionLabel.gestureRecognizers ?? [] {
descriptionView.descriptionLabel.removeGestureRecognizer(recognizer)
}
descriptionView.descriptionLabel.addGestureRecognizer(descriptionViewGesture)
}

// MARK: - UI Method

func setDescriptionViewUI() {
let size: CGSize = CGSize(width: LODescriptionView.descriptionWidth, height: .infinity)
let estimatedSize: CGSize = descriptionView.descriptionLabel.sizeThatFits(size)
let totalHeight: CGFloat = estimatedSize.height + descriptionView.titleLabel.intrinsicContentSize.height
descriptionView.heightAnchor.constraint(equalToConstant: totalHeight).isActive = true
descriptionView.titleLabel.topAnchor.constraint(equalTo: descriptionView.topAnchor, constant: totalHeight - LODescriptionView.descriptionHeight).isActive = true
if descriptionView.checkLabelOverflow() {
let size: CGSize = CGSize(width: LODescriptionView.descriptionWidth, height: .infinity)
let estimatedSize: CGSize = descriptionView.descriptionLabel.sizeThatFits(size)
let totalHeight: CGFloat = estimatedSize.height + descriptionView.titleLabel.intrinsicContentSize.height
descriptionView.heightAnchor.constraint(equalToConstant: totalHeight).isActive = true
descriptionView.titleLabel.topAnchor.constraint(equalTo: descriptionView.topAnchor, constant: totalHeight - LODescriptionView.descriptionHeight).isActive = true
descriptionView.descriptionLabel.layer.addSublayer(gradientLayer)
addDescriptionAnimateGesture()
} else {
descriptionView.heightAnchor.constraint(equalToConstant: LODescriptionView.descriptionHeight).isActive = true
descriptionView.titleLabel.topAnchor.constraint(equalTo: descriptionView.topAnchor).isActive = true
}
}

Expand Down
20 changes: 10 additions & 10 deletions iOS/Layover/Layover/Scenes/Playback/PlaybackViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,14 @@ extension PlaybackViewController: PlaybackDisplayLogic {
func stopPrevPlayerAndPlayCurPlayer(viewModel: PlaybackModels.DisplayPlaybackVideo.ViewModel) {
guard let tabBarHeight: CGFloat = self.tabBarController?.tabBar.frame.height else { return }
if let prevCell = viewModel.prevCell {
prevCell.playbackView.removePlayerSlider()
prevCell.playbackView.stopPlayer()
prevCell.playbackView.replayPlayer()
prevCell.playbackView?.removePlayerSlider()
prevCell.playbackView?.stopPlayer()
prevCell.playbackView?.replayPlayer()
}
if let curCell = viewModel.curCell {
curCell.addPlayerSlider(tabBarHeight: tabBarHeight)
curCell.playbackView.addTargetPlayerSlider()
curCell.playbackView.playPlayer()
curCell.playbackView?.addTargetPlayerSlider()
curCell.playbackView?.playPlayer()
}
}

Expand All @@ -164,7 +164,7 @@ extension PlaybackViewController: PlaybackDisplayLogic {
}

func showPlayerSlider(viewModel: PlaybackModels.DisplayPlaybackVideo.ViewModel) {
viewModel.curCell?.playbackView.playerSlider?.isHidden = false
viewModel.curCell?.playbackView?.playerSlider?.isHidden = false
}

func moveInitialPlaybackCell(viewModel: PlaybackModels.SetInitialPlaybackCell.ViewModel) {
Expand All @@ -179,7 +179,7 @@ extension PlaybackViewController: PlaybackDisplayLogic {
}

func leavePlaybackView(viewModel: PlaybackModels.DisplayPlaybackVideo.ViewModel) {
viewModel.prevCell?.playbackView.stopPlayer()
viewModel.prevCell?.playbackView?.stopPlayer()
}

func configureDataSource(viewModel: PlaybackModels.ConfigurePlaybackCell.ViewModel) {
Expand All @@ -199,14 +199,14 @@ extension PlaybackViewController: PlaybackDisplayLogic {

func seekVideo(viewModel: PlaybackModels.SeekVideo.ViewModel) {
let seekTime: CMTime = CMTime(value: CMTimeValue(viewModel.willMoveLocation), timescale: 1)
viewModel.curCell.playbackView.seekPlayer(seekTime: seekTime)
viewModel.curCell.playbackView.playPlayer()
viewModel.curCell.playbackView?.seekPlayer(seekTime: seekTime)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curCell이 현재 셀인가요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네 그렇습니다.

viewModel.curCell.playbackView?.playPlayer()
}

func routeToBack(viewModel: PlaybackModels.DisplayPlaybackVideo.ViewModel) {
var curCell = viewModel.curCell
curCell?.resetObserver()
curCell?.playbackView.resetPlayer()
curCell?.playbackView?.resetPlayer()
curCell = nil
}

Expand Down