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.

165 lines
6.4 KiB

6 years ago
  1. //
  2. // ReviewMobileRechargeViewController.swift
  3. // GMERemittance
  4. //
  5. // Created by Sujal on 1/13/18.
  6. // Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import UIKit
  9. class MobileRechargeReviewViewController: UIViewController {
  10. @IBOutlet weak var labelRechargeAmount: UILabel!
  11. @IBOutlet weak var labelRechargeTo: UILabel!
  12. var mobilerechargeviewmodel: MobileRechargeViewModel?
  13. var convertedData: String?
  14. var transferAmount: String?
  15. var operatorUrl: String?
  16. private var activityIndicator: UIActivityIndicatorView = UIActivityIndicatorView()
  17. @IBAction func rechargePhone(_ sender: Any) {
  18. let alertController = UIAlertController(title: "Enter your login password", message: nil, preferredStyle: .alert)
  19. alertController.addTextField { (textField : UITextField!) -> Void in
  20. textField.placeholder = "Password"
  21. textField.isSecureTextEntry = true
  22. textField.tag = 51 //unique identifier set
  23. textField.delegate = self
  24. }
  25. let confirmAction = UIAlertAction(title: "Confirm", style: .default, handler: {
  26. alert -> Void in
  27. let valueTextField = alertController.textFields![0] as UITextField
  28. if valueTextField.text != "" {
  29. if self.transferAmount != "0"{
  30. self.disableUserInteractions()
  31. self.showActivityIndicator(activityIndicator: self.activityIndicator)
  32. if let transferAmount = self.transferAmount{
  33. self.mobilerechargeviewmodel?.topUpMobile(password: valueTextField.text!,transferAmount: transferAmount)
  34. }
  35. }
  36. } else {
  37. self.popUpMessageInfo(value: 16, title: "Password was missing", message: "Could not complete your request")
  38. }
  39. })
  40. let cancelAction = UIAlertAction(title: "Cancel", style: .destructive, handler: {
  41. (action : UIAlertAction!) -> Void in
  42. })
  43. cancelAction.setValue(UIColor.black, forKey: "titleTextColor")
  44. confirmAction.setValue(UIColor(hex:0xEC1C24), forKey: "titleTextColor")
  45. alertController.addAction(cancelAction)
  46. alertController.addAction(confirmAction)
  47. self.present(alertController, animated: true, completion: nil)
  48. }
  49. override func viewDidLoad() {
  50. super.viewDidLoad()
  51. guard mobilerechargeviewmodel != nil else {
  52. return
  53. }
  54. setUpAnotherLoginListener(genericviewmodel: mobilerechargeviewmodel!)
  55. mobilerechargeviewmodel?.mobileToppedUp.value = nil
  56. setUpNavBar(id: 201, title: "Mobile Recharge")
  57. let rechargeAmountColor = UIColor(red: 236/255, green: 28/255.0, blue: 36/255, alpha: 1.0)
  58. let rechargeAmountMessage1: NSString = "Recharge Amount: "
  59. let amount = (self.transferAmount)! + " \(convertedData!)"
  60. let rechargeAmountMessage2: NSString = amount as NSString
  61. let mutableRechargeAmountMessage1 = NSMutableAttributedString(string: rechargeAmountMessage1 as String)
  62. let mutableRechargeAmountMessage2 = NSMutableAttributedString(string: rechargeAmountMessage2 as String)
  63. mutableRechargeAmountMessage2.addAttribute(NSAttributedStringKey.foregroundColor, value: rechargeAmountColor, range: NSRange(location:0, length: rechargeAmountMessage2.length))
  64. let mutableRechargeAmountMessage = NSMutableAttributedString()
  65. mutableRechargeAmountMessage.append(mutableRechargeAmountMessage1)
  66. mutableRechargeAmountMessage.append(mutableRechargeAmountMessage2)
  67. labelRechargeTo.text = "Recharge To: " + (mobilerechargeviewmodel?.getCountryCode())! + " " + (mobilerechargeviewmodel?.getMobileNumber())!
  68. labelRechargeAmount.attributedText = mutableRechargeAmountMessage
  69. mobilerechargeviewmodel?.rechargeConnectionTimeOut.value = nil
  70. /**
  71. connection timeout
  72. */
  73. mobilerechargeviewmodel?.rechargeConnectionTimeOut.bind { [unowned self] in
  74. guard $0 != nil else {
  75. return
  76. }
  77. self.enableUserInteractions()
  78. self.dismissActivityIndicator(activityIndicator: self.activityIndicator)
  79. self.popUpMessage(value: 20)
  80. }
  81. mobilerechargeviewmodel?.internetConnection.value = nil
  82. mobilerechargeviewmodel?.internetConnection.bind { [unowned self] in
  83. guard $0 != nil else {
  84. return
  85. }
  86. self.enableUserInteractions()
  87. self.dismissActivityIndicator(activityIndicator: self.activityIndicator)
  88. self.popUpMessage(value: 15)
  89. }
  90. mobilerechargeviewmodel?.mobileToppedUp.bind { [unowned self] in
  91. guard $0 != nil else {
  92. return
  93. }
  94. self.dismissActivityIndicator(activityIndicator: self.activityIndicator)
  95. self.enableUserInteractions()
  96. guard $0! else {
  97. self.popUpMessageError(value: 10, message: (self.mobilerechargeviewmodel?.getErrorMessage())!)
  98. return
  99. }
  100. self.performSegue(withIdentifier: "successfulRecharge", sender: nil)
  101. }
  102. }
  103. override func didReceiveMemoryWarning() {
  104. super.didReceiveMemoryWarning()
  105. }
  106. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  107. if segue.identifier == "successfulRecharge" {
  108. let detailRechargeViewController = segue.destination as! MobileRechargeDetailsViewController
  109. detailRechargeViewController.convertedData = self.convertedData
  110. detailRechargeViewController.transferAmount = self.transferAmount
  111. detailRechargeViewController.rechargeResponse = self.mobilerechargeviewmodel?.getRechargeResponseDetails()
  112. detailRechargeViewController.transactionNumber = self.mobilerechargeviewmodel?.getTransactionNumber()
  113. detailRechargeViewController.operatorUrl = self.operatorUrl
  114. }
  115. }
  116. }
  117. extension MobileRechargeReviewViewController: UITextFieldDelegate {
  118. func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
  119. if textField.tag == 51 {
  120. textField.tag = 0
  121. return false
  122. }
  123. return true
  124. }
  125. }