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

feat: 지도 탭 업로드 vip 구현 #229

Merged
merged 6 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
6 changes: 5 additions & 1 deletion iOS/Layover/Layover.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
FC68E2A12B023326001AABFF /* EndPoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC68E2A02B023326001AABFF /* EndPoint.swift */; };
FC68E2A32B0233BC001AABFF /* NetworkError.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC68E2A22B0233BC001AABFF /* NetworkError.swift */; };
FC68E2A52B0233D3001AABFF /* Provider.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC68E2A42B0233D3001AABFF /* Provider.swift */; };
FC70BB2B2B20718A00B37CBE /* VideoPickerManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC70BB2A2B20718A00B37CBE /* VideoPickerManager.swift */; };
FC767F842B1214A80088CF9B /* MockUserWorker.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC767F832B1214A70088CF9B /* MockUserWorker.swift */; };
FC767F862B1214C10088CF9B /* CheckUserNameDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC767F852B1214C10088CF9B /* CheckUserNameDTO.swift */; };
FC767F932B1220CC0088CF9B /* NicknameDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC767F922B1220CC0088CF9B /* NicknameDTO.swift */; };
Expand Down Expand Up @@ -351,6 +352,7 @@
FC68E2A02B023326001AABFF /* EndPoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EndPoint.swift; sourceTree = "<group>"; };
FC68E2A22B0233BC001AABFF /* NetworkError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkError.swift; sourceTree = "<group>"; };
FC68E2A42B0233D3001AABFF /* Provider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Provider.swift; sourceTree = "<group>"; };
FC70BB2A2B20718A00B37CBE /* VideoPickerManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoPickerManager.swift; sourceTree = "<group>"; };
FC767F832B1214A70088CF9B /* MockUserWorker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MockUserWorker.swift; sourceTree = "<group>"; };
FC767F852B1214C10088CF9B /* CheckUserNameDTO.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CheckUserNameDTO.swift; sourceTree = "<group>"; };
FC767F922B1220CC0088CF9B /* NicknameDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NicknameDTO.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -672,6 +674,7 @@
FC0E801D2B1A0A4900EF56D6 /* UploadPost */ = {
isa = PBXGroup;
children = (
FC70BB2A2B20718A00B37CBE /* VideoPickerManager.swift */,
FC0E80222B1A0BBB00EF56D6 /* UploadPostViewController.swift */,
FC0E80232B1A0BBB00EF56D6 /* UploadPostInteractor.swift */,
FC0E801E2B1A0BBB00EF56D6 /* UploadPostPresenter.swift */,
Expand Down Expand Up @@ -700,12 +703,12 @@
isa = PBXGroup;
children = (
FC767FA62B1269980088CF9B /* Views */,
FC767FA92B126D080088CF9B /* LOAnnotation.swift */,
FC2511A82B04DAD4004717BC /* MapViewController.swift */,
FC2511AC2B04EACD004717BC /* MapInteractor.swift */,
FC2511AE2B04EAD9004717BC /* MapPresenter.swift */,
FC2511AA2B04EA6B004717BC /* MapConfigurator.swift */,
FC2511B02B04EAEC004717BC /* MapModels.swift */,
FC767FA92B126D080088CF9B /* LOAnnotation.swift */,
836C33902B17629400ECAFB0 /* MapRouter.swift */,
);
path = Map;
Expand Down Expand Up @@ -1176,6 +1179,7 @@
194551F42B037F2D00299768 /* LoginRouter.swift in Sources */,
FC4975992B03439000D8627F /* UIFont+.swift in Sources */,
FC5BE11E2B148D160036366D /* EditProfileRouter.swift in Sources */,
FC70BB2B2B20718A00B37CBE /* VideoPickerManager.swift in Sources */,
FC42E4142B17AB69005D4956 /* VideoFileWorker.swift in Sources */,
FC767F952B1222350088CF9B /* ProfileImageDTO.swift in Sources */,
FC0E803F2B1B91C900EF56D6 /* EditTagInteractor.swift in Sources */,
Expand Down
56 changes: 18 additions & 38 deletions iOS/Layover/Layover/Scenes/Home/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,9 @@ final class HomeViewController: BaseViewController {
var router: (HomeRoutingLogic & HomeDataPassing)?
var interactor: HomeBusinessLogic?

// MARK: - UI Components
private let videoPickerManager: VideoPickerManager = VideoPickerManager()

private lazy var phPickerViewController: PHPickerViewController = {
var configuration = PHPickerConfiguration()
configuration.preferredAssetRepresentationMode = .current
configuration.filter = .videos
configuration.selectionLimit = 1
let phPickerViewController = PHPickerViewController(configuration: configuration)
phPickerViewController.delegate = self
return phPickerViewController
}()
// MARK: - UI Components

private lazy var uploadButton: LOCircleButton = {
let button = LOCircleButton(style: .add, diameter: 52)
Expand Down Expand Up @@ -72,11 +64,13 @@ final class HomeViewController: BaseViewController {
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
setup()
setDelegation()
}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setup()
setDelegation()
}

// MARK: - Setup
Expand Down Expand Up @@ -120,11 +114,15 @@ final class HomeViewController: BaseViewController {
override func setUI() {
super.setUI()
carouselCollectionView.dataSource = carouselDatasource
carouselCollectionView.delegate = self
}

// MARK: - Methods

private func setDelegation() {
carouselCollectionView.delegate = self
videoPickerManager.videoPickerDelegate = self
}

private func createCarouselLayout(groupWidthDimension: CGFloat,
groupHeightDimension: CGFloat,
maximumZoomScale: CGFloat,
Expand Down Expand Up @@ -184,7 +182,7 @@ final class HomeViewController: BaseViewController {
// MARK: - Actions

@objc private func uploadButtonDidTap() {
present(phPickerViewController, animated: true)
present(videoPickerManager.phPickerViewController, animated: true)
}

@objc private func tagButtonDidTap(_ sender: UIButton) {
Expand Down Expand Up @@ -215,34 +213,16 @@ extension HomeViewController: HomeCarouselCollectionViewDelegate {
}
}

// MARK: - PHPickerViewControllerDelegate

extension HomeViewController: PHPickerViewControllerDelegate {
// MARK: - VideoPickerDelegate

func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
guard let result = results.first else {
self.phPickerViewController.dismiss(animated: true)
return
}

_ = result.itemProvider.loadFileRepresentation(forTypeIdentifier: UTType.movie.identifier) { url, error in

if error != nil {
Task {
await MainActor.run {
Toast.shared.showToast(message: "지원하지 않는 동영상 형식입니다 T.T")
}
}
}
extension HomeViewController: VideoPickerDelegate {

if let url {
self.interactor?.selectVideo(with: HomeModels.SelectVideo.Request(videoURL: url))
Task {
await MainActor.run {
self.router?.routeToEditVideo()
self.phPickerViewController.dismiss(animated: true)
}
}
func didFinishPickingVideo(_ url: URL) {
self.interactor?.selectVideo(with: HomeModels.SelectVideo.Request(videoURL: url))
Task {
await MainActor.run {
self.router?.routeToEditVideo()
self.videoPickerManager.phPickerViewController.dismiss(animated: true)
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions iOS/Layover/Layover/Scenes/Map/MapConfigurator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ final class MapConfigurator: Configurator {
let interactor = MapInteractor()
let presenter = MapPresenter()
let router = MapRouter()
let videoFileWorker = VideoFileWorker()

router.viewController = viewController
viewController.interactor = interactor
interactor.presenter = presenter
interactor.videoFileWorker = videoFileWorker
presenter.viewController = viewController
viewController.router = router
router.dataStore = interactor
Expand Down
19 changes: 11 additions & 8 deletions iOS/Layover/Layover/Scenes/Map/MapInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,32 @@ protocol MapBusinessLogic {
func fetchVideos()
func moveToPlaybackScene(with: MapModels.MoveToPlaybackScene.Request)
func playPosts(with: MapModels.PlayPosts.Request)
func selectVideo(with request: MapModels.SelectVideo.Request)
}

protocol MapDataStore {
var postPlayStartIndex: Int? { get set }
var posts: [Post]? { get set }
var index: Int? { get set }
var selectedVideoURL: URL? { get set }
}

final class MapInteractor: NSObject, MapBusinessLogic, MapDataStore {

// MARK: - Properties

typealias Models = MapModels
var presenter: MapPresentationLogic?
var videoFileWorker: VideoFileWorker?

private let locationManager = CLLocationManager()

private var latitude: Double?

private var longitude: Double?

var index: Int?

var posts: [Post]?

var postPlayStartIndex: Int?

var presenter: MapPresentationLogic?
var posts: [Post]?
var index: Int?
var selectedVideoURL: URL?

override init() {
super.init()
Expand Down Expand Up @@ -74,6 +73,10 @@ final class MapInteractor: NSObject, MapBusinessLogic, MapDataStore {
presenter?.presentPlaybackScene()
}

func selectVideo(with request: Models.SelectVideo.Request) {
selectedVideoURL = videoFileWorker?.copyToNewURL(at: request.videoURL)
}

private func checkCurrentLocationAuthorization(for status: CLAuthorizationStatus) {
switch status {
case .authorizedAlways, .authorizedWhenInUse:
Expand Down
14 changes: 14 additions & 0 deletions iOS/Layover/Layover/Scenes/Map/MapModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,18 @@ enum MapModels {
struct ViewModel {
}
}

enum SelectVideo {
struct Request {
let videoURL: URL
}

struct Response {

}

struct ViewModel {

}
}
}
14 changes: 14 additions & 0 deletions iOS/Layover/Layover/Scenes/Map/MapRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Foundation

protocol MapRoutingLogic {
func routeToPlayback()
func routeToEditVideo()
}

protocol MapDataPassing {
Expand All @@ -35,4 +36,17 @@ final class MapRouter: MapRoutingLogic, MapDataPassing {
destination.posts = source.posts
viewController?.navigationController?.pushViewController(playbackViewController, animated: true)
}

func routeToEditVideo() {
let nextViewController = EditVideoViewController()
guard let source = dataStore,
var destination = nextViewController.router?.dataStore,
let videoURL = source.selectedVideoURL
else { return }

// Data Passing
destination.videoURL = videoURL
nextViewController.hidesBottomBarWhenPushed = true
viewController?.navigationController?.pushViewController(nextViewController, animated: true)
}
}
38 changes: 36 additions & 2 deletions iOS/Layover/Layover/Scenes/Map/MapViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ final class MapViewController: BaseViewController {
return button
}()

private let uploadButton: LOCircleButton = LOCircleButton(style: .add, diameter: 52)
private lazy var uploadButton: LOCircleButton = {
let button = LOCircleButton(style: .add, diameter: 52)
button.addTarget(self, action: #selector(uploadButtonDidTap), for: .touchUpInside)
return button
}()

private lazy var carouselCollectionView: UICollectionView = {
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: createLayout())
Expand All @@ -72,6 +76,7 @@ final class MapViewController: BaseViewController {
var interactor: MapBusinessLogic?
var router: (MapRoutingLogic & MapDataPassing)?

private let videoPickerManager: VideoPickerManager = VideoPickerManager()
private lazy var carouselCollectionViewHeight: NSLayoutConstraint = carouselCollectionView.heightAnchor.constraint(equalToConstant: 0)

// MARK: - Life Cycle
Expand All @@ -90,8 +95,8 @@ final class MapViewController: BaseViewController {
super.viewDidLoad()
interactor?.checkLocationAuthorizationStatus()
setCollectionViewDataSource()
setDelegation()
createMapAnnotation()
carouselCollectionView.delegate = self
}

// MARK: - UI + Layout
Expand Down Expand Up @@ -131,6 +136,11 @@ final class MapViewController: BaseViewController {

// MARK: - Methods

private func setDelegation() {
carouselCollectionView.delegate = self
videoPickerManager.videoPickerDelegate = self
}

private func createLayout() -> UICollectionViewLayout {
let groupWidthDimension: CGFloat = 94/375
let minumumZoomScale: CGFloat = 73/94
Expand Down Expand Up @@ -185,8 +195,14 @@ final class MapViewController: BaseViewController {
mapView.setUserTrackingMode(.follow, animated: true)
}

@objc private func uploadButtonDidTap() {
present(videoPickerManager.phPickerViewController, animated: true)
}

}

// MARK: - MKMapViewDelegate

extension MapViewController: MKMapViewDelegate {

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
Expand All @@ -211,6 +227,24 @@ extension MapViewController: MKMapViewDelegate {

}

// MARK: - VideoPickerDelegate

extension MapViewController: VideoPickerDelegate {

func didFinishPickingVideo(_ url: URL) {
self.interactor?.selectVideo(with: Models.SelectVideo.Request(videoURL: url))
Task {
await MainActor.run {
self.router?.routeToEditVideo()
self.videoPickerManager.phPickerViewController.dismiss(animated: true)
Copy link
Collaborator

@loinsir loinsir Dec 6, 2023

Choose a reason for hiding this comment

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

이거 화면 전환 먼저하고 dismiss 하는 부분 dismiss completion으로 처리안해도 안꼬이나요?

Copy link
Member Author

Choose a reason for hiding this comment

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

문제는 없는데 로직상 dissmiss하고 라우팅하는게 나을 것 같아서 순서 바꿔두겠습니당!

}
}
}

}

// MARK: - MapDisplayLogic

extension MapViewController: MapDisplayLogic {

func displayFetchedVideos(viewModel: ViewModel) {
Expand Down
Loading