Skip to content

Commit

Permalink
Merge pull request #283 from team-haribo/282-QRScan-ErrorEdit
Browse files Browse the repository at this point in the history
🔀 :: [#282] 뒤로가기 수정, VC 호출 오류
  • Loading branch information
Xixn2 authored Nov 25, 2024
2 parents 6db7c57 + 0eb9d1c commit 81b5885
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 102 deletions.
51 changes: 37 additions & 14 deletions Projects/App/Sources/Application/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
let isSwitchOn = defaults.bool(forKey: "isSwitchOn")
let adminIsSwitchOn = defaults.bool(forKey: "isSwitchMakeOn")

checkForUpdates { needsUpdate in
if needsUpdate {
print("업데이트 필요")
self.showUpdatePopup()
} else {
print("최신 버전입니다")
}
}

applySavedTheme()

if let accessToken = KeyChain.shared.read(key: Const.KeyChainKey.accessToken), !accessToken.isEmpty {
Expand All @@ -38,9 +47,23 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
DispatchQueue.main.async {
if authority == "ROLE_STUDENT_COUNCIL" {
if adminIsSwitchOn {
print("Admin Screen: AdminQRViewController")
self.window?.rootViewController = UINavigationController(rootViewController: AdminQRViewController())
} else {
print("Admin Screen: AdminMainViewController")

let adminMainVC = AdminMainViewController()
let navigationController = UINavigationController(rootViewController: adminMainVC)
self.window?.rootViewController = navigationController

DispatchQueue.main.async {
let adminQRVC = AdminQRViewController()

UIView.performWithoutAnimation {
navigationController.pushViewController(adminQRVC, animated: false)
}
}
}


else {
print("Admin Screen: AdminMainViewController")
self.window?.rootViewController = UINavigationController(rootViewController: AdminMainViewController())
}
Expand Down Expand Up @@ -79,7 +102,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
completion(false)
return
}

let url = URL(string: "https://itunes.apple.com/lookup?bundleId=\(bundleID)")!
let task = URLSession.shared.dataTask(with: url) { data, response, error in
guard let data = data, error == nil else {
Expand All @@ -90,7 +113,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
if let json = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any],
let results = json["results"] as? [[String: Any]],
let appStoreVersion = results.first?["version"] as? String {

let currentVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
if let currentVersion = currentVersion, currentVersion.compare(appStoreVersion, options: .numeric) == .orderedAscending {
completion(true)
Expand All @@ -106,36 +129,36 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
}
task.resume()
}

private func showUpdatePopup() {
let alertController = UIAlertController(
title: "업데이트 알림",
message: "더 나은 서비스를 위해 곰스가 수정되었어요!\n업데이트해 주시겠어요?",
preferredStyle: .alert
)

let updateAction = UIAlertAction(title: "확인", style: .default) { _ in
if let url = URL(string: "https://apps.apple.com/kr/app/goms/id6502936560") {
UIApplication.shared.open(url)
}
}

alertController.addAction(updateAction)

DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
self.window?.rootViewController?.present(alertController, animated: true) {
print("업데이트 팝업 표시됨")
}
}
}

func sceneDidDisconnect(_ scene: UIScene) {}

func sceneDidBecomeActive(_ scene: UIScene) {}

func sceneWillResignActive(_ scene: UIScene) {}

func sceneWillEnterForeground(_ scene: UIScene) {}

func sceneDidEnterBackground(_ scene: UIScene) {}
}
2 changes: 1 addition & 1 deletion Projects/App/Support/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.4.3</string>
<string>1.4.4</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class AdminMainViewController: BaseViewController, UICollectionViewDataSo
private let basicsProfileView = ProfileCardView()
private let authViewModel = AuthViewModel()
private let profileViewModel = ProfileViewModel()
private let profileView = MainProfileView()
let refreshControl = UIRefreshControl()

let scrollView = UIScrollView().then {
Expand All @@ -33,8 +34,6 @@ public class AdminMainViewController: BaseViewController, UICollectionViewDataSo
$0.expandedTouchArea = 30
}

private let profileView = MainProfileView()

private let latecomerLabel = UILabel().then {
$0.text = "지각자 TOP 3"
$0.setDynamicTextColor(darkModeColor: .white, lightModeColor: .black)
Expand Down Expand Up @@ -93,16 +92,19 @@ public class AdminMainViewController: BaseViewController, UICollectionViewDataSo
$0.addTarget(self, action: #selector(qrButtonTapped), for: .touchUpInside)
}

private var isVisible: Bool = false // 추가된 플래그

// MARK: - Life Cycle
public override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
viewModel.getProfile {_ in
self.setupProfileView()
isVisible = true // 뷰 컨트롤러가 나타남
viewModel.getProfile { [weak self] _ in
self?.setupProfileView()
}

viewModel.getLateList {
self.viewModel.getOutingList {
self.setup()
viewModel.getLateList { [weak self] in
self?.viewModel.getOutingList { [weak self] in
self?.setup()
}
}

Expand All @@ -114,14 +116,20 @@ public class AdminMainViewController: BaseViewController, UICollectionViewDataSo
self.navigationController?.navigationBar.isHidden = true
}

public override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
isVisible = false // 뷰 컨트롤러가 사라짐
refreshControl.endRefreshing() // 새로고침 종료
}

public override func viewDidLoad() {
super.viewDidLoad()
self.latecomerCollectionView.reloadData()
self.outingStatusCollectionView.reloadData()
handleRefreshControl()
configureRefreshControl()
setupScrollView()
setupProfileView()

refreshControl.beginRefreshing()
handleRefreshControl()
}

func setupScrollView() {
Expand Down Expand Up @@ -151,9 +159,12 @@ public class AdminMainViewController: BaseViewController, UICollectionViewDataSo

@objc func handleRefreshControl() {
fetchData()

guard let isLocalEmail = UserDefaults.standard.string(forKey: "localEmail"),
let isLocalPass = UserDefaults.standard.string(forKey: "localPass") else {
print("localEmail 또는 localPass 값이 없습니다.")
let introVC = IntroViewController()
self.navigationController?.setViewControllers([introVC], animated: false)
self.refreshControl.endRefreshing()
return
}
Expand All @@ -164,34 +175,46 @@ public class AdminMainViewController: BaseViewController, UICollectionViewDataSo
authViewModel.signIn { [weak self] statusCode, _ in
guard let self = self else { return }
DispatchQueue.main.async {
guard self.isVisible else {
self.refreshControl.endRefreshing()
return
}

switch statusCode {
case 200:
self.profileViewModel.loadProfileInfo { [weak self] success, authority in
guard let self = self else { return }
if success {
if let authority = self.profileViewModel.profileInfo?.authority {
let currentVC = self.navigationController?.viewControllers.last

switch authority {
case "ROLE_STUDENT":
if !(currentVC is MainViewController) {
let mainVC = MainViewController()
self.navigationController?.setViewControllers([mainVC], animated: false)
}
case "ROLE_STUDENT_COUNCIL":
if !(currentVC is AdminMainViewController) {
let adminVC = AdminMainViewController()
self.navigationController?.setViewControllers([adminVC], animated: false)
DispatchQueue.main.async {
guard self.isVisible else {
self.refreshControl.endRefreshing()
return
}

if success {
if let authority = self.profileViewModel.profileInfo?.authority {
let currentVC = self.navigationController?.viewControllers.last

switch authority {
case "ROLE_STUDENT":
if !(currentVC is MainViewController) {
let mainVC = MainViewController()
self.navigationController?.setViewControllers([mainVC], animated: false)
}
case "ROLE_STUDENT_COUNCIL":
if !(currentVC is AdminMainViewController) {
let adminVC = AdminMainViewController()
self.navigationController?.setViewControllers([adminVC], animated: false)
}
default:
print("권한이 없습니다.")
}
default:
print("권한이 없습니다.")
}
} else {
print("프로필 정보를 불러오는데 실패했습니다.")
}
} else {
print("프로필 정보를 불러오는데 실패했습니다.")
}

self.refreshControl.endRefreshing()
self.refreshControl.endRefreshing()
}
}
case 400:
print("400")
Expand All @@ -214,17 +237,27 @@ public class AdminMainViewController: BaseViewController, UICollectionViewDataSo
self.viewModel.getProfile { [weak self] _ in
guard let self = self else { return }

self.setupProfileView()
self.view.layoutIfNeeded()
DispatchQueue.main.async {
guard self.isVisible else {
self.refreshControl.endRefreshing()
return
}

self.viewModel.getOutingList { [weak self] in
guard let self = self else { return }
self.setupProfileView()
self.viewModel.getOutingList { [weak self] in
guard let self = self else { return }

self.setupViewComponents()
DispatchQueue.main.async {
guard self.isVisible else {
self.refreshControl.endRefreshing()
return
}

DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
self.refreshControl.endRefreshing()
self.view.frame.origin.y = 0
self.setupViewComponents()
self.latecomerCollectionView.reloadData()
self.outingStatusCollectionView.reloadData()
self.refreshControl.endRefreshing()
}
}
}
}
Expand Down Expand Up @@ -287,6 +320,7 @@ public class AdminMainViewController: BaseViewController, UICollectionViewDataSo

profileView.nameLabel.text = viewModel.profileData?.name
basicsProfileView.nameLabel.text = viewModel.profileData?.name

if viewModel.profileData?.major == Major.sw.rawValue {
profileView.studentInformationLabel.text = "\(grade)기 | SW개발"
basicsProfileView.studentInformationLabel.text = "\(grade)기 | SW개발"
Expand All @@ -297,6 +331,13 @@ public class AdminMainViewController: BaseViewController, UICollectionViewDataSo
profileView.studentInformationLabel.text = "\(grade)기 | AI"
basicsProfileView.studentInformationLabel.text = "\(grade)기 | AI"
}

if let authority = viewModel.profileData?.authority {
if authority == "ROLE_STUDENT_COUNCIL" {
profileView.profileStatus.text = "학생회"
basicsProfileView.myOutingStatusLabel.text = "학생회"
}
}
}

// MARK: - Selector
Expand All @@ -305,14 +346,14 @@ public class AdminMainViewController: BaseViewController, UICollectionViewDataSo
navigationController?.pushViewController(outingVC, animated: true)
}

@objc func qrButtonTapped() {
@objc public func qrButtonTapped() {
qrButton.isUserInteractionEnabled = false
let adminQRVC = AdminQRViewController()
navigationController?.pushViewController(adminQRVC, animated: true)

DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { [weak self] in
self?.qrButton.isUserInteractionEnabled = true
}
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { [weak self] in
self?.qrButton.isUserInteractionEnabled = true
}
}

@objc func adminMenuButtonTapped() {
Expand Down
Loading

0 comments on commit 81b5885

Please sign in to comment.