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

//
// ReviewMobileRechargeViewController.swift
// GMERemittance
//
// Created by Sujal on 1/13/18.
// Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
//
import UIKit
class MobileRechargeReviewViewController: UIViewController {
@IBOutlet weak var labelRechargeAmount: UILabel!
@IBOutlet weak var labelRechargeTo: UILabel!
var mobilerechargeviewmodel: MobileRechargeViewModel?
var convertedData: String?
var transferAmount: String?
var operatorUrl: String?
private var activityIndicator: UIActivityIndicatorView = UIActivityIndicatorView()
@IBAction func rechargePhone(_ sender: Any) {
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 //unique identifier set
textField.delegate = self
}
let confirmAction = UIAlertAction(title: "Confirm", style: .default, handler: {
alert -> Void in
let valueTextField = alertController.textFields![0] as UITextField
if valueTextField.text != "" {
if self.transferAmount != "0"{
self.disableUserInteractions()
self.showActivityIndicator(activityIndicator: self.activityIndicator)
if let transferAmount = self.transferAmount{
self.mobilerechargeviewmodel?.topUpMobile(password: valueTextField.text!,transferAmount: transferAmount)
}
}
} else {
self.popUpMessageInfo(value: 16, title: "Password was missing", message: "Could not complete your request")
}
})
let cancelAction = UIAlertAction(title: "Cancel", style: .destructive, 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)
}
override func viewDidLoad() {
super.viewDidLoad()
guard mobilerechargeviewmodel != nil else {
return
}
setUpAnotherLoginListener(genericviewmodel: mobilerechargeviewmodel!)
mobilerechargeviewmodel?.mobileToppedUp.value = nil
setUpNavBar(id: 201, title: "Mobile Recharge")
let rechargeAmountColor = UIColor(red: 236/255, green: 28/255.0, blue: 36/255, alpha: 1.0)
let rechargeAmountMessage1: NSString = "Recharge Amount: "
let amount = (self.transferAmount)! + " \(convertedData!)"
let rechargeAmountMessage2: NSString = amount as NSString
let mutableRechargeAmountMessage1 = NSMutableAttributedString(string: rechargeAmountMessage1 as String)
let mutableRechargeAmountMessage2 = NSMutableAttributedString(string: rechargeAmountMessage2 as String)
mutableRechargeAmountMessage2.addAttribute(NSAttributedStringKey.foregroundColor, value: rechargeAmountColor, range: NSRange(location:0, length: rechargeAmountMessage2.length))
let mutableRechargeAmountMessage = NSMutableAttributedString()
mutableRechargeAmountMessage.append(mutableRechargeAmountMessage1)
mutableRechargeAmountMessage.append(mutableRechargeAmountMessage2)
labelRechargeTo.text = "Recharge To: " + (mobilerechargeviewmodel?.getCountryCode())! + " " + (mobilerechargeviewmodel?.getMobileNumber())!
labelRechargeAmount.attributedText = mutableRechargeAmountMessage
mobilerechargeviewmodel?.rechargeConnectionTimeOut.value = nil
/**
connection timeout
*/
mobilerechargeviewmodel?.rechargeConnectionTimeOut.bind { [unowned self] in
guard $0 != nil else {
return
}
self.enableUserInteractions()
self.dismissActivityIndicator(activityIndicator: self.activityIndicator)
self.popUpMessage(value: 20)
}
mobilerechargeviewmodel?.internetConnection.value = nil
mobilerechargeviewmodel?.internetConnection.bind { [unowned self] in
guard $0 != nil else {
return
}
self.enableUserInteractions()
self.dismissActivityIndicator(activityIndicator: self.activityIndicator)
self.popUpMessage(value: 15)
}
mobilerechargeviewmodel?.mobileToppedUp.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.mobilerechargeviewmodel?.getErrorMessage())!)
return
}
self.performSegue(withIdentifier: "successfulRecharge", sender: nil)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "successfulRecharge" {
let detailRechargeViewController = segue.destination as! MobileRechargeDetailsViewController
detailRechargeViewController.convertedData = self.convertedData
detailRechargeViewController.transferAmount = self.transferAmount
detailRechargeViewController.rechargeResponse = self.mobilerechargeviewmodel?.getRechargeResponseDetails()
detailRechargeViewController.transactionNumber = self.mobilerechargeviewmodel?.getTransactionNumber()
detailRechargeViewController.operatorUrl = self.operatorUrl
}
}
}
extension MobileRechargeReviewViewController: UITextFieldDelegate {
func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
if textField.tag == 51 {
textField.tag = 0
return false
}
return true
}
}