// // LoyalityPointsViewController.swift // GME Remit // // Created by Armaan Shrestha on 12/12/2022. //Copyright © 2022 Gobal Money Express Co. Ltd. All rights reserved. // import UIKit class LoyalityPointsViewController: UIViewController { var loyalityPoint: LoyalityPointsModel! { didSet { renderData() } } // MARK: Properties var presenter: LoyalityPointsModuleInterface? // MARK: IBOutlets @IBOutlet weak var titleLabel: UILabel! @IBOutlet weak var descLabel: UILabel! @IBOutlet weak var loyalityPointStackView: UIStackView! @IBOutlet weak var containerView: UIView! @IBOutlet weak var sendBtn: UIButton! // MARK: VC's Life cycle override func viewDidLoad() { super.viewDidLoad() self.setup() self.fetchData() self.title = "Loyality Points" // self.presenter?.viewInitiated() } // MARK: IBActions @IBAction func sendBtnClicked(_ sender: Any) { presenter?.openSendMoneyView() } // MARK: Other Functions private func fetchData() { self.presenter?.viewInitiated() } private func setup() { // all setup should be done here setupView() } func setupView() { containerView.backgroundColor = .clear containerView.set(cornerRadius: 16) containerView.set(borderWidth: 1, of: .themeWhite) sendBtn.set(cornerRadius: 8) sendBtn.setTitle("SEND MONEY", for: .normal) // sendBtn.setTitle("loyalty_points_btn_link_text".localized(), for: .normal) } func renderData() { titleLabel.font = .sanfrancisco(.semibold, size: 20) descLabel.font = .sanfrancisco(.semibold, size: 16) titleLabel.text = loyalityPoint.loyaltyMsgHead descLabel.text = loyalityPoint.loyaltyMsgBody descLabel.textColor = .themeBlack.withAlphaComponent(0.6) for i in 0...Int(loyalityPoint.totalCount ?? "0")! - 1 { if i < Int(loyalityPoint.tranCount ?? "0")! { loyalityPointStackView.addArrangedSubview(createView(true)) } else { loyalityPointStackView.addArrangedSubview(createView(false)) } } } func createView(_ isStar: Bool) -> UIView { let part = UIImageView() // part.frame.size.width = 24 // part.frame.size.height = 24 part.image = UIImage(named: isStar ? "loyalty-star-dot" : "loyalty-circle_border") NSLayoutConstraint.activate([ part.widthAnchor.constraint(equalToConstant: 18), part.heightAnchor.constraint(equalTo: part.widthAnchor, multiplier: 1) ]) return part } } // MARK: LoyalityPointsViewInterface extension LoyalityPointsViewController: LoyalityPointsViewInterface { func obtained(data: LoyalityPointsModel) { loyalityPoint = data } func obtained(error: String) { self.gmeAlert(message: error) } func progress(isShow: Bool) { if isShow { self.showProgressHud() } else { self.hideProgressHud() } } }