Showing
1 changed file
with
6 additions
and
31 deletions
| ... | @@ -28,14 +28,12 @@ import UIKit | ... | @@ -28,14 +28,12 @@ import UIKit |
| 28 | @IBOutlet weak var tableView: UITableView! | 28 | @IBOutlet weak var tableView: UITableView! |
| 29 | @IBOutlet weak var activeCodeImage: UIImageView! | 29 | @IBOutlet weak var activeCodeImage: UIImageView! |
| 30 | 30 | ||
| 31 | - public var coupons:Array<swiftApi.CouponItemModel> = [] | 31 | + public var coupons:Array<swiftApi.CouponItemModel> = swiftApi().getCouponList() |
| 32 | public var dfyCoupons:Array<swiftApi.ActiveDFYCouponModel> = swiftApi().getActiveDFYCoupons() | 32 | public var dfyCoupons:Array<swiftApi.ActiveDFYCouponModel> = swiftApi().getActiveDFYCoupons() |
| 33 | 33 | ||
| 34 | public override func viewDidLoad() { | 34 | public override func viewDidLoad() { |
| 35 | super.viewDidLoad() | 35 | super.viewDidLoad() |
| 36 | 36 | ||
| 37 | - getCouponsRequest() | ||
| 38 | - | ||
| 39 | setBackButton() | 37 | setBackButton() |
| 40 | setNavigationTitle("For You") | 38 | setNavigationTitle("For You") |
| 41 | 39 | ||
| ... | @@ -98,9 +96,12 @@ import UIKit | ... | @@ -98,9 +96,12 @@ import UIKit |
| 98 | couponEarnView.layer.shadowOpacity = 1.0 | 96 | couponEarnView.layer.shadowOpacity = 1.0 |
| 99 | couponEarnView.layer.shadowRadius = 3.0 | 97 | couponEarnView.layer.shadowRadius = 3.0 |
| 100 | 98 | ||
| 99 | + var totalCouponDiscount = coupons.reduce(0) { $0 + (Float($1.discount ?? "") ?? 0) } | ||
| 100 | + totalCouponDiscount = Float(round(100 * totalCouponDiscount) / 100) | ||
| 101 | + let totalCouponDiscountString = String(format: "%.2f", totalCouponDiscount).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil) | ||
| 101 | 102 | ||
| 102 | - couponEarnLabel.text = "" | 103 | + couponEarnLabel.text = "Μέχρι τώρα έχεις κερδίσει " + totalCouponDiscountString + "€ σε προσφορές από " + String(coupons.count) + " κουπόνια!" |
| 103 | - couponEarnAmountLabel.text = "" | 104 | + couponEarnAmountLabel.text = totalCouponDiscountString + "€" |
| 104 | 105 | ||
| 105 | activeCodeView.layer.cornerRadius = 5.0 | 106 | activeCodeView.layer.cornerRadius = 5.0 |
| 106 | activeCodeView.layer.shadowColor = UIColor(red: 0.00, green: 0.00, blue: 0.00, alpha: 0.16).cgColor | 107 | activeCodeView.layer.shadowColor = UIColor(red: 0.00, green: 0.00, blue: 0.00, alpha: 0.16).cgColor |
| ... | @@ -143,32 +144,6 @@ import UIKit | ... | @@ -143,32 +144,6 @@ import UIKit |
| 143 | activeCodeExpirationLabel.text = "" | 144 | activeCodeExpirationLabel.text = "" |
| 144 | } | 145 | } |
| 145 | } | 146 | } |
| 146 | - | ||
| 147 | - // MARK: - API Functions | ||
| 148 | - func getCouponsRequest() { | ||
| 149 | - swiftApi().getCouponsAsync(getCouponsCallback) | ||
| 150 | - } | ||
| 151 | - | ||
| 152 | - func getCouponsCallback (_ couponsData: Array<swiftApi.CouponItemModel>?) -> Void { | ||
| 153 | - if (couponsData != nil) { | ||
| 154 | - let activeCouponData = swiftApi().filterActiveCoupons(couponsData ?? []) | ||
| 155 | - | ||
| 156 | - self.coupons = activeCouponData | ||
| 157 | - | ||
| 158 | - DispatchQueue.main.async { | ||
| 159 | - self.tableView.reloadData() | ||
| 160 | - | ||
| 161 | - var totalCouponDiscount = self.coupons.reduce(0) { $0 + (Float($1.discount ?? "") ?? 0) } | ||
| 162 | - totalCouponDiscount = Float(round(100 * totalCouponDiscount) / 100) | ||
| 163 | - let totalCouponDiscountString = String(format: "%.2f", totalCouponDiscount).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil) | ||
| 164 | - | ||
| 165 | - self.couponEarnLabel.text = "Μέχρι τώρα έχεις κερδίσει " + totalCouponDiscountString + "€ σε προσφορές από " + String(activeCouponData.count) + " κουπόνια!" | ||
| 166 | - self.couponEarnAmountLabel.text = totalCouponDiscountString + "€" | ||
| 167 | - } | ||
| 168 | - } else { | ||
| 169 | - self.coupons = [] | ||
| 170 | - } | ||
| 171 | - } | ||
| 172 | 147 | ||
| 173 | // MARK: - Actions | 148 | // MARK: - Actions |
| 174 | @IBAction func qustionnaireButtonAction(_ sender: Any) { | 149 | @IBAction func qustionnaireButtonAction(_ sender: Any) { | ... | ... |
-
Please register or login to post a comment