Skip to content

Commit

Permalink
Merge pull request #395 from OMZigak/fix/#394-qaSolveJihoon
Browse files Browse the repository at this point in the history
[Fix] 최종 QA 반영
  • Loading branch information
hooni0918 authored Sep 23, 2024
2 parents 7776f5e + 9897c03 commit 33adacc
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 112 deletions.
4 changes: 2 additions & 2 deletions KkuMulKum.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2225,7 +2225,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0;
MARKETING_VERSION = 1.0.1;
PRODUCT_BUNDLE_IDENTIFIER = KkuMulKum.yizihn;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -2267,7 +2267,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0;
MARKETING_VERSION = 1.0.1;
ONLY_ACTIVE_ARCH = NO;
PRODUCT_BUNDLE_IDENTIFIER = KkuMulKum.yizihn;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
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>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>CFBundleURLTypes</key>
<array>
<dict>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MyPageEditViewController: BaseViewController {
private let rootView = MyPageEditView()
private let viewModel: MyPageEditViewModel
private let disposeBag = DisposeBag()
private let newProfileImageSubject = PublishSubject<UIImage?>()
private var selectedImage: UIImage?
let profileImageUpdated = PublishSubject<String?>()

init(viewModel: MyPageEditViewModel) {
Expand Down Expand Up @@ -54,39 +54,25 @@ class MyPageEditViewController: BaseViewController {

rootView.confirmButton.rx.tap
.subscribe(onNext: { [weak self] in
self?.navigationController?.popViewController(animated: true)
self?.handleConfirmButtonTap()
})
.disposed(by: disposeBag)

rootView.skipButton.rx.tap
.subscribe(onNext: { [weak self] in
self?.newProfileImageSubject.onNext(UIImage.imgProfile)
self?.navigationController?.popViewController(animated: true)
self?.handleSkipButtonTap()
})
.disposed(by: disposeBag)
}

private func setupBindings() {
let input = MyPageEditViewModel.Input(
profileImageTap: rootView.cameraButton.rx.tap.asObservable(),
confirmButtonTap: rootView.confirmButton.rx.tap.asObservable(),
skipButtonTap: rootView.skipButton.rx.tap.asObservable(),
newProfileImage: newProfileImageSubject.asObservable()
skipButtonTap: rootView.skipButton.rx.tap.asObservable()
)

input.newProfileImage
.compactMap { $0 }
.subscribe(onNext: { [weak self] image in
self?.viewModel.updateProfileImage(image)
})
.disposed(by: disposeBag)

let output = viewModel.transform(input: input, disposeBag: disposeBag)

output.profileImage
.drive(rootView.profileImageView.rx.image)
.disposed(by: disposeBag)

output.isConfirmButtonEnabled
.drive(rootView.confirmButton.rx.isEnabled)
.disposed(by: disposeBag)
Expand Down Expand Up @@ -130,6 +116,18 @@ class MyPageEditViewController: BaseViewController {
imagePicker.allowsEditing = true
present(imagePicker, animated: true)
}

private func handleConfirmButtonTap() {
if let selectedImage = selectedImage {
viewModel.updateProfileImage(selectedImage)
}
navigationController?.popViewController(animated: true)
}

private func handleSkipButtonTap() {
viewModel.setDefaultProfileImage()
navigationController?.popViewController(animated: true)
}
}

extension MyPageEditViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
Expand All @@ -139,7 +137,9 @@ extension MyPageEditViewController: UIImagePickerControllerDelegate, UINavigatio
) {
if let editedImage = info[.editedImage] as? UIImage ?? info[.originalImage] as? UIImage {
let croppedImage = cropToCircle(image: editedImage)
newProfileImageSubject.onNext(croppedImage)
selectedImage = croppedImage
rootView.profileImageView.image = croppedImage
rootView.confirmButton.isEnabled = true
}
dismiss(animated: true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ class MyPageViewController: BaseViewController, CustomActionSheetDelegate {
})
.disposed(by: disposeBag)


viewModel.userInfo
.observe(on: MainScheduler.instance)
.subscribe(onNext: { [weak self] userInfo in
Expand Down
115 changes: 25 additions & 90 deletions KkuMulKum/Source/MyPage/ViewModel/MyPageEditViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,12 @@ class MyPageEditViewModel: ViewModelType {
private let userInfo = BehaviorRelay<LoginUserModel?>(value: nil)
let profileImageUpdated = PublishSubject<String?>()


struct Input {
let profileImageTap: Observable<Void>
let confirmButtonTap: Observable<Void>
let skipButtonTap: Observable<Void>
let newProfileImage: Observable<UIImage?>
}

struct Output {
let profileImage: Driver<UIImage?>
let isConfirmButtonEnabled: Driver<Bool>
let serverResponse: Driver<String?>
let userInfo: Driver<LoginUserModel?>
Expand All @@ -37,95 +33,12 @@ class MyPageEditViewModel: ViewModelType {
}

func transform(input: Input, disposeBag: DisposeBag) -> Output {
let imageDataRelay = BehaviorRelay<Data?>(value: nil)
let serverResponseRelay = PublishRelay<String?>()

input.newProfileImage
.compactMap { $0?.jpegData(compressionQuality: 0.8) }
.do(onNext: { data in
print("New profile image data size: \(data.count) bytes")
})
.bind(to: imageDataRelay)
.disposed(by: disposeBag)

let profileImage = imageDataRelay
.map { data -> UIImage? in
guard let data = data else { return UIImage.imgProfile }
return UIImage(data: data)
}
.asDriver(onErrorJustReturn: UIImage.imgProfile)

let isConfirmButtonEnabled = imageDataRelay
.map { $0 != nil }
.asDriver(onErrorJustReturn: false)

input.confirmButtonTap
.withLatestFrom(imageDataRelay)
.flatMapLatest { [weak self] imageData -> Observable<String> in
guard let self = self, let imageData = imageData else {
print("No image data available for upload")
return .just("이미지 데이터가 없습니다.")
}
return Observable.create { observer in
Task {
do {
print("Attempting to upload image data of size: \(imageData.count) bytes")
let _: EmptyModel = try await self.authService.performRequest(
.updateProfileImage(
image: imageData,
fileName: "profile_image.jpg",
mimeType: "image/jpeg"
)
)
print("Profile image upload successful")
self.profileImageUpdated.onNext(imageData.base64EncodedString())
observer.onNext("프로필 이미지가 성공적으로 업로드되었습니다.")
observer.onCompleted()
} catch {
let networkError = error as? NetworkError ?? .unknownError("알 수 없는 오류가 발생했습니다.")
print("Profile image upload failed: \(networkError)")
observer.onNext(self.handleError(networkError))
observer.onCompleted()
}
}
return Disposables.create()
}
}
.bind(to: serverResponseRelay)
.disposed(by: disposeBag)

input.skipButtonTap
.flatMapLatest { [weak self] _ -> Observable<String> in
guard let self = self else { return .just("오류가 발생했습니다.") }
return Observable.create { observer in
Task {
do {
let defaultImageData = UIImage.imgProfile.jpegData(compressionQuality: 1.0) ?? Data()
let _: EmptyModel = try await self.authService.performRequest(
.updateProfileImage(
image: defaultImageData,
fileName: "default_profile.jpg",
mimeType: "image/jpeg"
)
)
self.profileImageUpdated.onNext(nil)
observer.onNext("프로필 이미지가 기본 이미지로 변경되었습니다.")
observer.onCompleted()
} catch {
let networkError = error as? NetworkError ?? .unknownError("알 수 없는 오류가 발생했습니다.")
observer.onNext(self.handleError(networkError))
observer.onCompleted()
}
}
return Disposables.create()
}
}
.bind(to: serverResponseRelay)
.disposed(by: disposeBag)
let isConfirmButtonEnabled = BehaviorRelay<Bool>(value: false)

return Output(
profileImage: profileImage,
isConfirmButtonEnabled: isConfirmButtonEnabled,
isConfirmButtonEnabled: isConfirmButtonEnabled.asDriver(),
serverResponse: serverResponseRelay.asDriver(onErrorJustReturn: nil),
userInfo: userInfo.asDriver()
)
Expand All @@ -152,7 +65,29 @@ class MyPageEditViewModel: ViewModelType {
} catch {
let networkError = error as? NetworkError ?? .unknownError("오류 발생.")
print("Profile image upload failed: \(networkError)")
self.profileImageUpdated.onNext(nil)
self.profileImageUpdated.onNext(nil)
}
}
}

func setDefaultProfileImage() {
Task {
do {
let defaultImageData = UIImage.imgProfile.jpegData(compressionQuality: 1.0) ?? Data()
let _: EmptyModel = try await self.authService.performRequest(
.updateProfileImage(
image: defaultImageData,
fileName: "default_profile.jpg",
mimeType: "image/jpeg"
)
)
DispatchQueue.main.async { [weak self] in
self?.profileImageUpdated.onNext(nil)
}
} catch {
let networkError = error as? NetworkError ?? .unknownError("오류 발생.")
print("Default profile image upload failed: \(networkError)")
self.profileImageUpdated.onNext(nil)
}
}
}
Expand Down

0 comments on commit 33adacc

Please sign in to comment.