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

chore: 재생화면 동작 개선 #172

Merged
merged 13 commits into from
Dec 4, 2023
Merged
2 changes: 1 addition & 1 deletion iOS/Layover/Layover/Models/Board.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

struct Board: Hashable {
struct Board {
let identifier: Int
let title: String
let description: String?
Expand Down
2 changes: 1 addition & 1 deletion iOS/Layover/Layover/Models/Member.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

struct Member: Hashable {
struct Member {
let identifier: Int
let username: String
let introduce: String
Expand Down
2 changes: 1 addition & 1 deletion iOS/Layover/Layover/Models/Post.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

struct Post: Hashable {
struct Post {
let member: Member
let board: Board
let tag: [String]
Expand Down
2 changes: 1 addition & 1 deletion iOS/Layover/Layover/Network/Mock/MockData/PostList.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"board" : {
"id" : 2,
"url" : "https://playertest.longtailvideo.com/adaptive/wowzaid3/playlist.m3u8",
"url" : "https://qc66zhsq1708.edge.naverncp.com/hls/fMG98EEU8c1UirV-awtm4qKJyhaHRcnDymRFlPLZbTs_/layover-station/IMG_0136_AVC_,HD,SD,_1Pass_30fps.mp4.smil/master.m3u8",
"video_thumbnail" : "video_thumbnail_link",
"longitude" : "37.0532156213",
"latitude" : "127.060123123",
Expand Down
1 change: 1 addition & 0 deletions iOS/Layover/Layover/Scenes/Home/HomeInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ extension HomeInteractor: HomeBusinessLogic {
let response = Models.FetchPosts.Response(posts: posts)

await MainActor.run {
self.posts = posts
presenter?.presentPosts(with: response)
}
}
Expand Down
7 changes: 1 addition & 6 deletions iOS/Layover/Layover/Scenes/Home/HomeRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final class HomeRouter: NSObject, HomeRoutingLogic, HomeDataPassing {
else { return }
destination.parentView = .home
destination.index = source.postPlayStartIndex
destination.videos = transData(videos: source.posts ?? [])
destination.posts = source.posts
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

viewController?.navigationController?.pushViewController(playbackViewController, animated: true)
}
func routeToEditVideo() {
Expand All @@ -55,11 +55,6 @@ final class HomeRouter: NSObject, HomeRoutingLogic, HomeDataPassing {
viewController?.navigationController?.pushViewController(nextViewController, animated: true)
}

private func transData(videos: [Post]) -> [PlaybackModels.PlaybackVideo] {
videos.map { video in
return PlaybackModels.PlaybackVideo(post: video)
}
}
// MARK: - Data Passing

// func passDataTo(_ destinationDS: inout NextDataStore, from sourceDS: HomeDataStore) {
Expand Down
8 changes: 4 additions & 4 deletions iOS/Layover/Layover/Scenes/Map/MapInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protocol MapBusinessLogic {
}

protocol MapDataStore {
var videos: [Post]? { get set }
var posts: [Post]? { get set }
var index: Int? { get set }
}

Expand All @@ -34,8 +34,8 @@ final class MapInteractor: NSObject, MapBusinessLogic, MapDataStore {

var index: Int?

var videos: [Post]?
var posts: [Post]?

var presenter: MapPresentationLogic?

override init() {
Expand All @@ -60,7 +60,7 @@ final class MapInteractor: NSObject, MapBusinessLogic, MapDataStore {
}

func moveToPlaybackScene(with request: Models.MoveToPlaybackScene.Request) {
videos = request.videos
posts = request.videos
index = request.index
presenter?.presentPlaybackScene()
}
Expand Down
9 changes: 1 addition & 8 deletions iOS/Layover/Layover/Scenes/Map/MapRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,7 @@ final class MapRouter: MapRoutingLogic, MapDataPassing {
else { return }
destination.parentView = .other
destination.index = source.index
destination.videos = transData(videos: source.videos ?? [])
destination.posts = source.posts
viewController?.navigationController?.pushViewController(playbackViewController, animated: true)
}

private func transData(videos: [Post]) -> [PlaybackModels.PlaybackVideo] {
videos.map { video in
return PlaybackModels.PlaybackVideo(post: video)
}
}

}
18 changes: 7 additions & 11 deletions iOS/Layover/Layover/Scenes/Playback/Cell/PlaybackCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,20 @@ final class PlaybackCell: UICollectionViewCell {
configure()
}

// TODO: VideoModel 받아서 처리
func setPlaybackContents(viewModel: PlaybackModels.PlaybackVideo) {
playbackView.descriptionView.titleLabel.text = viewModel.post.board.title
playbackView.descriptionView.setText(viewModel.post.board.description ?? "")

func setPlaybackContents(info: PlaybackModels.PlaybackInfo) {
playbackView.descriptionView.titleLabel.text = info.title
playbackView.descriptionView.setText(info.content)
playbackView.profileLabel.text = info.profileName
info.tag.forEach { tag in
playbackView.tagStackView.addTag(tag)
}
Comment on lines +28 to +30
Copy link
Collaborator

@loinsir loinsir Dec 4, 2023

Choose a reason for hiding this comment

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

지웅님 이 부분 재사용 이슈는 없나요? 다시 set될때 tag 버튼이 중복으로 들어갈 것 같은데 처음에 초기화 주는 부분이 없는 것 같아서요

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

재사용 이슈 생겨서 stackView remove하는 식으로 해결했습니다. UI에 관련된 것이기 때문에 prepareForReuse안쓰고 셀 초기화 하는 부분에서 해줬어용

}

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

func setPlayerSlider(tabbarHeight: CGFloat) {
playbackView.setPlayerSlider()
playbackView.setPlayerSliderUI(tabbarHeight: tabbarHeight)
}

private func configure() {
playbackView.translatesAutoresizingMaskIntoConstraints = false
contentView.addSubview(playbackView)
Expand All @@ -47,6 +44,5 @@ final class PlaybackCell: UICollectionViewCell {
playbackView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
playbackView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor)
])
playbackView.playerSlider.isHidden = true
}
}
58 changes: 34 additions & 24 deletions iOS/Layover/Layover/Scenes/Playback/PlaybackInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@ import UIKit
protocol PlaybackBusinessLogic {
func displayVideoList()
func moveInitialPlaybackCell()
func hidePlayerSlider()
func setInitialPlaybackCell()
func leavePlaybackView()
func playInitialPlaybackCell(with request: PlaybackModels.DisplayPlaybackVideo.Request)
func playVideo(with request: PlaybackModels.DisplayPlaybackVideo.Request)
func playTeleportVideo(with request: PlaybackModels.DisplayPlaybackVideo.Request)
func configurePlaybackCell()
func controlPlaybackMovie(with request: PlaybackModels.SeekVideo.Request)
}

protocol PlaybackDataStore: AnyObject {
var videos: [PlaybackModels.PlaybackVideo]? { get set }
var parentView: PlaybackModels.ParentView? { get set }
var prevCell: PlaybackCell? { get set }
var index: Int? { get set }
var isTeleport: Bool? { get set }
var posts: [Post]? { get set }
}

final class PlaybackInteractor: PlaybackBusinessLogic, PlaybackDataStore {
Expand All @@ -36,8 +37,6 @@ final class PlaybackInteractor: PlaybackBusinessLogic, PlaybackDataStore {
lazy var worker = PlaybackWorker()
var presenter: PlaybackPresentationLogic?

var videos: [PlaybackModels.PlaybackVideo]?

var parentView: Models.ParentView?

var prevCell: PlaybackCell?
Expand All @@ -46,24 +45,21 @@ final class PlaybackInteractor: PlaybackBusinessLogic, PlaybackDataStore {

var isTeleport: Bool?

var posts: [Post]?

// MARK: - UseCase Load Video List

func displayVideoList() {
guard let parentView: Models.ParentView else {
return
}
guard var videos: [PlaybackModels.PlaybackVideo] else {
return
}
guard let parentView: Models.ParentView else { return }
guard var posts: [Post] else { return }
if parentView == .other {
videos = worker.makeInfiniteScroll(videos: videos)
self.videos = videos
posts = worker.makeInfiniteScroll(posts: posts)
self.posts = posts
}
let response: Models.LoadPlaybackVideoList.Response = Models.LoadPlaybackVideoList.Response(videos: videos)
let response: Models.LoadPlaybackVideoList.Response = Models.LoadPlaybackVideoList.Response(posts: posts)
presenter?.presentVideoList(with: response)
}


func moveInitialPlaybackCell() {
let response: Models.SetInitialPlaybackCell.Response = Models.SetInitialPlaybackCell.Response(indexPathRow: index ?? 0)
if parentView == .other {
Expand Down Expand Up @@ -94,13 +90,8 @@ final class PlaybackInteractor: PlaybackBusinessLogic, PlaybackDataStore {
presenter?.presentPlayInitialPlaybackCell(with: response)
}

func hidePlayerSlider() {
let response: Models.DisplayPlaybackVideo.Response = Models.DisplayPlaybackVideo.Response(prevCell: prevCell, curCell: nil)
presenter?.presentHidePlayerSlider(with: response)
}

func playVideo(with request: PlaybackModels.DisplayPlaybackVideo.Request) {
guard let videos else { return }
guard let posts else { return }
var response: Models.DisplayPlaybackVideo.Response
if prevCell == request.curCell {
response = Models.DisplayPlaybackVideo.Response(prevCell: nil, curCell: prevCell)
Expand All @@ -110,10 +101,10 @@ final class PlaybackInteractor: PlaybackBusinessLogic, PlaybackDataStore {
}
// Home이 아닌 다른 뷰에서 왔을 경우(로드한 목록 무한 반복)
if parentView == .other {
if request.indexPathRow == (videos.count - 1) {
if request.indexPathRow == (posts.count - 1) {
response = Models.DisplayPlaybackVideo.Response(indexPathRow: 1, prevCell: prevCell, curCell: nil)
} else if request.indexPathRow == 0 {
response = Models.DisplayPlaybackVideo.Response(indexPathRow: videos.count - 2, prevCell: prevCell, curCell: nil)
response = Models.DisplayPlaybackVideo.Response(indexPathRow: posts.count - 2, prevCell: prevCell, curCell: nil)
} else {
response = Models.DisplayPlaybackVideo.Response(prevCell: prevCell, curCell: request.curCell)
prevCell = request.curCell
Expand All @@ -134,9 +125,9 @@ final class PlaybackInteractor: PlaybackBusinessLogic, PlaybackDataStore {

func playTeleportVideo(with request: PlaybackModels.DisplayPlaybackVideo.Request) {
guard let isTeleport else { return }
guard let videos else { return }
guard let posts else { return }
if isTeleport {
if request.indexPathRow == 1 || request.indexPathRow == (videos.count - 2) {
if request.indexPathRow == 1 || request.indexPathRow == (posts.count - 2) {
let response: Models.DisplayPlaybackVideo.Response = Models.DisplayPlaybackVideo.Response(prevCell: prevCell, curCell: request.curCell)
prevCell = request.curCell
presenter?.presentMoveCellNext(with: response)
Expand All @@ -150,4 +141,23 @@ final class PlaybackInteractor: PlaybackBusinessLogic, PlaybackDataStore {
presenter?.presentLeavePlaybackView(with: response)
}

func configurePlaybackCell() {
guard let posts else { return }
guard let parentView else { return }
let response: Models.ConfigurePlaybackCell.Response
switch parentView {
case .home:
response = Models.ConfigurePlaybackCell.Response(teleportIndex: nil)
case .other:
response = Models.ConfigurePlaybackCell.Response(teleportIndex: posts.count + 1)
}
presenter?.presentConfigureCell(with: response)
}

func controlPlaybackMovie(with request: PlaybackModels.SeekVideo.Request) {
guard let prevCell else { return }
let willMoveLocation: Float64 = request.currentLocation * prevCell.playbackView.getDuration()
let response: Models.SeekVideo.Response = Models.SeekVideo.Response(willMoveLocation: willMoveLocation, curCell: prevCell)
presenter?.presentSeekVideo(with: response)
}
}
51 changes: 49 additions & 2 deletions iOS/Layover/Layover/Scenes/Playback/PlaybackModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,29 @@ enum PlaybackModels {
// MARK: - Properties Type
struct PlaybackVideo: Hashable {
var id: UUID = UUID()
let post: Post
let playbackInfo: PlaybackInfo
}
Comment on lines 13 to 16
Copy link
Collaborator

Choose a reason for hiding this comment

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

지웅님 이거 근데 궁금한게 있는데 UUID 넣어주신 이유가 있나요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

넹 무한스크롤 구현할 때 더미 셀이 들어가는데, 더미 셀 들어갈 때 중복셀 방지하려고 넣었습니다.

Copy link
Collaborator

Choose a reason for hiding this comment

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

아 그러면 이제 아래 PlaybackInfo가 Hashable하니까 이건 안써도 되는...?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

넹넹 리뷰 반영사항에 수정해뒀어요


enum ParentView {
case home
case other
}

struct PlaybackInfo: Hashable {
let title: String
let content: String
let profileImageURL: URL?
let profileName: String
let tag: [String]
// location
let videoURL: URL
}

struct PlaybackViewInfo {
let parentView: ParentView
let videos: [PlaybackVideo]
}

// MARK: - UseCase Load Video List

enum LoadPlaybackVideoList {
Expand All @@ -28,7 +43,7 @@ enum PlaybackModels {
}

struct Response {
let videos: [PlaybackVideo]
let posts: [Post]
}

struct ViewModel {
Expand Down Expand Up @@ -85,4 +100,36 @@ enum PlaybackModels {
}
}

// MARK: - UseCase Cell Configure

enum ConfigurePlaybackCell {
struct Request {
}

struct Response {
let teleportIndex: Int?
}

struct ViewModel {
let teleportIndex: Int?
}
}

// MARK: - UseCase Seek Video

enum SeekVideo {
struct Request {
let currentLocation: Float64
}

struct Response {
let willMoveLocation: Float64
let curCell: PlaybackCell
}

struct ViewModel {
let willMoveLocation: Float64
let curCell: PlaybackCell
}
}
}
Loading