Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Chess/App/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit
class SceneDelegate: UIResponder, UIWindowSceneDelegate {

var window: UIWindow?

var coordinator: Coordinator?

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
Expand Down
29 changes: 25 additions & 4 deletions Chess/Coordinators/MainCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,30 @@ protocol Coordinator: AnyObject {
func start()
}

enum TabBar: Int, CaseIterable {
case play, profile, settings
var title: String {
return Strings.TabBarTitles[self.rawValue]
}

var imageName: String {
return SystemImageNames.TabBarImages[self.rawValue]
}

var systemImage: UIImage? {
return UIImage(systemName: self.imageName)
}
}

class MainCoordinator: Coordinator {
var navigationController: UINavigationController // Not used for tabs, but required by protocol
var navigationController: UINavigationController = UINavigationController() // Not used for tabs, but required by protocol
var tabBarController: UITabBarController

// Keep track of child coordinators so they aren't deallocated
var childCoordinators = [Coordinator]()

init(navigationController: UINavigationController) {
self.navigationController = navigationController
self.tabBarController = UITabBarController()
init(tabBarController: UITabBarController) {
self.tabBarController = tabBarController
}

func start() {
Expand All @@ -43,6 +57,13 @@ class MainCoordinator: Coordinator {
self.tabBarController.viewControllers = [playNav, profileNav]
}

private func createNav(with item: TabBar) -> UINavigationController {
let nav = UINavigationController()
nav.tabBarItem.image = item.systemImage
nav.isNavigationBarHidden = true
return nav
}

private func configureAppearance() {
self.tabBarController.tabBar.tintColor = .link
self.tabBarController.tabBar.unselectedItemTintColor = .lightGray
Expand Down
5 changes: 4 additions & 1 deletion Chess/Coordinators/PlayCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class PlayCoordinator: Coordinator {
init(navigationController: UINavigationController) {
self.navigationController = navigationController
// Configure the tab bar item here
navigationController.tabBarItem = UITabBarItem(title: "Settings", image: UIImage(systemName: "gear"), tag: 1)
navigationController.isNavigationBarHidden = true
navigationController.tabBarItem.image = TabBar.play.systemImage
}

func start() {
Expand All @@ -24,6 +25,8 @@ class PlayCoordinator: Coordinator {

func showChessVC() {
let vc = UIStoryboard.instantiate(ChessViewController.self, from: Storyboards.main)
vc.coordinator = self
vc.hidesBottomBarWhenPushed = true
navigationController.pushViewController(vc, animated: true)
}
}
14 changes: 11 additions & 3 deletions Chess/Coordinators/ProfileCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,25 @@ class ProfileCoordinator: Coordinator {
init(navigationController: UINavigationController) {
self.navigationController = navigationController
// Configure the tab bar item here
navigationController.tabBarItem = UITabBarItem(title: "Settings", image: UIImage(systemName: "gear"), tag: 1)
navigationController.isNavigationBarHidden = true
navigationController.tabBarItem.image = TabBar.profile.systemImage
}

func start() {
let vc = UIStoryboard.instantiate(ProfileViewController.self, from: Storyboards.profile)
vc.coordinator = self
navigationController.pushViewController(vc, animated: false)
self.navigationController.pushViewController(vc, animated: false)
}

func showSettings() {
let vc = UIStoryboard.instantiate(SettingsViewController.self, from: Storyboards.settings)
navigationController.pushViewController(vc, animated: true)
vc.coordinator = self
self.navigationController.pushViewController(vc, animated: true)
}

func showSettings(of setting: SettingsDestination) {
let vc = UIStoryboard.instantiate(SettingsDetailViewController.self, from: Storyboards.settings)
vc.viewModel.currentSetting = setting
self.navigationController.pushViewController(vc, animated: true)
}
}
61 changes: 0 additions & 61 deletions Chess/MVVM/View/MainTabBarController.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ChessViewController: UIViewController {
@IBOutlet private weak var boardCollectionView: UICollectionView!
@IBOutlet private weak var playerTwoCollectionView: UICollectionView!

weak var coordinator: Coordinator?
public let viewModel = ChessViewModel()

override func viewDidLoad() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ModeSelectionViewController: UIViewController {
@IBOutlet private weak var navBar: UIView!
@IBOutlet private weak var titleLabel: UILabel!

weak var coordinator: Coordinator?
weak var coordinator: PlayCoordinator?
private var optionButtons: [UIButton] = []

private let stackView: UIStackView = {
Expand Down Expand Up @@ -89,9 +89,7 @@ class ModeSelectionViewController: UIViewController {
let mode = PlayerMode.allCases.first(where: {$0.string == text}) {
AppPreferences.shared.currentPlayerMode = mode
if mode == .passAndPlay {
let chessVC = UIStoryboard.instantiate(ChessViewController.self, from: Storyboards.main)
chessVC.hidesBottomBarWhenPushed = true
self.navigationController?.pushViewController(chessVC, animated: true)
self.coordinator?.showChessVC()
} else {
self.showAlert(title: Strings.vsComputerAlert.title, message: Strings.vsComputerAlert.description)
}
Expand Down
6 changes: 2 additions & 4 deletions Chess/MVVM/View/Profile/ProfileViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ProfileViewController: UIViewController {

@IBOutlet private weak var tableView: UITableView!

weak var coordinator: Coordinator?
weak var coordinator: ProfileCoordinator?
private let viewModel = ProfileViewModel()

override func viewDidLoad() {
Expand All @@ -31,9 +31,7 @@ class ProfileViewController: UIViewController {
}

@IBAction func settingsButtonTapped(_ sender: Any) {
let settingsVC = UIStoryboard.instantiate(SettingsViewController.self, from: Storyboards.settings)
settingsVC.hidesBottomBarWhenPushed = true
self.navigationController?.pushViewController(settingsVC, animated: true)
coordinator?.showSettings()
}
}

Expand Down
8 changes: 3 additions & 5 deletions Chess/MVVM/View/Settings/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class SettingsViewController: UIViewController {

@IBOutlet private weak var tableView: UITableView!

weak var coordinator: ProfileCoordinator?
private let viewModel = SettingsViewModel()

override func viewDidLoad() {
Expand Down Expand Up @@ -72,12 +73,9 @@ extension SettingsViewController: UITableViewDelegate, UITableViewDataSource {

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
let setting = self.viewModel.sections[indexPath.section].items[indexPath.row]
let setting = self.viewModel.getSettings(at: indexPath)
if setting.details.type == .navigation {
let vc = UIStoryboard.instantiate(SettingsDetailViewController.self, from: Storyboards.settings)
vc.viewModel.currentSetting = setting
self.navigationController?.pushViewController(vc, animated: true)

coordinator?.showSettings(of: setting)
}
}
}
9 changes: 7 additions & 2 deletions Chess/MVVM/View/SplashViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ class SplashViewController: UIViewController {
}

private func navigateToNextPage() {
guard let window = view.window else { return }
window.rootViewController = MainTabBarController()
guard let window = view.window, let delegate = view.window?.windowScene?.delegate as? SceneDelegate else { return }
let tabBarController = UITabBarController()
let coordinator = MainCoordinator(tabBarController: tabBarController)
coordinator.start()
delegate.coordinator = coordinator
window.rootViewController = tabBarController
window.makeKeyAndVisible()
}
}
5 changes: 5 additions & 0 deletions Chess/MVVM/ViewModel/SettingsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//
// Created by Philips Jose on 30/01/26.
//
import Foundation

enum SettingType {
case toggle
Expand Down Expand Up @@ -63,4 +64,8 @@ class SettingsViewModel {
public func setupData() {
sections = SettingsSection.allCases
}

public func getSettings(at indexPath: IndexPath) -> SettingsDestination {
return sections[indexPath[0]].items[indexPath[1]]
}
}
Loading