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: 업로드 안되는 버그 및 업로드 화면 개선 #272

Merged
merged 6 commits into from
Dec 10, 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
1 change: 1 addition & 0 deletions iOS/Layover/Layover/Extensions/Notification.Name+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ extension Notification.Name {
static let uploadTaskStart = Notification.Name("uploadTaskStart")
static let progressChanged = Notification.Name("progressChanged")
static let uploadTaskDidComplete = Notification.Name("uploadTaskDidComplete")
static let uploadTaskDidFail = Notification.Name("uploadTaskDidFail")
}
21 changes: 12 additions & 9 deletions iOS/Layover/Layover/Network/Provider/Provider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
//

import Foundation
import UniformTypeIdentifiers

import OSLog

protocol ProviderType {
Expand Down Expand Up @@ -40,15 +42,15 @@ extension ProviderType {
}

func upload(fromFile: URL,
to url: String,
method: HTTPMethod = .PUT,
sessionTaskDelegate: URLSessionTaskDelegate? = nil,
delegateQueue: OperationQueue? = nil) async throws -> Data {
to url: String,
method: HTTPMethod = .PUT,
sessionTaskDelegate: URLSessionTaskDelegate? = nil,
delegateQueue: OperationQueue? = nil) async throws -> Data {
return try await upload(fromFile: fromFile,
to: url,
method: method,
sessionTaskDelegate: sessionTaskDelegate,
delegateQueue: delegateQueue)
to: url,
method: method,
sessionTaskDelegate: sessionTaskDelegate,
delegateQueue: delegateQueue)
}

}
Expand Down Expand Up @@ -159,9 +161,10 @@ class Provider: ProviderType {
sessionTaskDelegate: URLSessionTaskDelegate? = nil,
delegateQueue: OperationQueue? = nil) async throws -> Data {
guard let url = URL(string: url) else { throw NetworkError.components }
guard let mimeType = UTType(filenameExtension: fromFile.pathExtension)?.preferredMIMEType else { throw NetworkError.unknown }
Copy link
Collaborator

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.

이거 프로필 사진 업로드에도 사용해야겠어요. 감사합니다.

var request = URLRequest(url: url, cachePolicy: .reloadIgnoringLocalCacheData)
request.httpMethod = method.rawValue
request.setValue("video/\(fromFile.pathExtension)", forHTTPHeaderField: "Content-Type")
request.setValue(mimeType, forHTTPHeaderField: "Content-Type")
let (data, response) = try await session.upload(for: request,
fromFile: fromFile,
delegate: sessionTaskDelegate)
Expand Down
31 changes: 16 additions & 15 deletions iOS/Layover/Layover/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,14 @@ extension SceneDelegate {
self?.showProgressView()
}
NotificationCenter.default.addObserver(forName: .progressChanged, object: nil, queue: .main) { [weak self] notification in
self?.progressChanged(notification)
guard let progress = notification.userInfo?["progress"] as? Float else { return }
self?.progressView.setProgress(progress, animated: true)
}
NotificationCenter.default.addObserver(forName: .uploadTaskDidComplete, object: nil, queue: .main) { [weak self] _ in
self?.removeProgressView()
self?.removeProgressView(message: "업로드가 완료되었습니다 ✨")
}
NotificationCenter.default.addObserver(forName: .uploadTaskDidFail, object: nil, queue: .main) { [weak self] _ in
self?.removeProgressView(message: "업로드에 실패했습니다 💦")
}
}

Expand All @@ -93,14 +97,17 @@ extension SceneDelegate {
name: .refreshTokenDidExpired,
object: nil)
NotificationCenter.default.removeObserver(self,
name: .refreshTokenDidExpired,
name: .uploadTaskStart,
object: nil)
NotificationCenter.default.removeObserver(self,
name: .progressChanged,
object: nil)
NotificationCenter.default.removeObserver(self,
name: .uploadTaskDidComplete,
object: nil)
NotificationCenter.default.removeObserver(self,
name: .uploadTaskDidFail,
object: nil)
}

@objc private func routeToLoginViewController() {
Expand All @@ -113,8 +120,10 @@ extension SceneDelegate {
private func showProgressView() {
guard let progressViewWidth = window?.screen.bounds.width,
let windowHeight = window?.screen.bounds.height,
let tabBarViewController = window?.rootViewController as? UITabBarController else { return }
let tabBarHeight: CGFloat = tabBarViewController.tabBar.frame.height
let navigationController = window?.rootViewController as? UINavigationController,
let tabBarController = navigationController.topViewController as? UITabBarController
else { return }
let tabBarHeight: CGFloat = tabBarController.tabBar.frame.height
progressView.progress = 0
progressView.tintColor = .primaryPurple
progressView.frame = CGRect(x: 0,
Expand All @@ -124,17 +133,9 @@ extension SceneDelegate {
window?.addSubview(progressView)
}


private func progressChanged(_ notification: Notification) {
guard let progress = notification.userInfo?["progress"] as? Float else { return }
progressView.setProgress(progress, animated: true)
if progress == 1 {
Toast.shared.showToast(message: "업로드가 완료되었습니다 ✨")
}
}

private func removeProgressView() {
private func removeProgressView(message: String) {
progressView.removeFromSuperview()
Toast.shared.showToast(message: message)
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ final class EditVideoInteractor: EditVideoBusinessLogic, EditVideoDataStore {

func fetchVideo(request: EditVideoModels.FetchVideo.Request) {
let isEdited = request.editedVideoURL != nil
guard let videoURL = isEdited ? request.editedVideoURL : videoURL else { return }
if let editedVideoURL = request.editedVideoURL {
videoURL = editedVideoURL
}

guard let videoURL else { return }
Task {
let duration = try await AVAsset(url: videoURL).load(.duration)
let seconds = CMTimeGetSeconds(duration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ final class EditVideoViewController: BaseViewController {
}

@objc private func cutButtonDidTap() {
loopingPlayerView.player?.pause()
guard let videoPath = originalVideoURL?.path() else { return }
if UIVideoEditorController.canEditVideo(atPath: videoPath) {
let editController = UIVideoEditorController()
Expand All @@ -139,7 +140,24 @@ extension EditVideoViewController: UINavigationControllerDelegate, UIVideoEditor
func videoEditorController(_ editor: UIVideoEditorController, didSaveEditedVideoToPath editedVideoPath: String) {
let editedVideoURL = NSURL(fileURLWithPath: editedVideoPath) as URL
interactor?.fetchVideo(request: EditVideoModels.FetchVideo.Request(editedVideoURL: editedVideoURL))
dismiss(animated: true)
editor.dismiss(animated: true) { [weak self] in
guard let self else { return }
self.loopingPlayerView.play()
}
}

func videoEditorControllerDidCancel(_ editor: UIVideoEditorController) {
editor.dismiss(animated: true) { [weak self] in
guard let self else { return }
self.loopingPlayerView.play()
}
}

func videoEditorController(_ editor: UIVideoEditorController, didFailWithError error: Error) {
editor.dismiss(animated: true) { [weak self] in
guard let self else { return }
self.loopingPlayerView.play()
}
}

}
Expand All @@ -155,7 +173,12 @@ extension EditVideoViewController: EditVideoDisplayLogic {
loopStart: .zero,
duration: viewModel.duration)
loopingPlayerView.play()
loopingPlayerView.player?.isMuted = soundButton.isSelected
Copy link
Collaborator

Choose a reason for hiding this comment

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

오...

nextButton.isEnabled = viewModel.canNext

if !viewModel.canNext {
Toast.shared.showToast(message: "3초 ~ 60초의 영상만 올릴 수 있어요 👀")
}
}

}
15 changes: 10 additions & 5 deletions iOS/Layover/Layover/Scenes/UIComponents/Toast.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,27 @@ final class Toast {
let windowScene: UIWindowScene? = scenes.first as? UIWindowScene
guard let window: UIWindow = windowScene?.windows.first else { return }
let toastLabel: ToastLabel = ToastLabel()
toastLabel.backgroundColor = .background
toastLabel.alpha = 0
toastLabel.backgroundColor = .background.withAlphaComponent(0.8)
toastLabel.textColor = .layoverWhite
toastLabel.textAlignment = .center
toastLabel.font = .loFont(type: .body2)
toastLabel.text = message
toastLabel.layer.cornerRadius = 8
toastLabel.clipsToBounds = true
toastLabel.numberOfLines = 1
toastLabel.layer.opacity = 0.8
toastLabel.frame.size = toastLabel.intrinsicContentSize
window.addSubview(toastLabel)
toastLabel.center = window.center
UIView.animate(withDuration: 2.0, delay: 0.1, options: .curveEaseOut, animations: {
toastLabel.alpha = 0.0

UIView.animate(withDuration: 0.3, delay: 0.5, options: .curveEaseOut, animations: {
toastLabel.alpha = 1.0
}, completion: { _ in
toastLabel.removeFromSuperview()
UIView.animate(withDuration: 1.0, delay: 1.0, options: .curveEaseOut, animations: {
toastLabel.alpha = 0.0
}, completion: { _ in
toastLabel.removeFromSuperview()
})
Comment on lines +56 to +63
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ final class UploadPostWorker: NSObject, UploadPostWorkerProtocol {
return true
} catch {
os_log(.error, log: .data, "Failed to upload Video: %@", error.localizedDescription)
NotificationCenter.default.post(name: .uploadTaskDidComplete, object: nil)
NotificationCenter.default.post(name: .uploadTaskDidFail, object: nil)
return false
}
}
Expand Down