|
|
@ -10,42 +10,8 @@ import Foundation |
|
|
|
import UIKit |
|
|
|
|
|
|
|
class MainWireframe { |
|
|
|
private static var _userShared: MainWireframe? |
|
|
|
private static var _salesShared: MainWireframe? = MainWireframe(false) |
|
|
|
|
|
|
|
static var userShared: MainWireframe { |
|
|
|
if _userShared == nil { |
|
|
|
_userShared = MainWireframe() |
|
|
|
} |
|
|
|
return _userShared! |
|
|
|
} |
|
|
|
static var salesShared: MainWireframe { |
|
|
|
if _salesShared == nil { |
|
|
|
_salesShared = MainWireframe(false) |
|
|
|
} |
|
|
|
return _salesShared! |
|
|
|
} |
|
|
|
|
|
|
|
init(_ isUser: Bool = true) { |
|
|
|
self.isUserWireframe = isUser |
|
|
|
} |
|
|
|
static var shared: MainWireframe? = MainWireframe() |
|
|
|
weak var view: UIViewController! |
|
|
|
|
|
|
|
private var isUserWireframe: Bool |
|
|
|
|
|
|
|
// MARK: Wireframes for user views |
|
|
|
private lazy var homeWireFrame: HomeWireframeInput = {HomeWireframe()}() |
|
|
|
private lazy var moreWireFrame: MoreWireFrameInput = {MoreWireframe()}() |
|
|
|
private lazy var categoriesWireframe: CategoriesWireframeInput = {CategoriesWireframe()}() |
|
|
|
private lazy var favoriteWireframe: FavouritesWireframeInput = {FavouritesWireframe()}() |
|
|
|
private lazy var quickOrderWireframe: QuickOrderWireframeInput = {QuickOrderWireframe()}() |
|
|
|
|
|
|
|
// MARK: Wireframes for sales |
|
|
|
|
|
|
|
private lazy var salesDashboardWireframe: SalesDashboardWireframeInput = {SalesDashboardWireframe()}() |
|
|
|
private lazy var storeListWireframe: StoreListWireframeInput = {StoreListWireframe()}() |
|
|
|
private lazy var salesMoreWireframe: SalesMoreWireFrameInput = {SalesMoreWireframe()}() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
extension MainWireframe: MainWireframeInput { |
|
|
@ -54,7 +20,7 @@ extension MainWireframe: MainWireframeInput { |
|
|
|
func getMainView() -> UIViewController { |
|
|
|
|
|
|
|
let viewController = MainViewController() |
|
|
|
let viewControllers: [UIViewController] = self.isUserWireframe ? self.getUser() : self.getSales() |
|
|
|
let viewControllers: [UIViewController] = self.getViewControllers() |
|
|
|
|
|
|
|
viewController.setup(viewControllers: viewControllers) |
|
|
|
|
|
|
@ -67,74 +33,42 @@ extension MainWireframe: MainWireframeInput { |
|
|
|
return viewController |
|
|
|
} |
|
|
|
|
|
|
|
private func getUser() -> [UIViewController] { |
|
|
|
private func getViewControllers() -> [UIViewController] { |
|
|
|
// home view controller |
|
|
|
let homeViewController = self.homeWireFrame.getMainView() |
|
|
|
let navHomeViewController = UINavigationController(rootViewController: homeViewController) |
|
|
|
|
|
|
|
// user more view controller |
|
|
|
let moreViewController = moreWireFrame.getMainView() |
|
|
|
let navMoreViewController = UINavigationController(rootViewController: moreViewController) |
|
|
|
|
|
|
|
// categories view controller |
|
|
|
let categoriesViewController = categoriesWireframe.getMainView() |
|
|
|
let navCategoriesViewController = UINavigationController(rootViewController: categoriesViewController) |
|
|
|
|
|
|
|
// favorite view controller |
|
|
|
let favoritesViewController = favoriteWireframe.getMainView() |
|
|
|
let navFavoriteViewController = UINavigationController(rootViewController: favoritesViewController) |
|
|
|
|
|
|
|
let quickOrderViewController = quickOrderWireframe.getMainView() |
|
|
|
let navQuickOrderViewController = UINavigationController(rootViewController: quickOrderViewController) |
|
|
|
|
|
|
|
return [navHomeViewController, navCategoriesViewController, navFavoriteViewController, navQuickOrderViewController, navMoreViewController] |
|
|
|
} |
|
|
|
let homeViewController = UIStoryboard.init(name: "Home", bundle: nil).instantiateViewController(withIdentifier: "Home") as! HomeViewController |
|
|
|
let navHomeViewController = UINavigationController(rootViewController: homeViewController) |
|
|
|
|
|
|
|
private func getSales() -> [UIViewController] { |
|
|
|
// sales dashboard |
|
|
|
let salesDashboardViewController = salesDashboardWireframe.getMainView() |
|
|
|
let navSalesDashboardViewController = UINavigationController(rootViewController: salesDashboardViewController) |
|
|
|
// user send money view controller |
|
|
|
let sendMoneyViewController = UIStoryboard.init(name: "RecipientListViewController", bundle: nil).instantiateViewController(withIdentifier: "RecipientListViewController") as! RecipientListViewController |
|
|
|
let navSendMoneyViewController = UINavigationController(rootViewController: sendMoneyViewController) |
|
|
|
|
|
|
|
// store list |
|
|
|
let storeListViewController = storeListWireframe.getMainView() |
|
|
|
let navSalesListViewController = UINavigationController(rootViewController: storeListViewController) |
|
|
|
// Constacts view controller |
|
|
|
let contactsViewController = GmeContactsWireframe().getMainView() |
|
|
|
let navContactsViewController = UINavigationController(rootViewController: contactsViewController) |
|
|
|
|
|
|
|
// store more |
|
|
|
let salesMoreViewController = salesMoreWireframe.getMainView() |
|
|
|
let navSalesMoreViewController = UINavigationController(rootViewController: salesMoreViewController) |
|
|
|
// profile view controller |
|
|
|
let profileViewController = UIStoryboard.init(name: "Profile", bundle: nil).instantiateViewController(withIdentifier: "ProfileViewController") as! ProfileViewController |
|
|
|
let navProfileViewController = UINavigationController(rootViewController: profileViewController) |
|
|
|
|
|
|
|
return [navSalesDashboardViewController, navSalesListViewController, navSalesMoreViewController] |
|
|
|
return [navHomeViewController, navSendMoneyViewController, navContactsViewController, navProfileViewController] |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func show(index: Int) { |
|
|
|
if let view = self.view as? MainViewController { |
|
|
|
view.selectedIndex = index |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func replaceLoginToProfile() { |
|
|
|
// let profileView = self.profileWireframe.getMainView() |
|
|
|
// |
|
|
|
// let nav = UINavigationController(rootViewController: profileView) |
|
|
|
// if let view = self.view as? MainViewController { |
|
|
|
// view.viewControllers?.remove(at: 3) |
|
|
|
// view.viewControllers?.insert(nav, at: 3) |
|
|
|
// } |
|
|
|
// |
|
|
|
// self.show(index: 3) |
|
|
|
} |
|
|
|
|
|
|
|
func showStoreListing () { |
|
|
|
if !self.isUserWireframe { |
|
|
|
self.show(index: 1) |
|
|
|
self.storeListWireframe.changeOrderType(alphabetic: false) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
static func logout() { |
|
|
|
guard let window = (MainWireframe._salesShared?.window ?? MainWireframe._userShared?.window) else {return} |
|
|
|
MainWireframe._salesShared = nil |
|
|
|
MainWireframe._userShared = nil |
|
|
|
LoginWireframe().openMainViewAsNavigationControllerIn(window: window) |
|
|
|
} |
|
|
|
// func showStoreListing () { |
|
|
|
// if !self.isUserWireframe { |
|
|
|
// self.show(index: 1) |
|
|
|
// self.storeListWireframe.changeOrderType(alphabetic: false) |
|
|
|
// } |
|
|
|
// } |
|
|
|
|
|
|
|
} |