Skip to content

Commit

Permalink
Merge pull request #359 from OMZigak/fix/#352-jihoonQaSolve
Browse files Browse the repository at this point in the history
[Fix] QA 반영
  • Loading branch information
hooni0918 authored Sep 4, 2024
2 parents a469d23 + a50ee78 commit 084491e
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 107 deletions.
20 changes: 20 additions & 0 deletions KkuMulKum/Resource/Extension/UIButton+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,24 @@ extension UIButton {
)
setAttributedTitle(attributedString, for: .normal)
}

func addUnderlineWithMyPage(
textColor: UIColor,
underlineColor: UIColor = .gray2,
spacing: CGFloat = 12
) {
let font = UIFont.pretendard(.body05)
let underlineStyle = NSUnderlineStyle.single

let attributes: [NSAttributedString.Key: Any] = [
.font: font,
.foregroundColor: textColor,
.underlineStyle: underlineStyle.rawValue,
.underlineColor: underlineColor,
.baselineOffset: spacing / 2
]

let attributedString = NSMutableAttributedString(string: self.titleLabel?.text ?? "", attributes: attributes)
setAttributedTitle(attributedString, for: .normal)
}
}
2 changes: 2 additions & 0 deletions KkuMulKum/Resource/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPhotoLibraryUsageDescription</key>
<string>꾸물꿈은 카메라 권한을 필요로 합니다. 카메라를 통해 자신의 프로필을 즉시 찍어 업로드할 수 있습니다. 허용 안함 시 일부 기능이 동작하지 않을 수 있습니다.</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
Expand Down
4 changes: 2 additions & 2 deletions KkuMulKum/Source/MyPage/View/MyPageEditView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class MyPageEditView: BaseView {
}

let skipButton = UIButton().then {
$0.setTitle("기본 프로필로 설정", style: .body03, color: .gray5)
$0.addUnderline()
$0.setTitle("기본 프로필로 설정", style: .body05, color: .gray5)
$0.addUnderlineWithMyPage(textColor: .gray5, underlineColor: .gray2)
}

let confirmButton = UIButton().then {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,10 @@ class MyPageViewController: BaseViewController, CustomActionSheetDelegate {

private func updateUI(with userInfo: LoginUserModel?) {
guard let userInfo = userInfo else { return }
let levelText = viewModel.getLevelText(for: userInfo.level)

rootView.contentView.nameLabel.text = userInfo.name ?? "꾸물리안 님"
rootView.contentView.levelLabel.setText("Lv. \(userInfo.level) 지각대장 꾸물이", style: .body05, color: .white)
rootView.contentView.nameLabel.text = (userInfo.name.map { $0 + "" }) ?? "꾸물리안 님"
rootView.contentView.levelLabel.setText("Lv. \(userInfo.level) \(levelText)", style: .body05, color: .white)
rootView.contentView.levelLabel.setHighlightText("Lv. \(userInfo.level)", style: .body05, color: .lightGreen)

updateProfileImage(with: userInfo.profileImageURL)
Expand Down Expand Up @@ -215,8 +216,10 @@ class MyPageViewController: BaseViewController, CustomActionSheetDelegate {
KingfisherManager.shared.cache.clearDiskCache()
})
.disposed(by: disposeBag)

navigationController?.pushViewController(editProfileViewController, animated: true)

editProfileViewController.hidesBottomBarWhenPushed = true

navigationController?.pushViewController(editProfileViewController, animated: true)
}

private func pushAskViewController() {
Expand Down
15 changes: 15 additions & 0 deletions KkuMulKum/Source/MyPage/ViewModel/MyPageViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ class MyPageViewModel: NSObject {
.asSignal(onErrorJustReturn: ())
}

func getLevelText(for level: Int) -> String {
switch level {
case 1:
return "빼꼼 꾸물이"
case 2:
return "망기적 꾸물이"
case 3:
return "기적 꾸물이"
case 4:
return "꾸물꿈"
default:
return "꾸물리안 님"
}
}

func fetchUserInfo() {
Task {
do {
Expand Down
25 changes: 0 additions & 25 deletions KkuMulKum/Source/Onboarding/Login/VIewModel/LoginViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -269,31 +269,6 @@ class LoginViewModel: NSObject {
print("Failed to save tokens")
}
}

// TODO: 자동로그인 구현 후 삭제예정
func fetchValueFromPrivacyInfo(forKey key: String) -> String? {
guard let path = Bundle.main.path(forResource: "PrivacyInfo", ofType: "plist"),
let dict = NSDictionary(contentsOfFile: path) as? [String: AnyObject],
let value = dict[key] as? String else {
return nil
}
return value
}

// TODO: 자동로그인 구현 후 삭제예정
func performTestLogin() {
guard let testAccessToken = fetchValueFromPrivacyInfo(forKey: "TEST_ACCESS_TOKEN") else {
print("Failed to retrieve test access token")
error.value = "Test access token not found"
return
}

saveTokens(accessToken: testAccessToken, refreshToken: "")
userName.value = ""
loginState.value = .login
}


}

extension LoginViewModel: ASAuthorizationControllerDelegate, ASAuthorizationControllerPresentationContextProviding {
Expand Down
18 changes: 1 addition & 17 deletions KkuMulKum/Source/Onboarding/Login/View/LoginView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,8 @@ class LoginView: BaseView {
$0.isUserInteractionEnabled = true
}

// TODO: 자동로그인 구현 후 삭제예정
let testLoginButton = UIButton().then {
$0.setTitle("Test Login", for: .normal)
$0.setTitleColor(.white, for: .normal)
$0.backgroundColor = .systemBlue
$0.layer.cornerRadius = 10
}

override func setupView() {
addSubviews(backgroundImageView, appleLoginImageView, kakaoLoginImageView, testLoginButton)
addSubviews(backgroundImageView, appleLoginImageView, kakaoLoginImageView)
}

override func setupAutoLayout() {
Expand All @@ -59,13 +51,5 @@ class LoginView: BaseView {
$0.horizontalEdges.equalToSuperview().inset(14)
$0.height.equalTo(Screen.height(54))
}

// TODO: 자동로그인 구현 후 삭제예정
testLoginButton.snp.makeConstraints {
$0.centerX.equalToSuperview()
$0.top.equalTo(appleLoginImageView.snp.bottom).offset(20)
$0.width.equalTo(200)
$0.height.equalTo(50)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,9 @@ class LoginViewController: BaseViewController {
action: #selector(kakaoLoginTapped)
)
loginView.kakaoLoginImageView.addGestureRecognizer(kakaoTapGesture)

// TODO: 자동로그인 구현 후 삭제예정
loginView.testLoginButton.addTarget(self, action: #selector(testLoginTapped), for: .touchUpInside)

}

private func bindViewModel() {
// loginViewModel.loginState.bind(with: self) { owner, state in
//
// Task {
// switch state {
// case .notLogin:
// print("Login State: Not logged in")
// case .login:
// print("Login State: Logged in")
// await owner.navigateToOnboardingScreen()
// case .needOnboarding:
// print("Login State: Need onboarding")
// await owner.navigateToOnboardingScreen()
// }
// }
// }

loginViewModel.userName.bind(with: self) { owner, name in
Task {
if name != nil {
Expand Down Expand Up @@ -139,8 +119,4 @@ class LoginViewController: BaseViewController {
present(alert, animated: true)
}
}

@objc private func testLoginTapped() {
loginViewModel.performTestLogin()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import RxSwift
import RxCocoa

class NicknameViewController: BaseViewController {

private let nicknameView = NicknameView()
private let viewModel: NicknameViewModel
private let disposeBag = DisposeBag()
Expand All @@ -35,6 +35,8 @@ class NicknameViewController: BaseViewController {
setupTextField()
setupTapGesture()
setupNavigationBarTitle(with: "닉네임 설정")
navigationItem.leftBarButtonItem = nil

}

private func setupBindings() {
Expand Down Expand Up @@ -136,6 +138,7 @@ class NicknameViewController: BaseViewController {
.disposed(by: disposeBag)
view.addGestureRecognizer(tapGesture)
}

}

extension NicknameViewController: UITextFieldDelegate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import UIKit

import Kingfisher

class ProfileSetupViewModel {
Expand All @@ -17,52 +18,73 @@ class ProfileSetupViewModel {
private let authService: AuthServiceProtocol
private var imageData: Data?
private let maxImageSizeBytes = 4 * 1024 * 1024

init(nickname: String, authService: AuthServiceProtocol = AuthService()) {
self.nickname = nickname
self.authService = authService
}

func updateProfileImage(_ image: UIImage?) {
profileImage.value = image
if let image = image, let data = image.jpegData(compressionQuality: 1.0) {
imageData = data
print("이미지 크기: \(data.count) bytes")
if let image = image {
imageData = compressImage(image)
print("압축된 이미지 크기: \(imageData?.count ?? 0) bytes")
} else {
imageData = nil
}
isConfirmButtonEnabled.value = imageData != nil
clearImageCache()
}

private func compressImage(_ image: UIImage) -> Data? {
var compression: CGFloat = 1.0
var imageData = image.jpegData(compressionQuality: compression)

while (imageData?.count ?? 0) > maxImageSizeBytes && compression > 0.1 {
compression -= 0.1
imageData = image.jpegData(compressionQuality: compression)
}

return imageData
}

func uploadProfileImage() async -> Bool {
print("uploadProfileImage 함수 호출됨")
guard let imageData = imageData else {
print("이미지 데이터가 없습니다.")
serverResponse.value = "이미지 데이터가 없습니다."
return false
}

print("업로드할 이미지 데이터 크기: \(imageData.count) bytes")

let fileName = "profile_image.jpg"
let mimeType = "image/jpeg"

do {
let _: EmptyModel = try await authService.performRequest(
.updateProfileImage(
image: imageData,
fileName: fileName,
mimeType: mimeType
)
)
serverResponse.value = "프로필 이미지가 성공적으로 업로드되었습니다."
print("프로필 이미지 업로드 성공")
return true
} catch {
handleError(error as? NetworkError ?? .unknownError("알 수 없는 오류가 발생했습니다."))
return false
}
}
print("uploadProfileImage 함수 호출됨")
guard let imageData = imageData else {
print("이미지 데이터가 없습니다.")
serverResponse.value = "이미지 데이터가 없습니다."
return false
}

if imageData.count > maxImageSizeBytes {
print("이미지 크기가 최대 허용 크기를 초과합니다.")
serverResponse.value = "이미지 크기가 너무 큽니다. 더 작은 이미지를 선택해주세요."
return false
}

print("업로드할 이미지 데이터 크기: \(imageData.count) bytes")

let fileName = "profile_image.jpg"
let mimeType = "image/jpeg"

do {
let _: EmptyModel = try await authService.performRequest(
.updateProfileImage(
image: imageData,
fileName: fileName,
mimeType: mimeType
)
)
serverResponse.value = "프로필 이미지가 성공적으로 업로드되었습니다."
print("프로필 이미지 업로드 성공")

clearImageCache()
return true
} catch {
handleError(error as? NetworkError ?? .unknownError("알 수 없는 오류가 발생했습니다."))
return false
}
}

private func handleError(_ error: NetworkError) {
switch error {
Expand All @@ -81,4 +103,9 @@ class ProfileSetupViewModel {
}
print("프로필 이미지 업로드 실패: \(error.message)")
}

private func clearImageCache() {
KingfisherManager.shared.cache.clearMemoryCache()
KingfisherManager.shared.cache.clearDiskCache()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ final class SetReadyInfoViewModel {
let moveMinute = ObservablePattern<String>("")
let isSucceedToSave = ObservablePattern<Bool>(false)

let bufferTime: TimeInterval = 10 * 60

var readyTime: Int = 0
var moveTime: Int = 0

Expand Down Expand Up @@ -142,8 +144,8 @@ final class SetReadyInfoViewModel {
print("이동 시간: \(self.moveTime)")
print("총 준비 시간: \(totalPrepTime / 60)")

let readyStartTime = promiseDate.addingTimeInterval(-TimeInterval(self.readyTime + self.moveTime) * 60)
let moveStartTime = promiseDate.addingTimeInterval(-TimeInterval(self.moveTime) * 60)
let readyStartTime = promiseDate.addingTimeInterval(-(totalPrepTime + bufferTime))
let moveStartTime = promiseDate.addingTimeInterval(-(TimeInterval(self.moveTime * 60) + bufferTime))

print("준비 시작 시간: \(timeFormatter.string(from: readyStartTime))")
print("이동 시작 시간: \(timeFormatter.string(from: moveStartTime))")
Expand Down

0 comments on commit 084491e

Please sign in to comment.