5 // Created by Pawel Dabrowski on 29/05/2018.
6 // Copyright © 2018 Fundacja Nowoczesna Polska. All rights reserved.
14 class MainNavigator: NSObject {
16 fileprivate var window: UIWindow
17 fileprivate var navigator: WLNavigationController!
18 private var menuViewController: MenuViewController!
20 init(window: UIWindow){
24 SideMenuManager.default.menuPresentMode = .menuSlideIn
25 SideMenuManager.default.menuFadeStatusBar = false
26 SideMenuManager.default.menuWidth = 245
28 navigator = WLNavigationController(rootViewController: LibraryViewController.instance())
29 window.rootViewController = navigator
30 window.makeKeyAndVisible()
32 let menuLeftNavigationController = UISideMenuNavigationController.instance()
33 SideMenuManager.default.menuLeftNavigationController = menuLeftNavigationController
34 menuViewController = menuLeftNavigationController.viewControllers[0] as! MenuViewController
37 func updateSettingsViewIfPresented() {
38 if let settingsViewController = navigator.viewControllers.last as? SettingsViewController {
39 settingsViewController.updateNotificationsSwitchValue()
44 menuViewController.setup()
48 menuViewController.setup()
49 presentLibrary(dismissSideMenu: false)
53 func presentLibrary(dismissSideMenu: Bool){
54 setRootViewController(controller: LibraryViewController.instance(), dismissSideMenu: dismissSideMenu, menuItem: .wolne_lektury)
57 func presentSearch() {
58 setRootViewController(controller: SearchViewController.instance(type: .search), menuItem: .catalog)
62 setRootViewController(controller: NewsViewController.instance(dataSource: nil), menuItem: .news)
65 func presentPremiumBook(bookSlug: String) {
67 setRootViewController(controller: BookDetailsViewController.instance(bookSlug: bookSlug), menuItem: .premium)
70 func presentPayPalForm() {
71 appDelegate.presentPaypal(fromViewController: navigator)
74 func presentSettings() {
75 setRootViewController(controller: SettingsViewController.instance(), menuItem: .settings)
79 setRootViewController(controller: AboutViewController.instance(), menuItem: .about)
82 func presentSupportUs() {
83 setRootViewController(controller: SupportUsViewController.instance())
86 func presentBookList(listViewControllerType: ListViewControllerType){
87 let vc = BookListViewController.instance(listViewControllerType: listViewControllerType, dataSource: nil)
89 setRootViewController(controller: vc, menuItem: listViewControllerType.menuItem)
92 func presentDownloaded(){
93 let vc = DownloadedListViewController.instance()
94 setRootViewController(controller: vc, menuItem: .downloaded)
97 func presentLogin(push: Bool){
98 let vc = LoginViewController.instance()
100 navigator.pushViewController(vc, animated: true)
103 setRootViewController(controller: vc)
108 public func setRootViewController(controller: UIViewController, dismissSideMenu: Bool = true, menuItem: MenuItem? = nil){
109 if appDelegate.sideMenuNavigationController != nil && dismissSideMenu{
110 appDelegate.sideMenuNavigationController?.dismiss(animated: true, completion: nil)
113 if let menuItem = menuItem {
114 menuViewController.selectItem(menuItem: menuItem)
116 navigator.setViewControllers([controller], animated: false)