Skip to content

Commit

Permalink
Merge pull request #105 from boostcampwm-2022/bugfix_capsuleAdd
Browse files Browse the repository at this point in the history
캡슐 추가, 프로필 버그 수정
  • Loading branch information
pyj9748 authored Dec 12, 2022
2 parents 318df3c + 8b83b14 commit f2b73d2
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ extension KingReceiverWrapper where Base: UIImageView {
}
}

func setImage(with data: Data, placeholder: UIImage? = nil, width: CGFloat, scale: CGFloat = 1) {
guard let image = UIImage.resize(data: data, to: base.frame.size, scale: scale) else {
func setImage(
with data: Data,
placeholder: UIImage? = nil,
to targetSize: CGSize,
scale: CGFloat = 1
) {
guard let image = UIImage.resize(data: data, to: targetSize, scale: scale) else {
base.image = placeholder
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ extension UIImage {
kCGImageSourceCreateThumbnailWithTransform: true,
kCGImageSourceThumbnailMaxPixelSize: maxDimension,
] as CFDictionary

guard let resizedImage = CGImageSourceCreateThumbnailAtIndex(imageSource, 0, resizingOptions) else {
print("resized error")
return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ final class CapsuleCreateView: UIView, BaseView {
private let dateLabel = ThemeLabel(text: "추억 날짜", size: FrameResource.fontSize110, color: .themeGray300)
private let descriptionLabel = ThemeLabel(text: "내용", size: FrameResource.fontSize110, color: .themeGray300)

let titleTextField = ThemeTextField(placeholder: "추억하고 싶은 캡슐의 이름을 적어주세요")
let titleTextField: ThemeTextField = {
let textField = ThemeTextField(placeholder: "추억하고 싶은 캡슐의 이름을 적어주세요 (최대 15자)")

return textField
}()

let locationSelectView = SelectButton(text: "주소를 선택하세요")
let dateSelectView = SelectButton(text: "날짜를 선택하세요")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,7 @@ final class CapsuleCreateViewController: UIViewController, BaseViewController {
setUpNavigation()
addSubViews()
makeConstraints()

mainView.imageCollectionView.applyDataSource()

addTapGestureRecognizer()
scrollView.addKeyboardNotification()

configure()
bind()
}

Expand All @@ -60,6 +55,13 @@ final class CapsuleCreateViewController: UIViewController, BaseViewController {
scrollView.removeKeyboardNotification()
}

private func configure() {
mainView.titleTextField.delegate = self
mainView.imageCollectionView.applyDataSource()
addTapGestureRecognizer()
scrollView.addKeyboardNotification()
}

func bind() {
closeButton.rx.tap
.withUnretained(self)
Expand Down Expand Up @@ -256,7 +258,7 @@ extension CapsuleCreateViewController: PHPickerViewControllerDelegate {
return
}

itemProvider.loadObject(ofClass: UIImage.self) { [weak self] image, _ in
itemProvider.loadObject(ofClass: UIImage.self) { image, _ in
guard let selectedImage = image as? UIImage,
let data = selectedImage.jpegData(compressionQuality: 0.2) else {
dispatchGroup.leave()
Expand All @@ -272,8 +274,20 @@ extension CapsuleCreateViewController: PHPickerViewControllerDelegate {
let orderedData = dataDict
.sorted(by: { $0.key < $1.key })
.compactMap { $0.value }

self?.viewModel?.addImage(orderedData: orderedData)
}
}
}

extension CapsuleCreateViewController: UITextFieldDelegate {
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
guard let textValue = textField.text else {
return false
}
let currentString = textValue as NSString
let newString = currentString.replacingCharacters(in: range, with: string) as NSString

return newString.length <= 15
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ import UIKit
final class AddImageCell: UICollectionViewCell {
let imageView: UIImageView = {
let imageView = UIImageView()
imageView.contentMode = .scaleAspectFit
imageView.contentMode = .scaleAspectFill

return imageView
}()

override init(frame: CGRect) {
super.init(frame: frame)

backgroundColor = .themeBlack

addSubViews()
makeConstraints()
}
Expand All @@ -31,7 +31,12 @@ final class AddImageCell: UICollectionViewCell {
}

func configure(data: Data) {
imageView.kr.setImage(with: data, placeholder: .empty, width: frame.size.width)
imageView.kr.setImage(
with: data,
placeholder: .empty,
to: frame.size,
scale: FrameResource.openableImageScale
)
}

private func addSubViews() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,27 @@ final class ProfileViewController: UIViewController, BaseViewController {
}

func bind() {
guard let viewModel else {
return
}

profileView.notificationButton.rx.tap
.bind {
viewModel.input.tapSetupNotification.onNext(())
.bind { [weak self] in
self?.viewModel?.input.tapSetupNotification.onNext(())
}
.disposed(by: disposeBag)

profileView.settingButton.rx.tap
.bind {
viewModel.input.tapSetting.onNext(())
.bind { [weak self] in
self?.viewModel?.input.tapSetting.onNext(())
}
.disposed(by: disposeBag)

profileView.signOutButton.rx.tap
.bind {
viewModel.input.tapSignOut.onNext(())
.bind { [weak self] in
self?.viewModel?.input.tapSignOut.onNext(())
}
.disposed(by: disposeBag)

profileView.deleteAccountButton.rx.tap
.bind {
viewModel.input.tapWithdrawal.onNext(())
.bind { [weak self] in
self?.viewModel?.input.tapWithdrawal.onNext(())
}
.disposed(by: disposeBag)

Expand All @@ -77,28 +73,18 @@ final class ProfileViewController: UIViewController, BaseViewController {
guard let viewModel else {
return
}

viewModel.input.tapSetupNotification
.withUnretained(self)
.bind { owner, _ in
NotificationManager.shared.checkNotificationAuthorization { isAuthorized in
if isAuthorized {
owner.showAlreadyAllowed(type: .notification)
} else {
owner.showRequestAuthorization(type: .notification)
}
}
owner.showSettings(type: UIApplication.openNotificationSettingsURLString)
}
.disposed(by: disposeBag)

viewModel.input.tapSetting
.withUnretained(self)
.bind { owner, _ in
LocationManager.shared.checkLocationAuthorization { isAuthorized in
if isAuthorized {
owner.showAlreadyAllowed(type: .location)
} else {
owner.showRequestAuthorization(type: .location)
}
}
owner.showSettings(type: UIApplication.openSettingsURLString)
}
.disposed(by: disposeBag)

Expand Down Expand Up @@ -138,29 +124,12 @@ final class ProfileViewController: UIViewController, BaseViewController {
alertController.addAction(acceptAction)
present(alertController, animated: true, completion: nil)
}

private func showAlreadyAllowed(type: Authorization) {
let alertController = UIAlertController(title: type.description, message: "이미 동의하셨습니다.", preferredStyle: .alert)
let acceptAction = UIAlertAction(title: "확인", style: .default, handler: nil)
alertController.addAction(acceptAction)
DispatchQueue.main.async { [weak self] in
self?.present(alertController, animated: true, completion: nil)
}
}

private func showRequestAuthorization(type: Authorization) {
guard let url = URL(string: UIApplication.openSettingsURLString) else {
return
}
let alertController = UIAlertController(title: type.description, message: "앱 설정에서 \(type.description)을 허용해주세요.", preferredStyle: .alert)
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
let acceptAction = UIAlertAction(title: "OK", style: .default, handler: { _ in
UIApplication.shared.open(url)
})
alertController.addAction(cancelAction)
alertController.addAction(acceptAction)
DispatchQueue.main.async { [weak self] in
self?.present(alertController, animated: true, completion: nil)

private func showSettings(type: String) {
guard let url = URL(string: type) else {
return
}

UIApplication.shared.open(url)
}
}

0 comments on commit f2b73d2

Please sign in to comment.