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.
 
 
 
 

183 lines
6.1 KiB

//
// WithdrawViewController.swift
// GMERemittance
//
// Created by Fm-user on 1/12/18.
// Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
//
import UIKit
class WithdrawViewController: UIViewController {
@IBOutlet weak var textViewWithdraw: UITextView!
@IBOutlet weak var textFieldAmount: UITextField!
private var withdrawviewmodel = WithdrawViewModel()
private var activityIndicator: UIActivityIndicatorView = UIActivityIndicatorView()
override func viewDidLoad() {
super.viewDidLoad()
setUpNavBar(id: 201, title: "Withdraw")
setUpAnotherLoginListener(genericviewmodel: withdrawviewmodel)
hideKeyboardWhenTappedAround()
// Do any additional setup after loading the view.
textViewWithdraw.delegate = self
textViewWithdraw.text = "Reason for withdraw"
textViewWithdraw.textColor = UIColor(red:0.78, green:0.78, blue:0.80, alpha:1.0)
withdrawviewmodel.withdrawConnectionTimeOut.value = nil
/**
connection timeout
*/
withdrawviewmodel.withdrawConnectionTimeOut.bind { [unowned self] in
guard $0 != nil else {
return
}
self.enableUserInteractions()
self.dismissActivityIndicator(activityIndicator: self.activityIndicator)
self.popUpMessage(value: 20)
}
withdrawviewmodel.internetConnection.value = nil
/**
internet check
*/
withdrawviewmodel.internetConnection.bind { [unowned self] in
guard $0 != nil else {
return
}
self.enableUserInteractions()
self.dismissActivityIndicator(activityIndicator: self.activityIndicator)
self.popUpMessage(value: 15)
}
/**
Update the for send and withdraw request
*/
withdrawviewmodel.requestProcessed.bind { [unowned self] in
guard $0 != nil else {
return
}
self.dismissActivityIndicator(activityIndicator: self.activityIndicator)
self.enableUserInteractions()
guard $0! else {
self.popUpMessageError(value: 10, message: self.withdrawviewmodel.getErrorMessage())
return
}
guard let navController = self.navigationController else {
return
}
if let popUpViewController = UIStoryboard.init(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "popUpInfo") as? PopUpGeneralInfo {
popUpViewController.indexValue = 3
navController.addChildViewController(popUpViewController)
popUpViewController.view.frame = navController.view.bounds
navController.view.addSubview(popUpViewController.view)
popUpViewController.didMove(toParentViewController: navController)
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func submitWithdrawRequest(_ sender: Any) {
withdrawviewmodel.setParam(amount: textFieldAmount.text!, reason: textViewWithdraw.text)
switch withdrawviewmodel.validateAmountandReason() {
case .Valid:
confirmRequest()
case .InValid(let error):
self.popUpMessageError(value: 11, message: error)
}
}
/**
Conforming for request
*/
func confirmRequest() {
let alertController = UIAlertController(title: "Enter your login password", message: nil, preferredStyle: .alert)
alertController.addTextField { (textField : UITextField!) -> Void in
textField.placeholder = "Password"
textField.isSecureTextEntry = true
textField.tag = 51
textField.delegate = self
}
let confirmAction = UIAlertAction(title: "Confirm", style: .default, handler: {
alert -> Void in
let valueTextField = alertController.textFields![0] as UITextField
if valueTextField.text != "" {
self.disableUserInteractions()
self.showActivityIndicator(activityIndicator: self.activityIndicator)
self.withdrawviewmodel.sendWithdrawRequest(password: valueTextField.text!)
} else {
self.popUpMessageError(value: 11, message: "Password was missing")
}
})
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: {
(action : UIAlertAction!) -> Void in
})
cancelAction.setValue(UIColor.black, forKey: "titleTextColor")
confirmAction.setValue(UIColor(hex:0xEC1C24), forKey: "titleTextColor")
alertController.addAction(cancelAction)
alertController.addAction(confirmAction)
self.present(alertController, animated: true, completion: nil)
}
}
extension WithdrawViewController: UITextViewDelegate {
func textViewDidBeginEditing(_ textViewWithdraw: UITextView) {
if textViewWithdraw.textColor == UIColor(red:0.78, green:0.78, blue:0.80, alpha:1.0) {
textViewWithdraw.text = nil
textViewWithdraw.textColor = UIColor(red:0.29, green:0.29, blue:0.29, alpha:1.0)
}
}
func textViewDidEndEditing(_ textViewWithdraw: UITextView) {
if textViewWithdraw.text.isEmpty {
textViewWithdraw.text = "Reason for withdraw"
textViewWithdraw.textColor = UIColor(red:0.78, green:0.78, blue:0.80, alpha:1.0)
}
}
}
extension WithdrawViewController: UITextFieldDelegate {
func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
if textField.tag == 51 {
textField.tag = 0
return false
}
return true
}
}