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

[Fix] QA 반영 #359

Merged
merged 8 commits into from
Sep 4, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Release"
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
Expand All @@ -49,6 +49,13 @@
ReferencedContainer = "container:KkuMulKum.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<EnvironmentVariables>
<EnvironmentVariable
key = "IDEPreferLogStreaming"
value = "YES"
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
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)
}
Comment on lines +32 to +50
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

}
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.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 @@ -260,31 +260,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

Copy link
Member

Choose a reason for hiding this comment

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

여기 빈 줄 삭제 부탁드려요!

}

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

Copy link
Member

Choose a reason for hiding this comment

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

빈 줄 삭제!

}

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 함수 호출됨")
Comment on lines -65 to +52
Copy link
Contributor

Choose a reason for hiding this comment

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

이 정도의 print문은 삭제해도 좋을 것 같습니다.

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("프로필 이미지 업로드 성공")

Comment on lines +79 to +80
Copy link
Contributor

Choose a reason for hiding this comment

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

성공했을 때의 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()
}
}