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

[Feat] 네트워크 오류시 띄우는 얼럿 뷰 추가 및 홈 컨트롤러 levelProgressView 이슈 (#210) #211

Merged
merged 6 commits into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions Happic-iOS/Happic-iOS/Global/Extension/UIViewController+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,16 @@ extension UIViewController {
endPoint: CGPoint(x: 2.4, y: 0.4))
}

func showAlert(title: String, message: String? = nil,
okTitle: String = "확인", okAction: ((UIAlertAction) -> Void)? = nil,
completion : (() -> Void)? = nil) {
LoadingIndicator.hideLoading()
let generator = UIImpactFeedbackGenerator(style: .medium)
Copy link
Contributor

Choose a reason for hiding this comment

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

여기에 hideLoading()을 넣어주는 것도 괜찮겠네요!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

넵 수정하겠습니다

generator.impactOccurred()
let alertVC = UIAlertController(title: title, message: message,
preferredStyle: .alert)
let okAction = UIAlertAction(title: okTitle, style: .default, handler: okAction)
alertVC.addAction(okAction)
self.present(alertVC, animated: true, completion: completion)
}
}
3 changes: 1 addition & 2 deletions Happic-iOS/Happic-iOS/Global/Util/LoadingIndicator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ class LoadingIndicator {
guard let window = UIApplication.shared.windows.last else { return }

let loadingIndicatorView: UIActivityIndicatorView
if let existedView = window.subviews.first(where: { $0 is UIActivityIndicatorView } ) as? UIActivityIndicatorView {
if let existedView = window.subviews.first(where: { $0 is UIActivityIndicatorView }) as? UIActivityIndicatorView {
Copy link
Contributor

Choose a reason for hiding this comment

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

역시 인간 린트..

loadingIndicatorView = existedView
} else {
loadingIndicatorView = UIActivityIndicatorView(style: .large)
/// 다른 UI가 눌리지 않도록 indicatorView의 크기를 full로 할당
loadingIndicatorView.frame = window.frame
loadingIndicatorView.color = .lightGray
window.addSubview(loadingIndicatorView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ extension AuthViewController {
LoadingIndicator.hideLoading()
self.dismiss(animated: true)
default:
LoadingIndicator.hideLoading()
Copy link
Contributor

Choose a reason for hiding this comment

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

hideLoading() 없애면 로딩 뷰가 계속 보이고 그 위에 Alert가 뜰 거 같은데 괜찮을까요?

self.showAlert(title: "네트워크 오류로 인해\n데이터를 불러올 수 없습니다.\n다시 시도해 주세요.")
print(response)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ extension CharacterNameViewController {
LoadingIndicator.hideLoading()
self.dismiss(animated: true)
default:
LoadingIndicator.hideLoading()
self.showAlert(title: "네트워크 오류로 인해\n데이터를 불러올 수 없습니다.\n다시 시도해 주세요.")
print(response)
}
}
Expand All @@ -139,11 +139,12 @@ extension CharacterNameViewController {
SignUpService.shared.changeCharacter(characterId: characterId, characterName: characterName) { response in
switch response {
case .success:
LoadingIndicator.hideLoading()
print("change character name success")
default:
self.showAlert(title: "네트워크 오류로 인해\n데이터를 불러올 수 없습니다.\n다시 시도해 주세요.")
print(response)
}
}
LoadingIndicator.hideLoading()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,12 @@ extension CreateContentsController {
print(response)
guard let data = result as? UploadImageModel else { return }
self.photoURL = data.link
LoadingIndicator.hideLoading()
default:
self.showAlert(title: "네트워크 오류로 인해\n데이터를 불러올 수 없습니다.\n다시 시도해 주세요.")
print(response)
}
}
LoadingIndicator.hideLoading()
}

func getRecommendTag() {
Expand All @@ -368,11 +369,11 @@ extension CreateContentsController {
self.whereTagView.setData(tags: data.place)
self.whoTagView.setData(tags: data.who)
self.whatTagView.setData(tags: data.what)
LoadingIndicator.hideLoading()
default:
break
self.showAlert(title: "네트워크 오류로 인해\n데이터를 불러올 수 없습니다.\n다시 시도해 주세요.")
}
}
LoadingIndicator.hideLoading()
}

func createHaruHappic() {
Expand All @@ -397,11 +398,12 @@ extension CreateContentsController {
case .success:
self.dismissViewController()
self.delegate?.showToastAfterCreating("오늘의 해픽을 등록했어요")
LoadingIndicator.hideLoading()
default:
self.dismissViewController()
self.delegate?.showToastAfterCreating("\(response)")
self.showAlert(title: "네트워크 오류로 인해\n데이터를 불러올 수 없습니다.\n다시 시도해 주세요.")
}
}
LoadingIndicator.hideLoading()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ extension HappicCapsuleController {
self.capsuleView.whoLabel.text = "#\(data.who)"
self.capsuleView.whatLabel.text = "#\(data.what)"
self.capsuleView.whereLabel.text = "#\(data.place)"
LoadingIndicator.hideLoading()
default:
break
self.showAlert(title: "네트워크 오류로 인해\n데이터를 불러올 수 없습니다.\n다시 시도해 주세요.")
}
}
LoadingIndicator.hideLoading()
}

func canPost() {
Expand All @@ -166,10 +166,10 @@ extension HappicCapsuleController {
case .success(let result):
guard let data = result as? PostStatusModel else { return }
self.createContentsButton.isHidden = data.isPosted
LoadingIndicator.hideLoading()
default:
break
self.showAlert(title: "네트워크 오류로 인해\n데이터를 불러올 수 없습니다.\n다시 시도해 주세요.")
}
}
LoadingIndicator.hideLoading()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ extension HappicReportController {
self.keywordRankView.setData(model: data.rank2S)
self.categoryRankView.setData(model: data.rank3S)
self.monthHappicRecordView.setData(model: data.rank4S)
LoadingIndicator.hideLoading()
default:
break
self.showAlert(title: "네트워크 오류로 인해\n데이터를 불러올 수 없습니다.\n다시 시도해 주세요.")
}
}
LoadingIndicator.hideLoading()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ extension CategoryRankController {
guard let data = result as? [KeywordModel] else { return }
self.handleEmptyView(isEmpty: data.isEmpty)
self.categoryRankView.setWhenData(model: data)
LoadingIndicator.hideLoading()
default:
break
self.showAlert(title: "네트워크 오류로 인해\n데이터를 불러올 수 없습니다.\n다시 시도해 주세요.")
}
}

Expand All @@ -87,8 +88,9 @@ extension CategoryRankController {
case .success(let result):
guard let data = result as? [KeywordModel] else { return }
self.categoryRankView.setWhereData(model: data)
LoadingIndicator.hideLoading()
default:
break
self.showAlert(title: "네트워크 오류로 인해\n데이터를 불러올 수 없습니다.\n다시 시도해 주세요.")
}
}

Expand All @@ -97,8 +99,9 @@ extension CategoryRankController {
case .success(let result):
guard let data = result as? [KeywordModel] else { return }
self.categoryRankView.setWhoData(model: data)
LoadingIndicator.hideLoading()
default:
break
self.showAlert(title: "네트워크 오류로 인해\n데이터를 불러올 수 없습니다.\n다시 시도해 주세요.")
}
}

Expand All @@ -107,10 +110,10 @@ extension CategoryRankController {
case .success(let result):
guard let data = result as? [KeywordModel] else { return }
self.categoryRankView.setWhatData(model: data)
LoadingIndicator.hideLoading()
default:
break
self.showAlert(title: "네트워크 오류로 인해\n데이터를 불러올 수 없습니다.\n다시 시도해 주세요.")
}
}
LoadingIndicator.hideLoading()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ extension KeywordRankController {
self.keywordRankView.isHidden = data.isEmpty
self.containerView.isHidden = !data.isEmpty
self.keywordRankView.setData(model: data)
LoadingIndicator.hideLoading()
default:
break
self.showAlert(title: "네트워크 오류로 인해\n데이터를 불러올 수 없습니다.\n다시 시도해 주세요.")
}
}
LoadingIndicator.hideLoading()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ extension MonthHappicRecordController {
guard let data = result as? MonthlyCountModel else { return }
self.monthHappicRecordView.setData(model: data)
self.calendarView.setData(model: data)
LoadingIndicator.hideLoading()
default:
break
self.showAlert(title: "네트워크 오류로 인해\n데이터를 불러올 수 없습니다.\n다시 시도해 주세요.")
}
}
LoadingIndicator.hideLoading()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ extension HaruHappicController {
} else {
self.setActionSheet()
}
LoadingIndicator.hideLoading()
default:
break
self.showAlert(title: "네트워크 오류로 인해\n데이터를 불러올 수 없습니다.\n다시 시도해 주세요.")
}
}
LoadingIndicator.hideLoading()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ extension HomeController {
} else {
self.setActionSheet()
}
LoadingIndicator.hideLoading()
default:
break
self.showAlert(title: "네트워크 오류로 인해\n데이터를 불러올 수 없습니다.\n다시 시도해 주세요.")
}
}
LoadingIndicator.hideLoading()
}
}

Expand Down Expand Up @@ -214,11 +214,13 @@ extension HomeController {
}
self.progressLabel.text = "\(data.growthRate)/6"
self.nameLabel.text = data.characterName
self.levelProgressView.progress = Float(data.growthRate / 6)
let progressValue: Float = Float(data.growthRate) / 6
self.levelProgressView.setProgress(progressValue, animated: true)

LoadingIndicator.hideLoading()
default:
break
self.showAlert(title: "네트워크 오류로 인해\n데이터를 불러올 수 없습니다.\n다시 시도해 주세요.")
}
}
LoadingIndicator.hideLoading()
}
}