Manos Chorianopoulos

add dynamic dfyCoupons at WalletVC

......@@ -29,6 +29,7 @@ import UIKit
@IBOutlet weak var activeCodeImage: UIImageView!
public var coupons:Array<swiftApi.CouponItemModel> = []
public var dfyCoupons:Array<swiftApi.ActiveDFYCouponModel> = swiftApi().getActiveDFYCoupons()
public override func viewDidLoad() {
super.viewDidLoad()
......@@ -84,9 +85,12 @@ import UIKit
dfyEarnView.layer.shadowOpacity = 1.0
dfyEarnView.layer.shadowRadius = 3.0
// TODO: dynamic
dfyEarnLabel.text = "Μέχρι τώρα έχεις κερδίσει 18,00€ με το DEALS for YOU!"
dfyEarnAmountLabel.text = "18,00€"
var totalCouponValue = self.dfyCoupons.reduce(0) { $0 + (Float($1._value) ?? 0) }
totalCouponValue = Float(round(100 * totalCouponValue) / 100)
let totalCouponValueString = String(format: "%.2f", totalCouponValue).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil)
dfyEarnLabel.text = "Μέχρι τώρα έχεις κερδίσει " + totalCouponValueString + "€ με το DEALS for YOU!"
dfyEarnAmountLabel.text = totalCouponValueString + "€"
couponEarnView.layer.cornerRadius = 5.0
couponEarnView.layer.shadowColor = UIColor(red: 0.00, green: 0.00, blue: 0.00, alpha: 0.16).cgColor
......@@ -104,9 +108,40 @@ import UIKit
activeCodeView.layer.shadowOpacity = 1.0
activeCodeView.layer.shadowRadius = 6.0
// TODO: dynamic
activeCodeLabel.text = "961544809"
activeCodeExpirationLabel.text = "Λήγει σε 4 ημέρες"
if (dfyCoupons.count > 0) {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd hh:mm:ss"
// sort dfyCoupons by date
dfyCoupons.sort(by: {
let date1 = dateFormatter.date(from: $0._date)
let date2 = dateFormatter.date(from: $1._date)
if ((date1 != nil) && (date2 != nil)) {
return date1!.compare(date2!) == .orderedAscending
} else {
return false
}
})
// Get days from now of the most recet coupon
var daysFromNow = ""
let calendar = Calendar.current
// Replace the hour (time) of both dates with 00:00
let date1 = calendar.startOfDay(for: Date())
if let date2 = dateFormatter.date(from: dfyCoupons[0]._date) {
let components = calendar.dateComponents([.day], from: date1, to: date2)
daysFromNow = (components.day) != nil ? String(components.day ?? 0) : ""
}
activeCodeLabel.text = dfyCoupons[0]._code
activeCodeExpirationLabel.text = "Λήγει σε " + daysFromNow + " ημέρες"
} else {
activeCodeLabel.text = "-"
activeCodeExpirationLabel.text = ""
}
}
// MARK: - API Functions
......