Skip to content

Commit

Permalink
✨ 삭제 후 동영상 처리 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
chopmozzi committed Dec 7, 2023
1 parent 2fc4c0d commit b2d1af9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 13 deletions.
45 changes: 35 additions & 10 deletions iOS/Layover/Layover/Scenes/Playback/PlaybackInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,22 @@ protocol PlaybackBusinessLogic {
func playInitialPlaybackCell(with request: PlaybackModels.DisplayPlaybackVideo.Request)
func playVideo(with request: PlaybackModels.DisplayPlaybackVideo.Request)
func playTeleportVideo(with request: PlaybackModels.DisplayPlaybackVideo.Request)
func moveToBack()
func resetVideo()
func configurePlaybackCell()
func controlPlaybackMovie(with request: PlaybackModels.SeekVideo.Request)
func hidePlayerSlider()
func setSeeMoreButton()
@discardableResult
func deleteVideo(with request: PlaybackModels.DeletePlaybackVideo.Request) -> Task<Bool, Never>
func reRunVideo()
}

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

Expand All @@ -50,6 +52,8 @@ final class PlaybackInteractor: PlaybackBusinessLogic, PlaybackDataStore {

var isTeleport: Bool?

var isDelete: Bool?

var posts: [Post]?

// MARK: - UseCase Load Video List
Expand Down Expand Up @@ -132,14 +136,29 @@ final class PlaybackInteractor: PlaybackBusinessLogic, PlaybackDataStore {
}

func playTeleportVideo(with request: PlaybackModels.DisplayPlaybackVideo.Request) {
guard let isTeleport,
let posts else { return }
if isTeleport {
if request.indexPathRow == 1 || request.indexPathRow == (posts.count - 2) {
let response: Models.DisplayPlaybackVideo.Response = Models.DisplayPlaybackVideo.Response(prevCell: prevCell, curCell: request.curCell)
// guard let isTeleport,
// let posts,
// let isDelete
// else { return }
guard let posts else { return }
var response: Models.DisplayPlaybackVideo.Response
if let isTeleport {
if isTeleport {
if request.indexPathRow == 1 || request.indexPathRow == (posts.count - 2) {
response = Models.DisplayPlaybackVideo.Response(prevCell: prevCell, curCell: request.curCell)
prevCell = request.curCell
presenter?.presentMoveCellNext(with: response)
self.isTeleport = false
}
}
}

if let isDelete {
if isDelete {
response = Models.DisplayPlaybackVideo.Response(prevCell: nil, curCell: request.curCell)
prevCell = request.curCell
presenter?.presentMoveCellNext(with: response)
self.isTeleport = false
self.isDelete = false
}
}
}
Expand All @@ -149,7 +168,7 @@ final class PlaybackInteractor: PlaybackBusinessLogic, PlaybackDataStore {
presenter?.presentLeavePlaybackView(with: response)
}

func moveToBack() {
func resetVideo() {
let response: Models.DisplayPlaybackVideo.Response = Models.DisplayPlaybackVideo.Response(prevCell: nil, curCell: prevCell)
presenter?.presentResetPlaybackCell(with: response)
}
Expand Down Expand Up @@ -188,10 +207,11 @@ final class PlaybackInteractor: PlaybackBusinessLogic, PlaybackDataStore {
// MARK: - UseCase Delete Video

func deleteVideo(with request: PlaybackModels.DeletePlaybackVideo.Request) -> Task<Bool, Never> {
Task {
isDelete = true
return Task {
guard let prevCell,
let worker
else { return false}
else { return false }
let result: Bool = await worker.deletePlaybackVideo(boardID: prevCell.boardID)
let response: Models.DeletePlaybackVideo.Response = Models.DeletePlaybackVideo.Response(result: result, playbackVideo: request.playbackVideo)
await MainActor.run {
Expand All @@ -200,4 +220,9 @@ final class PlaybackInteractor: PlaybackBusinessLogic, PlaybackDataStore {
return result
}
}

func reRunVideo() {
guard let prevCell else { return }
prevCell.playbackView.playPlayer()
}
}
13 changes: 10 additions & 3 deletions iOS/Layover/Layover/Scenes/Playback/PlaybackViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ final class PlaybackViewController: BaseViewController {
super.viewWillDisappear(animated)
interactor?.leavePlaybackView()
if isMovingFromParent {
interactor?.moveToBack()
interactor?.resetVideo()
}
}

Expand Down Expand Up @@ -137,7 +137,10 @@ final class PlaybackViewController: BaseViewController {
[weak self] _ in
self?.router?.routeToReport()
})
let cancelAction: UIAlertAction = UIAlertAction(title: "취소", style: .cancel)
let cancelAction: UIAlertAction = UIAlertAction(title: "취소", style: .cancel, handler: {
[weak self] _ in
self?.interactor?.reRunVideo()
})
alert.addAction(reportAction)
alert.addAction(cancelAction)
self.present(alert, animated: true, completion: {
Expand All @@ -156,7 +159,10 @@ final class PlaybackViewController: BaseViewController {
[weak self] _ in
self?.interactor?.deleteVideo(with: request)
})
let cancelAction: UIAlertAction = UIAlertAction(title: "취소", style: .cancel)
let cancelAction: UIAlertAction = UIAlertAction(title: "취소", style: .cancel, handler: {
[weak self] _ in
self?.interactor?.reRunVideo()
})
alert.addAction(deleteAction)
alert.addAction(cancelAction)
present(alert, animated: true, completion: {
Expand Down Expand Up @@ -258,6 +264,7 @@ extension PlaybackViewController: PlaybackDisplayLogic {
}

func deleteVideo(viewModel: PlaybackModels.DeletePlaybackVideo.ViewModel) {
interactor?.resetVideo()
guard let dataSource else { return }
var snapshot = dataSource.snapshot()
snapshot.deleteItems([viewModel.playbackVideo])
Expand Down

0 comments on commit b2d1af9

Please sign in to comment.