Vasilis
......@@ -13,8 +13,16 @@ import UIKit
class DataModel {
var data: Array<NSDictionary> = []
var data2: Array<swiftApi.CouponItemModel> = []
init() { //initializer method
let instanceOfMySwiftApi = swiftApi()
let couponsData = instanceOfMySwiftApi.getCoupons()
self.data2 = couponsData
let instanceOfMyApi = MyApi()
let couponSets = instanceOfMyApi.getCouponSets(withActive: true, andVisible: true, andUuids: nil)
let coupons = instanceOfMyApi.getCoupons() as AnyObject?
......@@ -48,6 +56,12 @@ class DataModel {
}
}
var getData2: Array<swiftApi.CouponItemModel> {
get { // getter
return data2
}
}
var getData: Array<NSDictionary> {
get { // getter
return data.filter({
......@@ -143,7 +157,7 @@ extension CouponsView {
}
struct couponView: View {
var result: NSDictionary
var result: swiftApi.CouponItemModel
var index: Int
var parentView: UIView
......@@ -154,19 +168,20 @@ extension CouponsView {
}
static func convertDateFormat(inputDate: String) -> String {
let olDateFormatter = DateFormatter()
olDateFormatter.dateFormat = "yyyy-MM-dd hh:mm:ss"
let oldDate = olDateFormatter.date(from: inputDate)
let convertDateFormatter = DateFormatter()
convertDateFormatter.dateFormat = "dd/MM/yyyy"
return convertDateFormatter.string(from: oldDate!)
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd hh:mm:ss"
if let date = dateFormatter.date(from: inputDate) {
dateFormatter.dateFormat = "dd/MM/yyyy"
let resultString = dateFormatter.string(from: date)
return resultString
} else {
return ""
}
}
var body: some View {
let couponData = result["coupon_data"] as? [String: Any] ?? ["":""]
// let couponData = result["coupon_data"] as? [String: Any] ?? ["":""]
let couponSetData = result.couponset_data
VStack(alignment: .leading) {
......@@ -181,7 +196,7 @@ extension CouponsView {
couponBarcodeViewController.didMove(toParent: UIHostingController(rootView: self))
} label: {
HStack(alignment: .center) {
ImageView(withURL: result["img_preview"] as! String)
ImageView(withURL: couponSetData?.img_preview ?? "")
.frame(maxWidth: self.uiscreen.width * 0.15)
.padding(.leading , self.uiscreen.width * 0.055)
VLine()
......@@ -193,17 +208,17 @@ extension CouponsView {
.padding(.bottom, self.uiscreen.height * 0.0075)
Spacer()
VStack {
Text(CouponsView.couponView.localizedWithParameter(parameter: result["name"] as? String ?? ""))
Text(CouponsView.couponView.localizedWithParameter(parameter: couponSetData?.name ?? ""))
.fontWeight(.medium)
.foregroundColor(Color(red: 0.22745098039215686, green: 0.3215686274509804, blue: 0.4))
.frame(maxWidth: self.uiscreen.width * 0.35, maxHeight: .infinity, alignment: .leading)
.font(.system(size: 15))
Text(CouponsView.couponView.localizedWithParameter(parameter: couponData["discount"] as? String ?? ""))
Text(CouponsView.couponView.localizedWithParameter(parameter: result.discount ?? ""))
.fontWeight(.bold)
.foregroundColor(Color(red: 0.22745098039215686, green: 0.3215686274509804, blue: 0.4))
.frame(maxWidth: self.uiscreen.width * 0.35, maxHeight: self.uiscreen.height * 0.05, alignment: .leading)
.font(.system(size: 47))
Text(CouponsView.couponView.localizedWithParameter(parameter: "Ισχύει εώς " + CouponsView.couponView.convertDateFormat(inputDate: couponData["expiration"] as? String ?? "")))
Text(CouponsView.couponView.localizedWithParameter(parameter: "Ισχύει εώς " + (result.expiration ?? "")))
.fontWeight(.medium)
.foregroundColor(Color(red: 0.3803921568627451, green: 0.44313725490196076, blue: 0.5058823529411764))
.frame(maxWidth: self.uiscreen.width * 0.35, maxHeight: .infinity, alignment: .leading)
......@@ -213,7 +228,7 @@ extension CouponsView {
.padding(.top, self.uiscreen.height * 0.03)
.padding(.bottom, self.uiscreen.height * 0.03)
VStack {
Text(CouponsView.couponView.localizedWithParameter(parameter: result["short_description"] as! String))
Text(CouponsView.couponView.localizedWithParameter(parameter: couponSetData?.short_description ?? ""))
.fontWeight(.medium)
.foregroundColor(Color(red: 0.3803921568627451, green: 0.44313725490196076, blue: 0.5058823529411764))
.frame(maxWidth: self.uiscreen.width * 0.22, maxHeight: self.uiscreen.height * 0.10)
......@@ -239,12 +254,22 @@ extension CouponsView {
@available(iOS 13.0.0, *)
struct CouponsView: View {
var data:Array<NSDictionary> = DataModel().getData
// var data:Array<swiftApi.CouponItemModel> = []
var data:Array<swiftApi.CouponItemModel> = DataModel().getData2
var parentView: UIView
var uiscreen = UIScreen.main.bounds
// init() { //initializer method
//
// let instanceOfMySwiftApi = swiftApi()
// let couponsData = instanceOfMySwiftApi.getCoupons()
//
// self.data = couponsData
// }
func goBack(){
for subview in parentView.subviews {
if(subview.tag == 1) {
......
......@@ -153,15 +153,23 @@ public class swiftApi {
self.category = dictionary["category"] as? String? ?? ""
self.barcode = dictionary["barcode"] as? String? ?? ""
self.status = dictionary["status"] as? Int? ?? nil
self.couponset_data = dictionary["couponset_data"] as? CouponSetItemModel? ?? nil
let expirationObject = dictionary["expiration"] as? [String: Any]? ?? ["":""]
let expirationString = expirationObject?["value"] as? String? ?? ""
if let couponSetData = dictionary["couponset_data"] as? [String: Any]? ?? ["":""] {
let tempCouponset = CouponSetItemModel(dictionary: couponSetData)
self.couponset_data = tempCouponset
} else {
self.couponset_data = nil
}
let expirationString = dictionary["expiration"] as? String? ?? ""
// Example expirationString: Optional(2022-12-05 01:55)
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd hh:mm"
dateFormatter.dateFormat = "yyyy-MM-dd hh:mm:ss"
if let date = dateFormatter.date(from: expirationString ?? "") {
dateFormatter.dateFormat = "dd/MM/yyyy"
let resultString = dateFormatter.string(from: date)
......@@ -205,15 +213,15 @@ public class swiftApi {
let couponsData = (myCouponsDictionary["result"] as! Array<NSMutableDictionary>)
if let sets = couponSetsData as? NSArray {
for set in sets {
let s = set as! [String : Any]
let s = set as! NSDictionary
if let cpns = couponsData as? NSArray {
for coupon in cpns {
var c = coupon as! [String : Any]
var c = coupon as! NSDictionary
// var temp = NSMutableDictionary(dictionary: s);
if c["couponset_uuid"] as! String == s["uuid"] as! String {
let temp = NSMutableDictionary(dictionary: c);
temp.setValue(s as [AnyHashable : Any],forKey: "couponset_data")
temp.setValue(s as! [AnyHashable : Any],forKey: "couponset_data")
let tempCoupon = CouponItemModel(dictionary: temp as! [String : Any])
couponsArray.append(tempCoupon)
......