You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

233 lines
7.6 KiB

//
// SendMoneyParentViewController.swift
// GMERemittance
//
// Created by gme_2 on 28/08/2018.
//Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
//
import UIKit
protocol HUDStatusDelegate {
func showLoading()
func hideLoading()
}
protocol SendMoneyPaymentModeActionDelegate {
func continueToExchangeAction()
}
protocol SendMoneyExchangeRateActionDelegate {
func continueToVerificationAction()
}
class SendMoneyParentViewController: UIViewController {
enum StateButtons: Int {
case paymentMode = 1
case exchange = 2
case verification = 3
}
struct Constants {
static let stateRedColor = UIColor.init(hex: "#EC1C24")
static let stateGreenColor = UIColor.init(hex: "8CC241")
}
// MARK: IBOutlets
@IBOutlet weak var containerView: UIView!
@IBOutlet weak var paymentModeButton: UIButton!
@IBOutlet weak var exchangeRateButton: UIButton!
@IBOutlet weak var verificationButton: UIButton!
// MARK: Properties
var paymentModeViewController: UIViewController?
var exchangeViewController: UIViewController?
var verificationViewController: UIViewController?
var presenter: SendMoneyParentModuleInterface?
var stateButtons: [UIButton] = []
var state: StateButtons = .paymentMode {
didSet {
self.updateState(state: state)
}
}
var receipient: Recipient? {
didSet {
print( self.receipient?.firstName)
}
}
// MARK: VC's Life cycle
override func viewDidLoad() {
super.viewDidLoad()
self.setup()
self.presenter?.viewIsReady()
self.setupViewControllers()
self.addPaymentModeViewController()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}
// MARK: IBActions
@IBAction func paymentMode(_ sender: UIButton) {
self.addPaymentModeViewController()
self.state = StateButtons.paymentMode
}
@IBAction func exchangeRate(_ sender: UIButton) {
self.addExchangeViewController()
self.state = StateButtons.exchange
}
@IBAction func verification(_ sender: UIButton) {
self.addVerificationViewController()
self.state = StateButtons.verification
}
// MARK: Other Functions
private func setup() {
// all setup should be done here
self.setTitle(title: "Send Money")
self.state = StateButtons.paymentMode
self.configureViews()
}
private func setupNavigationBar() {
}
private func setTitle(title: String) {
self.navigationItem.title = title
}
private func setupViewControllers() {
let paymentModelWireframe = SendMoneyPaymentModeWireframe()
let pvc = paymentModelWireframe.getMainView() as! SendMoneyPaymentModeViewController
pvc.recipient = self.receipient
pvc.hudDelegate = self
pvc.actionDelegate = self
self.paymentModeViewController = pvc
let exchangeViewWireframe = SendMoneyExchangeRateWireframe()
let evc = exchangeViewWireframe.getMainView() as! SendMoneyExchangeRateViewController
evc.reciepient = self.receipient
evc.actionDelegate = self
evc.hudDelegate = self
self.exchangeViewController = evc
let verificationWireframe = SendMoneyVerificationWireframe()
let vvc = verificationWireframe.getMainView() as! SendMoneyVerificationViewController
vvc.reciepient = self.receipient
vvc.hudDelegate = self
self.verificationViewController = vvc
}
private func configureViews() {
self.paymentModeButton.tag = 1
self.exchangeRateButton.tag = 2
self.verificationButton.tag = 3
self.stateButtons = [paymentModeButton,exchangeRateButton, verificationButton ]
[paymentModeButton, exchangeRateButton, verificationButton].forEach({
$0?.rounded()
})
}
func updateState(state: StateButtons) {
switch state {
case .paymentMode:
self.paymentModeButton.backgroundColor = Constants.stateGreenColor
self.exchangeRateButton.backgroundColor = Constants.stateRedColor
self.verificationButton.backgroundColor = Constants.stateRedColor
case .exchange:
self.paymentModeButton.backgroundColor = Constants.stateGreenColor
self.exchangeRateButton.backgroundColor = Constants.stateGreenColor
self.verificationButton.backgroundColor = Constants.stateRedColor
case .verification:
self.paymentModeButton.backgroundColor = Constants.stateGreenColor
self.exchangeRateButton.backgroundColor = Constants.stateGreenColor
self.verificationButton.backgroundColor = Constants.stateGreenColor
}
}
func addPaymentModeViewController() {
guard let paymentModeViewController = self.paymentModeViewController else {return}
self.addChildViewController(paymentModeViewController)
UIView.transition(with: self.containerView, duration: 0.33, options: .transitionCrossDissolve, animations: {
self.containerView.addSubview(paymentModeViewController.view)
}, completion: nil)
paymentModeViewController.view.frame = containerView.bounds
paymentModeViewController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
paymentModeViewController.didMove(toParentViewController: self)
}
func addExchangeViewController() {
guard let exchangeViewController = self.exchangeViewController else {return}
self.addChildViewController(exchangeViewController)
UIView.transition(with: self.containerView, duration: 0.33, options: .transitionCrossDissolve, animations: {
self.containerView.addSubview(exchangeViewController.view)
}, completion: nil)
exchangeViewController.view.frame = containerView.bounds
exchangeViewController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
exchangeViewController.didMove(toParentViewController: self)
}
func addVerificationViewController() {
guard let verificationViewController = self.verificationViewController else {return}
self.addChildViewController(verificationViewController)
UIView.transition(with: self.containerView, duration: 0.33, options: .transitionCrossDissolve, animations: {
self.containerView.addSubview(verificationViewController.view)
}, completion: nil)
verificationViewController.view.frame = containerView.bounds
verificationViewController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
verificationViewController.didMove(toParentViewController: self)
}
}
// MARK: SendMoneyParentViewInterface
extension SendMoneyParentViewController: SendMoneyParentViewInterface {
func show(model: Recipient) {
self.receipient = model
}
}
extension SendMoneyParentViewController: HUDStatusDelegate {
func showLoading() {
self.showProgressHud()
}
func hideLoading() {
self.hideProgressHud()
}
}
extension SendMoneyParentViewController: SendMoneyPaymentModeActionDelegate {
func continueToExchangeAction() {
self.addExchangeViewController()
self.state = StateButtons.exchange
}
}
extension SendMoneyParentViewController: SendMoneyExchangeRateActionDelegate {
func continueToVerificationAction() {
self.addVerificationViewController()
self.state = StateButtons.verification
}
}