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.
236 lines
8.7 KiB
236 lines
8.7 KiB
//
|
|
// ExchangeRateViewController.swift
|
|
// GMERemittance
|
|
//
|
|
// Created by gme_2 on 20/08/2018.
|
|
// Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import Hex
|
|
|
|
enum PaymentMode: String {
|
|
case cashDelivery = "cash"
|
|
case bankDeposite = "bank"
|
|
case homeDelivery = "home"
|
|
}
|
|
|
|
class ExchangeRateViewControllerV2: UIViewController {
|
|
|
|
@IBOutlet weak var collectionView: UICollectionView!
|
|
@IBOutlet weak var exchangeBackground1: UIView!
|
|
@IBOutlet weak var exchangeBackground2: UIView!
|
|
@IBOutlet weak var dropDownImageView: UIImageView!
|
|
@IBOutlet weak var backgroundViewCountryLabel1: UIView!
|
|
@IBOutlet weak var backgroundViewCountryLabel2: UIView!
|
|
@IBOutlet weak var countryListStackView: UIStackView!
|
|
@IBOutlet weak var countryCodeLabel: UILabel!
|
|
@IBOutlet weak var countryFlagImage: UIImageView!
|
|
|
|
|
|
var countryListTapGuesture: UITapGestureRecognizer?
|
|
|
|
var exchangeModels: [ExchangeRateModel] = []
|
|
|
|
var selectedPaymentIndex: IndexPath = IndexPath.init(row: 0, section: 0)
|
|
|
|
|
|
var exchangeRateModels: [ExchangeRateModel] = []
|
|
|
|
var selectedExchageRateModel: ExchangeRateModel? {
|
|
didSet {
|
|
self.countryCodeLabel.text = self.selectedExchageRateModel?.countryCode
|
|
if let image = CountryFlag().getFlagfor(countryCode: self.selectedExchageRateModel?.countryCode ?? "") {
|
|
self.countryFlagImage.image = image
|
|
}
|
|
self.collectionView.reloadData()
|
|
}
|
|
}
|
|
|
|
// Life Cycle
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
setup()
|
|
setupDelegates()
|
|
setupTargets()
|
|
setupNavigation()
|
|
createTestModel()
|
|
// todo: show default native country and falg
|
|
// Do any additional setup after loading the view.
|
|
}
|
|
|
|
|
|
override func viewWillAppear(_ animated: Bool) {
|
|
super.viewWillAppear(animated)
|
|
self.title = "Today's Rate"
|
|
}
|
|
|
|
|
|
// IBActions
|
|
|
|
@objc func showCountryList(_ sender: UITapGestureRecognizer) {
|
|
print("show Country List")
|
|
let viewcontroller = UIStoryboard.init(name: "TableViewPicker", bundle: nil).instantiateViewController(withIdentifier: "TablePickerViewController") as! TablePickerViewController
|
|
viewcontroller.data = self.exchangeRateModels
|
|
viewcontroller.type = TablePickerViewTitle.country
|
|
viewcontroller.doneAction = self.countrySelected
|
|
// viewcontroller.defaultSelectedData = [self.selectedExchageRateModel]
|
|
self.present(viewcontroller, animated: true, completion: nil)
|
|
}
|
|
|
|
|
|
// function
|
|
func countrySelected(model: [ExchangeRateModel]) {
|
|
self.selectedExchageRateModel = model.first
|
|
print(model.first?.country)
|
|
// show country with flag.
|
|
}
|
|
|
|
|
|
private func setupTargets() {
|
|
let tapGuesture = UITapGestureRecognizer(target: self, action: #selector(self.showCountryList(_:)))
|
|
self.countryListTapGuesture = tapGuesture
|
|
self.countryListStackView.addGestureRecognizer(self.countryListTapGuesture!)
|
|
|
|
}
|
|
|
|
private func setupDelegates() {
|
|
self.collectionView.delegate = self
|
|
self.collectionView.dataSource = self
|
|
}
|
|
|
|
private func setup() {
|
|
let dropDownImage = #imageLiteral(resourceName: "dropdown_white").withRenderingMode(UIImageRenderingMode.alwaysTemplate)
|
|
let image = dropDownImage
|
|
self.dropDownImageView.image = image
|
|
self.dropDownImageView.tintColor = UIColor.white
|
|
|
|
// corner Radius
|
|
[backgroundViewCountryLabel1, backgroundViewCountryLabel2].forEach({
|
|
$0?.layer.cornerRadius = 5
|
|
})
|
|
|
|
[exchangeBackground1, exchangeBackground2].forEach({
|
|
$0?.layer.borderWidth = 1
|
|
$0?.layer.borderColor = UIColor.init(hex: "#E0E0E0").cgColor
|
|
$0?.layer.cornerRadius = 5
|
|
})
|
|
}
|
|
|
|
|
|
|
|
private func setupNavigation() {
|
|
|
|
var backBtnImage = #imageLiteral(resourceName: "backIconBlack")
|
|
backBtnImage = backBtnImage.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
|
|
self.navigationController!.navigationBar.backIndicatorImage = backBtnImage
|
|
self.navigationController!.navigationBar.backIndicatorTransitionMaskImage = backBtnImage
|
|
self.navigationController?.navigationBar.barTintColor = UIColor.white
|
|
}
|
|
}
|
|
|
|
|
|
extension ExchangeRateViewControllerV2: UICollectionViewDelegate {
|
|
|
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
|
|
|
let cell = collectionView.cellForItem(at: indexPath) as! ExchangeRateCollectionViewCell
|
|
self.selectedPaymentIndex = indexPath
|
|
self.collectionView.reloadData()
|
|
}
|
|
}
|
|
|
|
extension ExchangeRateViewControllerV2: UICollectionViewDataSource {
|
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
return self.selectedExchageRateModel?.availableServices?.count ?? 0
|
|
}
|
|
|
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
|
let service = self.selectedExchageRateModel?.availableServices?.elementAt(index: indexPath.row)
|
|
guard let index = PaymentMode.init(rawValue: service?.type ?? "") else {
|
|
return UICollectionViewCell()
|
|
|
|
}
|
|
switch index {
|
|
case .bankDeposite:
|
|
return configureBankDepositeCell(collectionView: collectionView, indexPath: indexPath)
|
|
case .cashDelivery:
|
|
return configureCashDeliveryCell(collectionView: collectionView, indexPath: indexPath)
|
|
case .homeDelivery:
|
|
return configureHomeDeliveryCell(collectionView: collectionView, indexPath: indexPath)
|
|
}
|
|
}
|
|
|
|
func configureBankDepositeCell(collectionView: UICollectionView, indexPath: IndexPath) -> UICollectionViewCell {
|
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ExchangeRateCollectionViewCell", for: indexPath) as! ExchangeRateCollectionViewCell
|
|
cell.cellSelected = self.selectedPaymentIndex == indexPath
|
|
cell.image = #imageLiteral(resourceName: "ic_bank")
|
|
cell.setup()
|
|
return cell
|
|
}
|
|
|
|
func configureCashDeliveryCell(collectionView: UICollectionView, indexPath: IndexPath) -> UICollectionViewCell {
|
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ExchangeRateCollectionViewCell", for: indexPath) as! ExchangeRateCollectionViewCell
|
|
cell.cellSelected = self.selectedPaymentIndex == indexPath
|
|
cell.image = #imageLiteral(resourceName: "ic_cash")
|
|
cell.setup()
|
|
return cell
|
|
}
|
|
|
|
func configureHomeDeliveryCell(collectionView: UICollectionView, indexPath: IndexPath) -> UICollectionViewCell {
|
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ExchangeRateCollectionViewCell", for: indexPath) as! ExchangeRateCollectionViewCell
|
|
cell.cellSelected = self.selectedPaymentIndex == indexPath
|
|
cell.image = #imageLiteral(resourceName: "ic_homeDelivery")
|
|
cell.setup()
|
|
return cell
|
|
}
|
|
}
|
|
|
|
|
|
extension ExchangeRateViewControllerV2 {
|
|
func createTestModel() {
|
|
let service1 = PaymentServiceType()
|
|
service1.type = "cash"
|
|
service1.subtitle = "1 business day"
|
|
|
|
let service2 = PaymentServiceType()
|
|
service2.type = "bank"
|
|
service2.subtitle = "2 hour"
|
|
|
|
let service3 = PaymentServiceType()
|
|
service3.type = "home"
|
|
service3.subtitle = "5 business day"
|
|
|
|
let model = ExchangeRateModel()
|
|
model.country = "Nepal"
|
|
model.countryCode = "Np"
|
|
model.currency = "NRS"
|
|
model.availableServices = [service2, service1]
|
|
|
|
let model1 = ExchangeRateModel()
|
|
model1.country = "Kore"
|
|
model1.countryCode = "krw"
|
|
model1.currency = "NRS"
|
|
model1.availableServices = [service2, service1, service3]
|
|
|
|
let model2 = ExchangeRateModel()
|
|
model2.country = "India"
|
|
model2.countryCode = "in"
|
|
model2.currency = "NRS"
|
|
model2.availableServices = [service2]
|
|
|
|
let model3 = ExchangeRateModel()
|
|
model3.country = "China"
|
|
model3.countryCode = "cn"
|
|
model3.currency = "NRS"
|
|
model3.availableServices = [service2, service1, service3]
|
|
|
|
let model4 = ExchangeRateModel()
|
|
model4.country = "Cambodia"
|
|
model4.countryCode = "Kh"
|
|
model4.currency = "NRS"
|
|
model4.availableServices = [service2, service1, service3]
|
|
|
|
self.exchangeRateModels = [model, model1, model2, model3, model4]
|
|
}
|
|
}
|