Commit bdca0e18 by Demid Merzlyakov

AppCoordinator can open screens now.

parent 1460b447
......@@ -40,6 +40,30 @@ class AppCoordinator: Coordinator {
tabBarController.setupTabBar()
}
public func openToday() {
tabBarController.selectedIndex = AppTabBarController.AppTab.today.rawValue
}
public func openForecast(timePeriod: TimePeriod?) {
let forecastIndex = AppTabBarController.AppTab.forecast.rawValue
tabBarController.selectedIndex = forecastIndex
if let timePeriod = timePeriod {
if let forecastCoordinator = childCoordinators[forecastIndex] as? ForecastCoordinator {
forecastCoordinator.open(timePeriod: timePeriod)
}
}
}
public func openRadar() {
tabBarController.selectedIndex = AppTabBarController.AppTab.radar.rawValue
}
public func openNotifications() {
let notificationsCoordinator = NotificationsCoordinator(parentViewController: tabBarController)
notificationsCoordinator.parentCoordinator = self
notificationsCoordinator.start()
}
func viewControllerDidEnd(controller: UIViewController) {
//
}
......
......@@ -12,6 +12,7 @@ class ForecastCoordinator: Coordinator {
private let forecastViewModel = ForecastViewModel(locationManager: LocationManager.shared)
private let navigationController = UINavigationController(nibName: nil, bundle: nil)
private var tabBarController:UITabBarController?
private var forecastViewController: ForecastViewController?
//Public
var childCoordinators = [Coordinator]()
......@@ -25,6 +26,11 @@ class ForecastCoordinator: Coordinator {
let forecastViewController = ForecastViewController(viewModel: forecastViewModel)
navigationController.viewControllers = [forecastViewController]
tabBarController?.add(viewController: navigationController)
self.forecastViewController = forecastViewController
}
public func open(timePeriod: TimePeriod) {
self.forecastViewController?.switchTo(timePeriod: timePeriod)
}
func viewControllerDidEnd(controller: UIViewController) {
......
......@@ -7,16 +7,17 @@
import UIKit
private enum AppTab:Int, CaseIterable {
case today = 0
case forecast = 1
case radar = 2
case menu = 3
}
class AppTabBarController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
}
public enum AppTab:Int, CaseIterable {
case today = 0
case forecast = 1
case radar = 2
case menu = 3
}
public func setupTabBar() {
......
......@@ -67,13 +67,19 @@ class ForecastViewController: UIViewController {
}
}
public func switchTo(timePeriod: TimePeriod) {
if self.timePeriodControl.selectedSegmentIndex != timePeriod.rawValue {
self.timePeriodControl.selectedSegmentIndex = timePeriod.rawValue
}
forecastCellFactory.setTimePeriod(timePeriod: timePeriod)
self.tableView.reloadData()
}
@objc private func handleSegmentDidChange() {
guard let timePeriod = TimePeriod(rawValue: self.timePeriodControl.selectedSegmentIndex) else {
return
}
forecastCellFactory.setTimePeriod(timePeriod: timePeriod)
self.tableView.reloadData()
self.switchTo(timePeriod: timePeriod)
}
@objc private func handleCityButton() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment