From 8b23d23bacd8b154f0edbc21302f4b0ffca0e7e3 Mon Sep 17 00:00:00 2001 From: chopmozzi <44396392+chopmozzi@users.noreply.github.com> Date: Mon, 11 Dec 2023 23:28:33 +0900 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=EC=8B=A0=EA=B3=A0=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EB=A1=9C=EC=A7=81=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Scenes/Playback/Cell/PlaybackCell.swift | 2 +- .../Scenes/Playback/PlaybackInteractor.swift | 7 +++-- .../Scenes/Playback/PlaybackModels.swift | 2 +- .../Scenes/Playback/PlaybackPresenter.swift | 3 +- .../Playback/PlaybackViewController.swift | 30 ++++++++++++++----- .../Scenes/Playback/PlaybackWorker.swift | 10 ++++++- .../Workers/Mocks/MockPlaybackWorker.swift | 14 +++++++-- 7 files changed, 52 insertions(+), 16 deletions(-) diff --git a/iOS/Layover/Layover/Scenes/Playback/Cell/PlaybackCell.swift b/iOS/Layover/Layover/Scenes/Playback/Cell/PlaybackCell.swift index cc783f8..1cf73a8 100644 --- a/iOS/Layover/Layover/Scenes/Playback/Cell/PlaybackCell.swift +++ b/iOS/Layover/Layover/Scenes/Playback/Cell/PlaybackCell.swift @@ -16,7 +16,7 @@ final class PlaybackCell: UICollectionViewCell { weak var delegate: PlaybackViewControllerDelegate? - private var memberID: Int? + private (set) var memberID: Int? let playbackView: PlaybackView = PlaybackView() diff --git a/iOS/Layover/Layover/Scenes/Playback/PlaybackInteractor.swift b/iOS/Layover/Layover/Scenes/Playback/PlaybackInteractor.swift index 4ebe050..0a7966b 100644 --- a/iOS/Layover/Layover/Scenes/Playback/PlaybackInteractor.swift +++ b/iOS/Layover/Layover/Scenes/Playback/PlaybackInteractor.swift @@ -225,8 +225,11 @@ final class PlaybackInteractor: PlaybackBusinessLogic, PlaybackDataStore { } func setSeeMoreButton() { - guard let parentView else { return } - let response: Models.SetSeemoreButton.Response = Models.SetSeemoreButton.Response(parentView: parentView) + guard let worker, + let currentCellMemberID: Int = previousCell?.memberID + else { return } + let buttonType: Models.SetSeemoreButton.ButtonType = worker.isMyVideo(currentCellMemberID: currentCellMemberID) ? .delete : .report + let response: Models.SetSeemoreButton.Response = Models.SetSeemoreButton.Response(buttonType: buttonType) presenter?.presentSetSeemoreButton(with: response) } diff --git a/iOS/Layover/Layover/Scenes/Playback/PlaybackModels.swift b/iOS/Layover/Layover/Scenes/Playback/PlaybackModels.swift index 905d63b..9c7c69f 100644 --- a/iOS/Layover/Layover/Scenes/Playback/PlaybackModels.swift +++ b/iOS/Layover/Layover/Scenes/Playback/PlaybackModels.swift @@ -179,7 +179,7 @@ enum PlaybackModels { } struct Response { - let parentView: ParentView + let buttonType: ButtonType } struct ViewModel { diff --git a/iOS/Layover/Layover/Scenes/Playback/PlaybackPresenter.swift b/iOS/Layover/Layover/Scenes/Playback/PlaybackPresenter.swift index 5bfafa8..72db79b 100644 --- a/iOS/Layover/Layover/Scenes/Playback/PlaybackPresenter.swift +++ b/iOS/Layover/Layover/Scenes/Playback/PlaybackPresenter.swift @@ -112,8 +112,7 @@ final class PlaybackPresenter: PlaybackPresentationLogic { } func presentSetSeemoreButton(with response: PlaybackModels.SetSeemoreButton.Response) { - let buttonType: Models.SetSeemoreButton.ButtonType = response.parentView == .myProfile ? .delete : .report - viewController?.setSeemoreButton(viewModel: Models.SetSeemoreButton.ViewModel(buttonType: buttonType)) + viewController?.setSeemoreButton(viewModel: Models.SetSeemoreButton.ViewModel(buttonType: response.buttonType)) } func presentDeleteVideo(with response: PlaybackModels.DeletePlaybackVideo.Response) { diff --git a/iOS/Layover/Layover/Scenes/Playback/PlaybackViewController.swift b/iOS/Layover/Layover/Scenes/Playback/PlaybackViewController.swift index 86598ff..afd2217 100644 --- a/iOS/Layover/Layover/Scenes/Playback/PlaybackViewController.swift +++ b/iOS/Layover/Layover/Scenes/Playback/PlaybackViewController.swift @@ -138,11 +138,17 @@ final class PlaybackViewController: BaseViewController { override func setUI() { super.setUI() - interactor?.setSeeMoreButton() + setSeeMoreButton() self.navigationController?.navigationBar.tintColor = .layoverWhite } - @objc private func reportButtonDidTap() { + private func setSeeMoreButton() { + guard let button = seemoreButton.customView as? UIButton else { return } + button.addTarget(self, action: #selector(seeMoreButtonDidTap), for: .touchUpInside) + self.navigationItem.rightBarButtonItem = seemoreButton + } + + private func reportButtonDidTap() { let alert: UIAlertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) let reportAction: UIAlertAction = UIAlertAction(title: "신고", style: .destructive, handler: { [weak self] _ in @@ -159,7 +165,7 @@ final class PlaybackViewController: BaseViewController { }) } - @objc private func deleteButtonDidTap() { + private func deleteButtonDidTap() { let visibleIndexPaths = playbackCollectionView.indexPathsForVisibleItems if visibleIndexPaths.count > 1 { return } guard let currentItemIndex = visibleIndexPaths.first else { return } @@ -180,6 +186,10 @@ final class PlaybackViewController: BaseViewController { self.interactor?.leavePlaybackView() }) } + + @objc private func seeMoreButtonDidTap() { + interactor?.setSeeMoreButton() + } } extension PlaybackViewController: PlaybackDisplayLogic { @@ -277,14 +287,20 @@ extension PlaybackViewController: PlaybackDisplayLogic { } func setSeemoreButton(viewModel: Models.SetSeemoreButton.ViewModel) { - guard let button = seemoreButton.customView as? UIButton else { return } +// guard let button = seemoreButton.customView as? UIButton else { return } +// switch viewModel.buttonType { +// case .delete: +// button.addTarget(self, action: #selector(deleteButtonDidTap), for: .touchUpInside) +// case .report: +// button.addTarget(self, action: #selector(reportButtonDidTap), for: .touchUpInside) +// } +// self.navigationItem.rightBarButtonItem = seemoreButton switch viewModel.buttonType { case .delete: - button.addTarget(self, action: #selector(deleteButtonDidTap), for: .touchUpInside) + deleteButtonDidTap() case .report: - button.addTarget(self, action: #selector(reportButtonDidTap), for: .touchUpInside) + reportButtonDidTap() } - self.navigationItem.rightBarButtonItem = seemoreButton } func deleteVideo(viewModel: PlaybackModels.DeletePlaybackVideo.ViewModel) { diff --git a/iOS/Layover/Layover/Scenes/Playback/PlaybackWorker.swift b/iOS/Layover/Layover/Scenes/Playback/PlaybackWorker.swift index da91dba..f8423a1 100644 --- a/iOS/Layover/Layover/Scenes/Playback/PlaybackWorker.swift +++ b/iOS/Layover/Layover/Scenes/Playback/PlaybackWorker.swift @@ -19,6 +19,7 @@ protocol PlaybackWorkerProtocol { func fetchHomePosts() async -> [Post]? func fetchProfilePosts(profileID: Int?, page: Int) async -> [Post]? func fetchTagPosts(selectedTag: String, page: Int) async -> [Post]? + func isMyVideo(currentCellMemberID: Int) -> Bool } final class PlaybackWorker: PlaybackWorkerProtocol { @@ -28,17 +29,19 @@ final class PlaybackWorker: PlaybackWorkerProtocol { typealias Models = PlaybackModels private let provider: ProviderType + private let authManager: AuthManagerProtocol private let defaultPostManagerEndPointFactory: PostManagerEndPointFactory private let defaultPostEndPointFactory: PostEndPointFactory private let defaultUserEndPointFactory: UserEndPointFactory // MARK: - Methods - init(provider: ProviderType = Provider(), defaultPostManagerEndPointFactory: PostManagerEndPointFactory = DefaultPostManagerEndPointFactory(), defaultPostEndPointFactory: PostEndPointFactory = DefaultPostEndPointFactory(), defaultUserEndPointFactory: UserEndPointFactory = DefaultUserEndPointFactory()) { + init(provider: ProviderType = Provider(), authManager: AuthManagerProtocol = AuthManager.shared, defaultPostManagerEndPointFactory: PostManagerEndPointFactory = DefaultPostManagerEndPointFactory(), defaultPostEndPointFactory: PostEndPointFactory = DefaultPostEndPointFactory(), defaultUserEndPointFactory: UserEndPointFactory = DefaultUserEndPointFactory()) { self.provider = provider self.defaultPostManagerEndPointFactory = defaultPostManagerEndPointFactory self.defaultPostEndPointFactory = defaultPostEndPointFactory self.defaultUserEndPointFactory = defaultUserEndPointFactory + self.authManager = authManager } func makeInfiniteScroll(posts: [Post]) -> [Post] { @@ -118,4 +121,9 @@ final class PlaybackWorker: PlaybackWorkerProtocol { return nil } } + + func isMyVideo(currentCellMemberID: Int) -> Bool { + let myMemberID = authManager.memberID + return currentCellMemberID == myMemberID + } } diff --git a/iOS/Layover/Layover/Workers/Mocks/MockPlaybackWorker.swift b/iOS/Layover/Layover/Workers/Mocks/MockPlaybackWorker.swift index ca84a80..3fda9a4 100644 --- a/iOS/Layover/Layover/Workers/Mocks/MockPlaybackWorker.swift +++ b/iOS/Layover/Layover/Workers/Mocks/MockPlaybackWorker.swift @@ -17,13 +17,19 @@ final class MockPlaybackWorker: PlaybackWorkerProtocol { typealias Models = PlaybackModels private let provider: ProviderType + private let authManager: AuthManagerProtocol // MARK: - Methods - init(provider: ProviderType = Provider(session: .initMockSession())) { +// init(provider: ProviderType = Provider(session: .initMockSession())) { +// self.provider = provider +// } + + init(provider: ProviderType = Provider(session: .initMockSession()), authManager: AuthManagerProtocol = StubAuthManager()) { self.provider = provider + self.authManager = authManager } - + func makeInfiniteScroll(posts: [Post]) -> [Post] { guard let tempLastVideo: Post = posts.last, let tempFirstVideo: Post = posts.first @@ -176,4 +182,8 @@ final class MockPlaybackWorker: PlaybackWorkerProtocol { } } + func isMyVideo(currentCellMemberID: Int) -> Bool { + return currentCellMemberID == authManager.memberID + } + }