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.

115 lines
3.2 KiB

1 year ago
2 years ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. //
  2. // LoyalityPointsViewController.swift
  3. // GME Remit
  4. //
  5. // Created by Armaan Shrestha on 12/12/2022.
  6. //Copyright © 2022 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import UIKit
  9. class LoyalityPointsViewController: UIViewController {
  10. var loyalityPoint: LoyalityPointsModel! {
  11. didSet {
  12. renderData()
  13. }
  14. }
  15. // MARK: Properties
  16. var presenter: LoyalityPointsModuleInterface?
  17. // MARK: IBOutlets
  18. @IBOutlet weak var titleLabel: UILabel!
  19. @IBOutlet weak var descLabel: UILabel!
  20. @IBOutlet weak var loyalityPointStackView: UIStackView!
  21. @IBOutlet weak var containerView: UIView!
  22. @IBOutlet weak var sendBtn: UIButton!
  23. // MARK: VC's Life cycle
  24. override func viewDidLoad() {
  25. super.viewDidLoad()
  26. self.setup()
  27. self.fetchData()
  28. self.title = "Loyality Points"
  29. // self.presenter?.viewInitiated()
  30. }
  31. // MARK: IBActions
  32. @IBAction func sendBtnClicked(_ sender: Any) {
  33. presenter?.openSendMoneyView()
  34. }
  35. // MARK: Other Functions
  36. private func fetchData() {
  37. self.presenter?.viewInitiated()
  38. }
  39. private func setup() {
  40. // all setup should be done here
  41. setupView()
  42. }
  43. func setupView() {
  44. containerView.backgroundColor = .clear
  45. containerView.set(cornerRadius: 16)
  46. containerView.set(borderWidth: 1, of: .themeWhite)
  47. sendBtn.set(cornerRadius: 8)
  48. sendBtn.setTitle("SEND MONEY", for: .normal)
  49. // sendBtn.setTitle("loyalty_points_btn_link_text".localized(), for: .normal)
  50. }
  51. func renderData() {
  52. titleLabel.font = .sanfrancisco(.semibold, size: 20)
  53. descLabel.font = .sanfrancisco(.semibold, size: 16)
  54. titleLabel.text = loyalityPoint.loyaltyMsgHead
  55. descLabel.text = loyalityPoint.loyaltyMsgBody
  56. descLabel.textColor = .themeBlack.withAlphaComponent(0.6)
  57. for i in 0...Int(loyalityPoint.totalCount ?? "0")! - 1 {
  58. if i < Int(loyalityPoint.tranCount ?? "0")! {
  59. loyalityPointStackView.addArrangedSubview(createView(true))
  60. } else {
  61. loyalityPointStackView.addArrangedSubview(createView(false))
  62. }
  63. }
  64. }
  65. func createView(_ isStar: Bool) -> UIView {
  66. let part = UIImageView()
  67. // part.frame.size.width = 24
  68. // part.frame.size.height = 24
  69. part.image = UIImage(named: isStar ? "loyalty-star-dot" : "loyalty-circle_border")
  70. NSLayoutConstraint.activate([
  71. part.widthAnchor.constraint(equalToConstant: 18),
  72. part.heightAnchor.constraint(equalTo: part.widthAnchor, multiplier: 1)
  73. ])
  74. return part
  75. }
  76. }
  77. // MARK: LoyalityPointsViewInterface
  78. extension LoyalityPointsViewController: LoyalityPointsViewInterface {
  79. func obtained(data: LoyalityPointsModel) {
  80. loyalityPoint = data
  81. }
  82. func obtained(error: String) {
  83. self.gmeAlert(message: error)
  84. }
  85. func progress(isShow: Bool) {
  86. if isShow {
  87. self.showProgressHud()
  88. } else {
  89. self.hideProgressHud()
  90. }
  91. }
  92. }