From 1b292bc251b3dbef532dacad9705bd197ac4227b Mon Sep 17 00:00:00 2001 From: Nicholas Tay Date: Thu, 24 Mar 2022 16:32:23 +1100 Subject: Reorganise into folder groups In preparation for presenters to come in largely, lots of files starting to go everywhere... --- foray/Coordinators/Coordinator.swift | 19 ++++++++++ foray/Coordinators/ForayCoordinator.swift | 63 +++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 foray/Coordinators/Coordinator.swift create mode 100644 foray/Coordinators/ForayCoordinator.swift (limited to 'foray/Coordinators') diff --git a/foray/Coordinators/Coordinator.swift b/foray/Coordinators/Coordinator.swift new file mode 100644 index 0000000..db97a1d --- /dev/null +++ b/foray/Coordinators/Coordinator.swift @@ -0,0 +1,19 @@ +// +// Coordinator.swift +// foray +// +// Created by Nicholas Tay on 21/3/2022. +// Based on code from Paul Hudson on Hacking with Swift +// (https://www.hackingwithswift.com/articles/71/how-to-use-the-coordinator-pattern-in-ios-apps) +// + +import Foundation +import UIKit + +protocol Coordinator { + var childCoordinators: [Coordinator] { get set } + var navigationController: UINavigationController { get set } + + func start() +} + diff --git a/foray/Coordinators/ForayCoordinator.swift b/foray/Coordinators/ForayCoordinator.swift new file mode 100644 index 0000000..6497ec0 --- /dev/null +++ b/foray/Coordinators/ForayCoordinator.swift @@ -0,0 +1,63 @@ +// +// ForayCoordinator.swift +// foray +// +// Created by Nicholas Tay on 21/3/2022. +// + +import Foundation +import UIKit + +protocol ForayCoordinated: UIViewController { + var coordinator: ForayCoordinator? { get set } +} + +class ForayCoordinator: Coordinator { + var childCoordinators = [Coordinator]() + var navigationController: UINavigationController + var loadingOverlay: ForayLoadingOverlay + + init(navigationController: UINavigationController) { + self.navigationController = navigationController + self.loadingOverlay = ForayLoadingOverlay(viewController: navigationController) + } + + private func push(vc: ForayCoordinated, animated: Bool = true) { + vc.coordinator = self + navigationController.pushViewController(vc, animated: animated) + } + + func start() { + push(vc: ForayTableViewController(), animated: false) + } + + let detailViewController = ForayDetailViewController() + + func showDetails(item: PenguinItem) { + let image: UIImage + var description: String = "Type: " + switch item.type { + case .item: + description += "Item" + image = UIImage(named: item.id)! + case .quest: + description += "Quest" + image = UIImage(named: "spy")! + } + description += "\nID: " + item.id + let dateFormatter = DateFormatter() + dateFormatter.dateFormat = "yyyy-MM-dd" + description += "\nReleased: " + dateFormatter.string(from: item.releaseDate) + + detailViewController.setDetails(name: item.name, description: description, image: image) + push(vc: detailViewController) + } + + func showLoading() { + loadingOverlay.show() + } + + func hideLoading() { + loadingOverlay.hide() + } +} -- cgit