-
Notifications
You must be signed in to change notification settings - Fork 167
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
쥬스메이커 [STEP 3] 제이티, Ari #135
Closed
Closed
Changes from 19 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
3d2a6da
feat: 재고수정 화면 진입시 Label, Stepper의 Value 연동 기능 구현
leeari95 1e85463
feat: FruitStore에서 Label과 Stepper의 값 연동 및 Stepper 터치 시 Label 값 변환 구현
HoneyCoding df7531a
feat: Stepper를 클릭시 재고가 계산되도록 기능 구현
leeari95 23a4bdc
fix: FruitStore의 잘못된 조건문 수정
HoneyCoding febd113
fix: 재고 부족시 재고수정으로 넘어갈 때 Label 반영 안되는 버그 수정
leeari95 bd2ac42
refactor: JuiceMakerViewController의 중복 코드를 빼주어 메소드 setupNextViewLabel…
HoneyCoding 9b545cf
refactor: stepperTapped 내부 가독성을 위해 fruitLabelText 메소드 추가하여 리팩토링
leeari95 e71fa4f
fix: Storyboard에서 JuiceMakerViewController Scene의 Content Priority 충돌…
HoneyCoding b9d4c03
fix: Button titleLabel이 버튼의 너비에 fit되도록 설정, 글꼴 자동 업데이트 설정
leeari95 4864c3c
refactor: JuiceMakerViewController의 코드를 extension을 사용해 분리
HoneyCoding 93bf54e
refactor: FruitStoreViewController 내부 extension으로 분리
leeari95 484a0a1
fix: Storyboard의 Stepper와 연결된 stepperTapped 메소드의 Sent Events 변경
HoneyCoding 2b397db
chore: 의미없는 줄바꿈과 프로퍼티 삭제
leeari95 1fec18c
chore: 기존 코드에서 오버 스펙으로 구현한 부분 제거
HoneyCoding da64fc6
docs: README.md 파일 내부에 STEP 3 관련 내용 추가
leeari95 ccb8a10
docs: README.md 파일 수정하다가 빠진 STEP 2 내용 다시 추가
leeari95 ae7582e
refactor: 메소드 네이밍 동사로 시작하도록 수정
HoneyCoding 3a3c801
docs: READMD.md 파일 내용 추가
leeari95 82c2aa5
refactor: chooseCalculator 메소드 내에서 switch 문 사용을 if 문 사용으로 수정
HoneyCoding 119b6d6
refactor: currentStockLabelUpdate 메소드 이름을 동사로 수정
leeari95 288fe58
refactor: JuiceMakerViewController, JuiceMaker, FruitStore 리팩토링
HoneyCoding d8f244d
refactor: 기존에 Singleton 패턴을 삭제
leeari95 ba4de9c
feat: UIButton에 extension을 통해 메소드 추가 및 기존 코드 일부 수정
HoneyCoding 6a7ae09
refactor: fruitLabelChanged 메소드 이름을 fruitStockChanged로 수정
leeari95 dc428fe
feat: FruitStoreViewController가 deinit될 때 Notification 제거 코드 추가
HoneyCoding 981c869
docs: README.md 내부 개선사항 내용 추가
leeari95 abef023
docs: README.md 수정
leeari95 827e98b
docs: README.md 내부 수정
leeari95 4809668
docs: README.md 내부 오타와 UML 이미지 수정
leeari95 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,8 @@ | |
|
||
import UIKit | ||
|
||
// MARK: - Properties and Lifecycle | ||
class JuiceMakerViewController: UIViewController { | ||
|
||
private let juiceMaker = JuiceMaker() | ||
|
||
@IBOutlet weak var strawberryStockLabel: UILabel! | ||
|
@@ -27,10 +27,69 @@ class JuiceMakerViewController: UIViewController { | |
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
updateFruitLabels() | ||
|
||
setUpbuttonLabelFontAttributes() | ||
|
||
NotificationCenter.default.addObserver(self, selector: #selector(fruitLabelChanged(notification:)), name: .changedFruitStockNotification, object: nil) | ||
} | ||
} | ||
|
||
// MARK: - Setup Label and Button | ||
extension JuiceMakerViewController { | ||
func setUpbuttonLabelFontAttributes() { | ||
orderStrawberryBananaJuiceButton.titleLabel?.adjustsFontForContentSizeCategory = true | ||
orderMangoKiwiJuiceButton.titleLabel?.adjustsFontForContentSizeCategory = true | ||
orderStrawberryJuiceButton.titleLabel?.adjustsFontForContentSizeCategory = true | ||
orderBananaJuiceButton.titleLabel?.adjustsFontForContentSizeCategory = true | ||
orderPineappleJuiceButton.titleLabel?.adjustsFontForContentSizeCategory = true | ||
orderKiwiJuiceButton.titleLabel?.adjustsFontForContentSizeCategory = true | ||
orderMangoJuiceButton.titleLabel?.adjustsFontForContentSizeCategory = true | ||
|
||
orderStrawberryBananaJuiceButton.titleLabel?.adjustsFontSizeToFitWidth = true | ||
orderMangoKiwiJuiceButton.titleLabel?.adjustsFontSizeToFitWidth = true | ||
orderStrawberryJuiceButton.titleLabel?.adjustsFontSizeToFitWidth = true | ||
orderBananaJuiceButton.titleLabel?.adjustsFontSizeToFitWidth = true | ||
orderPineappleJuiceButton.titleLabel?.adjustsFontSizeToFitWidth = true | ||
orderKiwiJuiceButton.titleLabel?.adjustsFontSizeToFitWidth = true | ||
orderMangoJuiceButton.titleLabel?.adjustsFontSizeToFitWidth = true | ||
} | ||
|
||
func updateFruitLabels() { | ||
currentStockLabelUpdate(fruit: .strawberry, label: strawberryStockLabel) | ||
currentStockLabelUpdate(fruit: .banana, label: bananaStockLabel) | ||
currentStockLabelUpdate(fruit: .pineapple, label: pineappleStockLabel) | ||
currentStockLabelUpdate(fruit: .kiwi, label: kiwiStockLabel) | ||
currentStockLabelUpdate(fruit: .mango, label: mangoStockLabel) | ||
} | ||
|
||
func currentStockLabelUpdate(fruit: Fruit, label: UILabel) { | ||
do { | ||
let stock = try FruitStore.shared.stock(fruit: fruit) | ||
label.text = stock.description | ||
} catch let error as RequestError { | ||
showNotificationAlert(message: error.errorDescription) | ||
} catch { | ||
showNotificationAlert(message: Message.unknownError.description) | ||
} | ||
} | ||
|
||
func fruitlabel(of fruit: Fruit) -> UILabel { | ||
switch fruit { | ||
case .strawberry: | ||
return strawberryStockLabel | ||
case .banana: | ||
return bananaStockLabel | ||
case .pineapple: | ||
return pineappleStockLabel | ||
case .kiwi: | ||
return kiwiStockLabel | ||
case .mango: | ||
return mangoStockLabel | ||
} | ||
} | ||
} | ||
|
||
// MARK: - Order Juice | ||
extension JuiceMakerViewController { | ||
@IBAction func orderJuiceButtonTapped(_ sender: UIButton) { | ||
let juice: Juice | ||
|
||
|
@@ -70,48 +129,6 @@ class JuiceMakerViewController: UIViewController { | |
} | ||
} | ||
|
||
@objc func fruitLabelChanged(notification: Notification) { | ||
guard let fruit = notification.object as? Fruit else { | ||
showNotificationAlert(message: Message.unknownError.description) | ||
return | ||
} | ||
currentStockLabelUpdate(fruit: fruit, label: fruitlabel(of: fruit)) | ||
} | ||
|
||
func updateFruitLabels() { | ||
currentStockLabelUpdate(fruit: .strawberry, label: strawberryStockLabel) | ||
currentStockLabelUpdate(fruit: .banana, label: bananaStockLabel) | ||
currentStockLabelUpdate(fruit: .pineapple, label: pineappleStockLabel) | ||
currentStockLabelUpdate(fruit: .kiwi, label: kiwiStockLabel) | ||
currentStockLabelUpdate(fruit: .mango, label: mangoStockLabel) | ||
} | ||
|
||
func currentStockLabelUpdate(fruit: Fruit, label: UILabel) { | ||
do { | ||
let stock = try FruitStore.shared.stock(fruit: fruit) | ||
label.text = stock.description | ||
} catch let error as RequestError { | ||
showNotificationAlert(message: error.errorDescription) | ||
} catch { | ||
showNotificationAlert(message: Message.unknownError.description) | ||
} | ||
} | ||
|
||
func fruitlabel(of fruit: Fruit) -> UILabel { | ||
switch fruit { | ||
case .strawberry: | ||
return strawberryStockLabel | ||
case .banana: | ||
return bananaStockLabel | ||
case .pineapple: | ||
return pineappleStockLabel | ||
case .kiwi: | ||
return kiwiStockLabel | ||
case .mango: | ||
return mangoStockLabel | ||
} | ||
} | ||
|
||
func showNotificationAlert(message: String, title: String = Text.ok.title) { | ||
let alert = UIAlertController(title: nil, message: message, preferredStyle: .alert) | ||
let cancel = UIAlertAction(title: title, style: .cancel, handler: nil) | ||
|
@@ -127,10 +144,40 @@ class JuiceMakerViewController: UIViewController { | |
alert.addAction(okAction) | ||
present(alert, animated: true, completion: nil) | ||
} | ||
|
||
} | ||
|
||
// MARK: - Transition | ||
extension JuiceMakerViewController { | ||
private func presentFruitStoreViewController(_ action: UIAlertAction) { | ||
guard let viewController = self.storyboard?.instantiateViewController(withIdentifier: "FruitStoreViewController") else { return } | ||
guard let viewController = self.storyboard?.instantiateViewController(withIdentifier: "FruitStoreViewController") as? UINavigationController else { return } | ||
self.present(viewController, animated: true, completion: nil) | ||
guard let nextViewController = viewController.topViewController as? FruitStoreViewController else { return } | ||
setupNextViewLabel(of: nextViewController) | ||
} | ||
|
||
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { | ||
guard let navigationController = segue.destination as? UINavigationController else { return } | ||
guard let nextViewController = navigationController.topViewController as? FruitStoreViewController else { return } | ||
setupNextViewLabel(of: nextViewController) | ||
} | ||
|
||
func setupNextViewLabel(of nextViewController: FruitStoreViewController) { | ||
nextViewController.loadViewIfNeeded() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
nextViewController.strawberryStockLabel.text = strawberryStockLabel.text | ||
nextViewController.bananaStockLabel.text = bananaStockLabel.text | ||
nextViewController.pineappleStockLabel.text = pineappleStockLabel.text | ||
nextViewController.kiwiStockLabel.text = kiwiStockLabel.text | ||
nextViewController.mangoStockLabel.text = mangoStockLabel.text | ||
} | ||
} | ||
|
||
// MARK: - Notification | ||
extension JuiceMakerViewController { | ||
@objc func fruitLabelChanged(notification: Notification) { | ||
guard let fruit = notification.object as? Fruit else { | ||
showNotificationAlert(message: Message.unknownError.description) | ||
return | ||
} | ||
currentStockLabelUpdate(fruit: fruit, label: fruitlabel(of: fruit)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
파라미터로 action 은 왜 받는건가요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.